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

2 thoughts on “Managing Services with systemd | Start Stop and List Services

  1. docent

    Great post 🙂 I’d add some more here:

    – systemd-cgls – show cgroup tree
    – systemctl get-default – what is the default target (runlevel)?
    – change boot target (runlevel):
    – ln -sf /usr/lib/systemd/system/multi-user.target /etc/systemd/system/default.target (like runlevel 3)
    – ln -sf /usr/lib/systemd/system/graphical.target /etc/systemd/system/default.target (like runlevel 5)
    – systemctl isolate graphical.target – change current target (runlevel); no effect after reboot
    – systemctl list-units –type=target – what is the current target (runlevel)?
    – systemctl show -p “Wants” multi-user.target – show target’s dependencies (could also try with “WantedBy”, “Requires”, “RequiredBy”, “Conflicts”,”ConflictedBy”, “Before”, “After”)
    – systemd –test –system –unit=foobar.target – check what would get started after booting into specific boot target
    – alias psc=’ps xawf -eo pid,user,cgroup,args’ – alias for ps with cgroups

    Reply
  2. DevOps

    The information which you have provided is very good and easily understood.

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *

Notify me of followup comments via e-mail. You can also subscribe without commenting.