James's Ramblings

systemd

Created: November 03, 2019

Enable the User-Based Service Manager

sudo loginctl enable-linger james

Service files for the user-based service manager can be created in ~/.config/systemd/user/.

Manipulate a User-Based Service

systemctl --user

System Service Files

System Service Files are located in: /etc/systemd/system/

Basic Syntax of a Service File

[Unit]
Description=caffeine

[Service]
ExecStart=/usr/bin/caffeine
WorkingDirectory=/usr/local

[Install]
WantedBy=multi-user.target

/sbin/init

There is a symlink at /usr/sbin/init to systemd and at /usr/sbin/telinit to systemctl.

Unit Files

Location of most of the default unit files:

/lib/systemd/system

/etc/systemd/system takes precedence over /lib/systemd/system.

Quick Notes

systemctl list-unit-files
systemctl list-timers

Boot Targets with systemd

  • There are different systemd boot targets that correspond to the older SysV runlevels.
Runlevel Boot Target
0 poweroff
1 rescue
3 multi-user
5 graphical
6 reboot

To switch between boot targets:

# systemctl isolate BOOT_TARGET.target

To get the default boot target:

# systemctl get-default

To set the default boot target:

# systemctl set-default BOOT_TARGET.target

Boot target files can be found in:

  • /etc/systemd/system/
  • /usr/lib/systemd/system/