Managing Services with systemd | Start Stop and List Services

By | 2014/03/07

Managing services with systemd is very straightforward. Since the major Linux distros are all going with systemd, managing services will be the same across those Linux distros. Here is a quick how-to!


Start or Stop a Service

$ sudo systemctl start cups

$ sudo systemctl stop cups


Check the Status of a Service

$ sudo systemctl status sshd
sshd.service - OpenSSH server daemon
   Loaded: loaded (/usr/lib/systemd/system/sshd.service; enabled)
   Active: active (running) since Fri 2014-03-07 16:16:08 UTC; 22min ago
 Main PID: 584 (sshd)
   CGroup: /system.slice/sshd.service
           └─584 /usr/sbin/sshd -D

Mar 07 16:16:08 localhost systemd[1]: Started OpenSSH server daemon.
Mar 07 16:16:08 localhost sshd[584]: Server listening on 0.0.0.0 port 22.
Mar 07 16:16:08 localhost sshd[584]: Server listening on :: port 22.
Mar 07 16:16:43 localhost sshd[591]: Accepted password for bob from 192.168.1.2 port 37467 ssh2
Mar 07 16:16:43 localhost sshd[591]: pam_systemd(sshd:session): Ignoring vtnr 0 for  which is not seat0
Mar 07 16:22:47 localhost sshd[7292]: Did not receive identification string from 192.168.1.2
$ 


Enable a Service at Boot

$ sudo systemctl enable sshd
ln -s '/usr/lib/systemd/system/sshd.service' '/etc/systemd/system/multi-user.target.wants/sshd.service'


Disable a Service From Starting at Boot

$ sudo systemctl disable cups
rm '/etc/systemd/system/printer.target.wants/cups.service'
rm '/etc/systemd/system/multi-user.target.wants/cups.path'
rm '/etc/systemd/system/sockets.target.wants/cups.socket'


List Services and Their Status

$ systemctl list-unit-files

or

$ sudo systemctl


For more, the fedora and arch wikis have great pages:

https://fedoraproject.org/wiki/Systemd

https://wiki.archlinux.org/index.php/systemd