Systemd

You can control how services are started, halted, and otherwise managed with systemd system and service manager. Let’s learn how to control various processes using systemd.

List the systemd system

Using systemctl, we can introspect and control the state of the systemd system and service manager.

systemctl
UNIT                               LOAD   ACTIVE SUB       DESCRIPTION
proc-sys-fs-binfmt_misc.automount  loaded active waiting   Arbitrary Executable File>
sys-devices-platform-serial8250-tty-ttyS1.device loaded active plugged   /sys/device>
sys-devices-platform-serial8250-tty-ttyS2.device loaded active plugged   /sys/device

Check service status

Using systemctl status, we can see if a service is running or enabled.

systemctl status sshd
● sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled; vendor preset: ena>
   Active: active (running) since Wed 2022-09-14 14:08:19 UTC; 1 weeks 2 days ago

Start/stop a service

Using systemctl start or systemctl stop, we can start/stop a service.

systemctl stop sshd
systemctl start sshd

Enable/disable a service

Using systemctl enable or systemctl disable, we can affect the service’s defaults at boot. For example, if we disable the service, it won’t start the next time the system boots.

sudo systemctl disable sshd
Removed /etc/systemd/system/multi-user.target.wants/sshd.service.

However, if we need the service to start automatically at boot, we can enable it.

sudo systemctl enable sshd
Created symlink /etc/systemd/system/multi-user.target.wants/sshd.service → /usr/lib/systemd/system/sshd.service.