Debug School

Cover image for Troubleshoot Services in Ubuntu
Suyash Sambhare
Suyash Sambhare

Posted on

Troubleshoot Services in Ubuntu

The well-known Linux distribution Ubuntu provides a strong mechanism for handling services. These services are background programs that are either manually invoked or launched at boot. They administer logging, network administration, and other functions that are essential to the system's operation.

It is essential for webmasters and administrators to comprehend how to handle these services. An issue-ridden server or one that runs smoothly can be determined by one's ability to list, manage, and troubleshoot these services.

Systemd is now the default init system on Ubuntu. This implies that systemd is in charge of controlling system processes and bootstrapping the user space. Understanding this change is crucial before beginning to use commands, as the majority of service management commands will centre around the systemctl utility provided by systemd.

Systemd is the first process to launch on your Ubuntu server. It is in charge of starting up several services, including the SSH daemon and network manager. Consider systemd to be the system administrator in charge of all other services.

List All Services

Use the following command to list all services, whether they are failed, inactive, or active: sudo systemctl list-units --type=service --all
This command offers a detailed list that displays each service's current status.

suyi@suyi:~$ sudo systemctl list-units --type=service --all
  UNIT                                                                                      LOAD      ACTIVE   SUB     DESCRIPTION
  apparmor.service                                                                          loaded    active   exited  Load AppArmor profiles
  apport-autoreport.service                                                                 loaded    inactive dead    Process error reports when automatic reporting is enabled
  apport.service                                                                            loaded    active   exited  LSB: automatic crash report generation
  apt-daily-upgrade.service                                                                 loaded    inactive dead    Daily apt upgrade and clean activities
  apt-daily.service                                                                         loaded    inactive dead    Daily apt download activities
● auditd.service                                                                            not-found inactive dead    auditd.service
  blk-availability.service                                                                  loaded    active   exited  Availability of block devices
  cloud-config.service                                                                      loaded    active   exited  Apply the settings specified in cloud-config
  cloud-final.service                                                                       loaded    active   exited  Execute cloud user/final scripts
  cloud-init-hotplugd.service                                                               loaded    inactive dead    cloud-init hotplug hook daemon
  cloud-init-local.service                                                                  loaded    active   exited  Initial cloud-init job (pre-networking)
  cloud-init.service                                                                        loaded    active   exited  Initial cloud-init job (metadata service crawler)
● connman.service                                                                           not-found inactive dead    connman.service
● console-screen.service                                                                    not-found inactive dead    console-screen.service
  console-setup.service                                                                     loaded    active   exited  Set console font and keymap
  containerd.service                                                                        loaded    active   running containerd container runtime
  cron.service                                                                              loaded    active   running Regular background program processing daemon
  dbus.service                                                                              loaded    active   running D-Bus System Message Bus
● display-manager.service                                                                   not-found inactive dead    display-manager.service
  dm-event.service                                                                          loaded    inactive dead    Device-mapper event daemon
  dmesg.service                                                                             loaded    inactive dead    Save initial kernel messages after boot
  docker.service                                                                            loaded    active   running Docker Application Container Engine
  dpkg-db-backup.service                                                                    loaded    inactive dead    Daily dpkg database backup service
  e2scrub_all.service                                                                       loaded    inactive dead    Online ext4 Metadata Check for All Filesystems
  e2scrub_reap.service                                                                      loaded    inactive dead    Remove Stale Online ext4 Metadata Check Snapshots
  emergency.service                                                                         loaded    inactive dead    Emergency Shell
● fcoe.service                                                                              not-found inactive dead    fcoe.service
  finalrd.service                                                                           loaded    active   exited  Create final runtime dir for shutdown pivot root
● firewalld.service                                                                         not-found inactive dead    firewalld.service
  fstrim.service                                                                            loaded    inactive dead    Discard unused blocks on filesystems from /etc/fstab
  fwupd-refresh.service                                                                     loaded    inactive dead    Refresh fwupd metadata and update motd
  getty-static.service                                                                      loaded    inactive dead    getty on tty2-tty6 if dbus and logind are not available
  getty@tty1.service                                                                        loaded    active   running Getty on tty1
  grub-common.service                                                                       loaded    inactive dead    Record successful boot for GRUB
  grub-initrd-fallback.service                                                              loaded    inactive dead    GRUB failed boot detection
● hv_kvp_daemon.service                                                                     not-found inactive dead    hv_kvp_daemon.service
  irqbalance.service                                                                        loaded    active   running irqbalance daemon
