systemd

runlevels
=> Upstart
==> Systemd

Upstart vs Systemd comparison

Upstart Systemd
“jobs” “units”
greedy event-based lazy dependency-based
only start if a dependency of sth

Commands

systemctl start/stop/restart/status <unit>
systemctl status
systemd-analyze verify <unit>
systemctl --state=failed
journalctl -u <unit>
journalctl -u <unit> -f
systemctl list-dependencies --all

Example Systemd service

/lib/systemd/system/foo.service:

[Unit]
Description=Job that runs the foo daemon
Documentation=man:foo(1)

[Service]
Type=forking
Environment=statedir=/var/cache/foo
ExecStartPre=/usr/bin/mkdir -p ${statedir}
ExecStart=/usr/bin/foo-daemon --arg1 "hello world" --statedir ${statedir}

[Install]
WantedBy=multi-user.target

Additional settings

Foreground/Background

Foreground [default]: Type=simple

Background: Type=forking

Environment Variables File

Mandatory environment variable file: EnvironmentFile=/etc/default/foo

Optional environment variable file: EnvironmentFile=-/etc/default/foo