A guide to using systemd

From www.ReeltoReel.nl Wiki
Jump to navigation Jump to search

This is how to stop a running service temporarily:

systemctl stop servicename.service

Send a kill:

systemctl kill sshd.service
systemctl kill -s HUP sshd.service

This stops it from starting at boot, but does not stop a running service:

systemctl disable servicename.service

And there is one way to really really stop a service for good, short of uninstalling it, and that is masking it by linking it to /dev/null:

ln -s /dev/null /etc/systemd/system/servicename.service
systemctl daemon-reload

When you do this you can't even start the service manually. Nothing can touch it.

What if you change your mind? Pish tosh, it's easy. Simply delete the symlink and run

systemctl enable servicename.service.

While we're here, let's talk about two reload commands: daemon-reload and reload. The daemon-reload option reloads the entire systemd manager configuration without disrupting active services. reload reloads the configuration files for specific services without disrupting service, like this:

systemctl reload servicename.service

This reloads the actual configuration file used by the hardy sysadmin, for example the /etc/ssh/sshd_config file for an SSH server, and not its systemd unit file, sshd.service. So this is what to use when you make configuration changes.

List active service units:

systemctl --type=service

list all service units:

systemctl --type=service --all

list systemd services:

systemctl list-unit-files

default target

The system boots to default.target

This is a symbolic link to multiuser.target or graphical.target.

Changing the default runlevel/target is replacing the symbolic link

ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target

To change runlevel:

systemctl isolate multi-user.target

booting

At boot time, on the kernel grub line, add:

systemd.unit=xxxxx

So what's taking so long? We can find out with the systemd-analyze blame command

$ systemd-analyze blame
  60057ms sendmail.service
  51241ms firstboot-graphical.service
  3574ms sshd-keygen.service
  3439ms NetworkManager.service
  3101ms udev-settle.service
  3025ms netfs.service
  2411ms iptables.service
  2411ms ip6tables.service
  2173ms abrtd.service
  2149ms nfs-idmap.service
  2116ms systemd-logind.service
  2097ms avahi-daemon.service
  1337ms iscsi.service


If you like pretty graphs systemd includes a cool command for automatically generating an SVG image from the blame output, like this:

systemd-analyze plot > graph1.svg

To shutdown:

systemctl poweroff


systemctl files

/lib/systemd/system/ 
/etc/systemd/system/ is for customized settings