● iscsi-shutdown.service                                                                    not-found inactive dead    iscsi-shutdown.service
  iscsid.service                                                                            loaded    inactive dead    iSCSI initiator daemon (iscsid)
● kbd.service                                                                               not-found inactive dead    kbd.service
  keyboard-setup.service                                                                    loaded    active   exited  Set the console keyboard layout
  kmod-static-nodes.service                                                                 loaded    active   exited  Create List of Static Device Nodes
  logrotate.service                                                                         loaded    inactive dead    Rotate log files
● lvm2-activation-early.service                                                             not-found inactive dead    lvm2-activation-early.service
● lvm2-activation.service                                                                   not-found inactive dead    lvm2-activation.service
  lvm2-lvmpolld.service                                                                     loaded    inactive dead    LVM2 poll daemon
  lvm2-monitor.service                                                                      loaded    active   exited  Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or progress polling
  lvm2-pvscan@252:3.service                                                                 loaded    active   exited  LVM event activation on device 252:3
  lxd-agent.service                                                                         loaded    inactive dead    LXD - agent
  man-db.service                                                                            loaded    inactive dead    Daily man-db regeneration
  ModemManager.service                                                                      loaded    active   running Modem Manager
  modprobe@configfs.service                                                                 loaded    inactive dead    Load Kernel Module configfs
  modprobe@drm.service                                                                      loaded    inactive dead    Load Kernel Module drm
  modprobe@efi_pstore.service                                                               loaded    inactive dead    Load Kernel Module efi_pstore
  modprobe@fuse.service                                                                     loaded    inactive dead    Load Kernel Module fuse
  motd-news.service                                                                         loaded    inactive dead    Message of the Day
  multipathd.service                                                                        loaded    active   running Device-Mapper Multipath Device Controller
  netplan-ovs-cleanup.service                                                               loaded    inactive dead    OpenVSwitch configuration for cleanup
  networkd-dispatcher.service                                                               loaded    active   running Dispatcher daemon for systemd-networkd
● networking.service                                                                        not-found inactive dead    networking.service
● NetworkManager.service                                                                    not-found inactive dead    NetworkManager.service
  ntp-systemd-netif.service                                                                 loaded    inactive dead    ntp-systemd-netif.service
  ntp.service                                                                               loaded    active   running Network Time Service
  open-iscsi.service                                                                        loaded    inactive dead    Login to default iSCSI targets
  open-vm-tools.service                                                                     loaded    inactive dead    Service for virtual machines hosted on VMware
● ovsdb-server.service                                                                      not-found inactive dead    ovsdb-server.service
  plymouth-quit-wait.service                                                                loaded    active   exited  Hold until boot process finishes up
  plymouth-quit.service                                                                     loaded    active   exited  Terminate Plymouth Boot Screen
  plymouth-read-write.service                                                               loaded    active   exited  Tell Plymouth To Write Out Runtime Data
  plymouth-start.service                                                                    loaded    inactive dead    Show Plymouth Boot Screen
  polkit.service                                                                            loaded    active   running Authorization Manager
  pollinate.service                                                                         loaded    inactive dead    Pollinate to seed the pseudo random number generator
● rbdmap.service                                                                            not-found inactive dead    rbdmap.service
  rc-local.service                                                                          loaded    inactive dead    /etc/rc.local Compatibility
  rescue.service                                                                            loaded    inactive dead    Rescue Shell
  rsyslog.service                                                                           loaded    active   running System Logging Service
  secureboot-db.service                                                                     loaded    inactive dead    Secure Boot updates for DB and DBX
  serial-getty@ttyS0.service                                                                loaded    active   running Serial Getty on ttyS0
  setvtrgb.service                                                                          loaded    active   exited  Set console scheme
  snap.lxd.activate.service                                                                 loaded    inactive dead    Service for snap application lxd.activate
  snap.lxd.daemon.service                                                                   loaded    inactive dead    Service for snap application lxd.daemon
  snap.lxd.user-daemon.service                                                              loaded    inactive dead    Service for snap application lxd.user-daemon
