Skip to content
Mike Perham edited this page Jul 7, 2016 · 20 revisions

Systemd is the init system that all major Linux distributions will be using in the future.

Overview

Basic commands:

# list all services
systemctl -t service

# working with foo.service, you can leave off the ".service"
systemctl start foo
systemctl restart foo
systemctl stop foo
systemctl status foo

You can enable and disable a service if you need to. Disabled services won't start on reboot.

systemctl enable foo
systemctl disable foo

Details

Systemd manages units; one type of unit is a service which is what we care about. User-custom unit files go in /usr/lib/systemd/system. When you enable a service, systemd will create a symlink in /etc/systemd/system/multi-user.target.wants. This is a way of saying "when the machine boots normally, start my service". Everything in this multi-user.target.wants directory is started on normal bootup.

Simple Example

Inspeqtor's service unit file in /usr/lib/systemd/system/inspeqtor.service is well-commented and hopefully straight-forward to understand.

More Examples

See your own system's /usr/lib/systemd/system directory for more examples. I found the following two systemd man pages to be incredibly helpful:

Forking Services

Services that fork (such as Nginx) need to include the PIDFile= option in their system unit file in order for Inspeqtor to monitor them. If this option is omitted then Systemd won't be able to detect the process id and Inspeqtor will be unable to determine an accurate status.