● snapd.aa-prompt-listener.service                                                          not-found inactive dead    snapd.aa-prompt-listener.service
  snapd.apparmor.service                                                                    loaded    active   exited  Load AppArmor profiles managed internally by snapd
  snapd.autoimport.service                                                                  loaded    inactive dead    Auto import assertions from block devices
  snapd.core-fixup.service                                                                  loaded    inactive dead    Automatically repair incorrect owner/permissions on core devices
  snapd.failure.service                                                                     loaded    inactive dead    Failure handling of the snapd snap
  snapd.recovery-chooser-trigger.service                                                    loaded    inactive dead    Wait for the Ubuntu Core chooser trigger
  snapd.seeded.service                                                                      loaded    active   exited  Wait until snapd is fully seeded
  snapd.service                                                                             loaded    active   running Snap Daemon
  snapd.snap-repair.service                                                                 loaded    inactive dead    Automatically fetch and run repair assertions
  ssh.service                                                                               loaded    active   running OpenBSD Secure Shell server
● sshd-keygen.service                                                                       not-found inactive dead    sshd-keygen.service
  systemd-ask-password-console.service                                                      loaded    inactive dead    Dispatch Password Requests to Console
  systemd-ask-password-plymouth.service                                                     loaded    inactive dead    Forward Password Requests to Plymouth
  systemd-ask-password-wall.service                                                         loaded    inactive dead    Forward Password Requests to Wall
  systemd-binfmt.service                                                                    loaded    active   exited  Set Up Additional Binary Formats
  systemd-boot-system-token.service                                                         loaded    inactive dead    Store a System Token in an EFI Variable
  systemd-fsck-root.service                                                                 loaded    inactive dead    File System Check on Root Device
  systemd-fsck@dev-disk-by\x2duuid-30683743\x2dc712\x2d4f97\x2d984a\x2d1113c82c48c6.service loaded    active   exited  File System Check on /dev/disk/by-uuid/30683743-c712-4f97-984a-1113c82c48c6
  systemd-fsckd.service                                                                     loaded    inactive dead    File System Check Daemon to report status
● systemd-hwdb-update.service                                                               not-found inactive dead    systemd-hwdb-update.service
  systemd-initctl.service                                                                   loaded    inactive dead    initctl Compatibility Daemon
  systemd-journal-flush.service                                                             loaded    active   exited  Flush Journal to Persistent Storage
  systemd-journald.service                                                                  loaded    active   running Journal Service
  systemd-logind.service                                                                    loaded    active   running User Login Management
  systemd-machine-id-commit.service                                                         loaded    inactive dead    Commit a transient machine-id on disk
  systemd-modules-load.service                                                              loaded    active   exited  Load Kernel Modules
  systemd-networkd-wait-online.service                                                      loaded    active   exited  Wait for Network to be Configured
  systemd-networkd.service                                                                  loaded    active   running Network Configuration
  systemd-pstore.service                                                                    loaded    inactive dead    Platform Persistent Storage Archival
  systemd-quotacheck.service                                                                loaded    inactive dead    File System Quota Check
  systemd-random-seed.service                                                               loaded    active   exited  Load/Save Random Seed
  systemd-remount-fs.service                                                                loaded    active   exited  Remount Root and Kernel File Systems
  systemd-resolved.service                                                                  loaded    active   running Network Name Resolution
  systemd-rfkill.service                                                                    loaded    inactive dead    Load/Save RF Kill Switch Status
  systemd-sysctl.service                                                                    loaded    active   exited  Apply Kernel Variables
  systemd-sysusers.service                                                                  loaded    active   exited  Create System Users
● systemd-timesyncd.service                                                                 masked    inactive dead    systemd-timesyncd.service
  systemd-tmpfiles-clean.service                                                            loaded    inactive dead    Cleanup of Temporary Directories
  systemd-tmpfiles-setup-dev.service                                                        loaded    active   exited  Create Static Device Nodes in /dev
  systemd-tmpfiles-setup.service                                                            loaded    active   exited  Create Volatile Files and Directories
  systemd-udev-trigger.service                                                              loaded    active   exited  Coldplug All udev Devices
  systemd-udevd.service                                                                     loaded    active   running Rule-based Manager for Device Events and Files
● systemd-update-done.service                                                               not-found inactive dead    systemd-update-done.service
  systemd-update-utmp-runlevel.service                                                      loaded    inactive dead    Record Runlevel Change in UTMP
  systemd-update-utmp.service                                                               loaded    active   exited  Record System Boot/Shutdown in UTMP
  systemd-user-sessions.service                                                             loaded    active   exited  Permit User Sessions
● systemd-vconsole-setup.service                                                            not-found inactive dead    systemd-vconsole-setup.service
  thermald.service                                                                          loaded    inactive dead    Thermal Daemon Service
● ua-auto-attach.service                                                                    not-found inactive dead    ua-auto-attach.service
  ua-reboot-cmds.service                                                                    loaded    inactive dead    Ubuntu Pro reboot cmds
  ua-timer.service                                                                          loaded    inactive dead    Ubuntu Pro Timer for running repeated jobs
● ubuntu-advantage-cloud-id-shim.service                                                    not-found inactive dead    ubuntu-advantage-cloud-id-shim.service
  ubuntu-advantage.service                                                                  loaded    inactive dead    Ubuntu Pro Background Auto Attach
  udisks2.service                                                                           loaded    active   running Disk Manager
  ufw.service                                                                               loaded    active   exited  Uncomplicated firewall
  unattended-upgrades.service                                                               loaded    active   running Unattended Upgrades Shutdown
  update-notifier-download.service                                                          loaded    inactive dead    Download data for packages that failed at package install time
  update-notifier-motd.service                                                              loaded    inactive dead    Check to see whether there is a new version of Ubuntu available
  user-runtime-dir@1000.service                                                             loaded    active   exited  User Runtime Directory /run/user/1000
  user@1000.service                                                                         loaded    active   running User Manager for UID 1000
  uuidd.service                                                                             loaded    active   running Daemon for generating UUIDs
  vgauth.service                                                                            loaded    inactive dead    Authentication service for virtual machines hosted on VMware
● zfs-mount.service                                                                         not-found inactive dead    zfs-mount.service

LOAD   = Reflects whether the unit definition was properly loaded.
ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
SUB    = The low-level unit activation state, values depend on unit type.
145 loaded units listed.
To show all installed unit files use 'systemctl list-unit-files'.
Enter fullscreen mode Exit fullscreen mode

Ubuntu

Mubuntu

Status of Service by Name

Use the following to find out the current state of a particular service: sudo systemctl status <Name of the service>

suyi@suyi:~$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sun 2024-09-15 22:40:08 UTC; 3h 40min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 849 (dockerd)
      Tasks: 10
     Memory: 104.0M
        CPU: 3.978s
     CGroup: /system.slice/docker.service
             └─849 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

Sep 15 22:40:05 suyi dockerd[849]: time="2024-09-15T22:40:05.285376658Z" level=info msg="Starting up"
Sep 15 22:40:05 suyi dockerd[849]: time="2024-09-15T22:40:05.291203704Z" level=info msg="detected 127.0.0.53 nameserver, assuming systemd-resolved, so using resolv.conf: /run/systemd/resolve/resolv.con>
Sep 15 22:40:05 suyi dockerd[849]: time="2024-09-15T22:40:05.940404598Z" level=info msg="[graphdriver] using prior storage driver: overlay2"
Sep 15 22:40:06 suyi dockerd[849]: time="2024-09-15T22:40:06.148735504Z" level=info msg="Loading containers: start."
Sep 15 22:40:07 suyi dockerd[849]: time="2024-09-15T22:40:07.612112932Z" level=info msg="Default bridge (docker0) is assigned with an IP address 172.17.0.0/16. Daemon option --bip can be used to set a >
Sep 15 22:40:07 suyi dockerd[849]: time="2024-09-15T22:40:07.809976695Z" level=info msg="Loading containers: done."
Sep 15 22:40:07 suyi dockerd[849]: time="2024-09-15T22:40:07.914247738Z" level=info msg="Docker daemon" commit=f9522e5 containerd-snapshotter=false storage-driver=overlay2 version=27.1.2
Sep 15 22:40:07 suyi dockerd[849]: time="2024-09-15T22:40:07.919455394Z" level=info msg="Daemon has completed initialization"
Sep 15 22:40:08 suyi dockerd[849]: time="2024-09-15T22:40:08.168499249Z" level=info msg="API listen on /run/docker.sock"
Sep 15 22:40:08 suyi systemd[1]: Started Docker Application Container Engine.
Enter fullscreen mode Exit fullscreen mode

Modifying services

Start a service:
sudo systemctl start docker

Stop a service:
sudo systemctl stop docker

Set service to start at boot:
sudo systemctl enable docker

Disable a service from starting at boot:
sudo systemctl disable docker

Troubleshooting Failed Services
Inspect a service logs:

sudo journalctl -u docker
This tool helps identify problems by displaying logs unique to the service.

Show logs with pattern
sudo journalctl -u docker -g error

Aug 22 01:32:54 suyi dockerd[834]: 2024/08/22 01:32:54 http2: server: error reading preface from client @: read unix /run/docker.sock->@: read: connection reset by peer
Aug 22 01:32:54 suyi dockerd[834]: 2024/08/22 01:32:54 http2: server: error reading preface from client @: read unix /run/docker.sock->@: read: connection reset by peer
Aug 22 02:13:05 suyi dockerd[834]: 2024/08/22 02:13:05 http2: server: error reading preface from client @: read unix /run/docker.sock->@: read: connection reset by peer
Aug 22 02:16:26 suyi dockerd[834]: 2024/08/22 02:16:26 http2: server: error reading preface from client @: read unix /run/docker.sock->@: read: connection reset by peer
Aug 22 02:16:26 suyi dockerd[834]: 2024/08/22 02:16:26 http2: server: error reading preface from client @: read unix /run/docker.sock->@: read: connection reset by peer
Aug 22 02:23:22 suyi dockerd[834]: 2024/08/22 02:23:22 http2: server: error reading preface from client @: read unix /run/docker.sock->@: read: connection reset by peer
Aug 22 02:34:33 suyi dockerd[834]: 2024/08/22 02:34:33 http2: server: error reading preface from client @: read unix /run/docker.sock->@: read: connection reset by peer
Aug 22 02:36:47 suyi dockerd[834]: time="2024-08-22T02:36:47.096274670Z" level=error msg="Handler for POST /v1.46/containers/44aa166cbfa74151ecf91b9a8b1894c4a65d0357e819404a0187f4726ed2ea3b/start retur>
Aug 22 02:52:35 suyi dockerd[834]: 2024/08/22 02:52:35 http2: server: error reading preface from client @: read unix /run/docker.sock->@: read: connection reset by peer
Aug 22 02:52:35 suyi dockerd[834]: 2024/08/22 02:52:35 http2: server: error reading preface from client @: read unix /run/docker.sock->@: read: connection reset by peer
Aug 22 02:52:58 suyi dockerd[834]: time="2024-08-22T02:52:58.885877415Z" level=error msg="Handler for POST /v1.46/containers/33caaaef459e7815dc0b7b19fb6013c75da4f8c30461449133651fdc2cb24f9d/start retur>
Aug 22 02:53:33 suyi dockerd[834]: time="2024-08-22T02:53:33.614744234Z" level=error msg="Handler for GET /v1.46/nodes returned error: This node is not a swarm manager. Use \"docker swarm init\" or \"d>
Aug 22 02:53:33 suyi dockerd[834]: time="2024-08-22T02:53:33.725262538Z" level=error msg="Handler for GET /v1.46/secrets returned error: This node is not a swarm manager. Use \"docker swarm init\" or \>
Aug 22 02:53:33 suyi dockerd[834]: time="2024-08-22T02:53:33.779312716Z" level=error msg="Handler for GET /v1.46/services returned error: This node is not a swarm manager. Use \"docker swarm init\" or >
Aug 22 03:34:32 suyi dockerd[834]: 2024/08/22 03:34:32 http2: server: error reading preface from client @: read unix /run/docker.sock->@: read: connection reset by peer
Aug 22 04:00:07 suyi dockerd[834]: 2024/08/22 04:00:07 http2: server: error reading preface from client @: read unix /run/docker.sock->@: read: connection reset by peer
Aug 22 04:07:58 suyi dockerd[834]: time="2024-08-22T04:07:58.336371559Z" level=error msg="Handler for GET /v1.46/containers/3f5ae5a0e2d4d31ee2b2a1e7349dc8f3b974357ad07d38058977dde457d64b00/json returne>
Aug 22 23:36:58 suyi dockerd[834]: time="2024-08-22T23:36:58.345922273Z" level=info msg="stopping event stream following graceful shutdown" error="<nil>" module=libcontainerd namespace=moby
-- Boot 669604f4faaf48118f69cf972a727357 --
Aug 22 23:39:59 suyi dockerd[834]: time="2024-08-22T23:39:59.284875890Z" level=info msg="stopping event stream following graceful shutdown" error="<nil>" module=libcontainerd namespace=moby
-- Boot c6e44628725942cba7220cce9f50ee24 --
Aug 26 03:33:25 suyi dockerd[836]: time="2024-08-26T03:33:25.334907163Z" level=info msg="Attempting next endpoint for pull after error: failed to register layer: write /usr/share/opensearch/jdk/jmods/j>
Enter fullscreen mode Exit fullscreen mode

Ref: https://webhostinggeeks.com/howto/how-to-list-manage-and-troubleshoot-services-in-ubuntu/

Top comments (0)