Making your package work
with systemd
Michael Stapelberg <stapelberg@debian.
org>
DebConf 2013
Topics
●
How systemd works (for pkg maintainers)
●
Example service file
●
tmpfiles.d(5), dh-systemd
●
More advanced examples
●
Questions
Non-topics
●
systemd sucks, let’s use $initsys instead
●
When will Debian switch the default?
●
Essentially, anything that ever came up on
debian-devel ;-)
How systemd works
●
Service files
correspond to init scripts:
/etc/init.d/apache2
→
/lib/systemd/system/apache2.service
●
systemctl
does what
service(8)
did:
service apache2 start
→
systemctl start apache2.service
How systemd works (2)
●
Targets
correspond to runlevels:
basic.target, multi-user.target,
graphical.target, …
(see
systemd.special(7)
)
●
symlinks
still enable a service:
update-rc.d apache2 defaults
→
systemctl enable apache2.service
Example service file: vnstat.service
[Unit]
Description=Network traffic monitor
[Service]
User=vnstat
ExecStart=/usr/sbin/vnstatd -n
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
tmpfiles.d(5)
●
useful e.g. for runtime directories:
$ cat /usr/lib/tmpfiles.d/lighttpd.conf
d /run/lighttpd 0750 www-data www-data -
●
more powerful:
○
files, directories, pipes, symlinks, …
○
automatic cleanup
Service file location
●
service files often shipped by upstream
●
if not, use debian/pkg.{service,tmpfile}
●
dh_installinit
installs
these files
●
send service files upstream!
Getting your service enabled
●
Build-Dep: dh-systemd, dh --with=systemd
●
maintscripts will contain appropriate code
●
deb-systemd-helper instead of systemctl
●
(avoids Depends: systemd)
Testing your package
●
Install systemd, boot with init=/bin/systemd
●
Check your service starts properly on boot
●
Check reload, stop, start, restart
Advanced examples: more features
[Unit]
Description=Debian Code Search: web frontend
[Service]
User=dcs
Group=dcs
ExecStart=/usr/bin/dcs-web \
-template_pattern=/usr/share/dcs/templates/*
StandardOutput=null
StandardError=journal
RestartSec=1
Restart=on-failure
[Install]
WantedBy=multi-user.target
Advanced examples: dbus-activated
[Unit]
Description=Manage, Install and
Generate Color Profiles
[Service]
Type=dbus
BusName=org.freedesktop.ColorManager
ExecStart=/usr/lib/colord/colord
User=colord
PrivateTmp=yes
Advanced examples: dh-systemd
# Only cleanup on purge,
# don’t enable service by default.
override_dh_systemd_enable:
dh_systemd_enable \
--no-enable
override_dh_systemd_start:
dh_systemd_start \
--restart-after-upgrade
Need help?
●
Check
https://wiki.debian.org/Systemd/Packaging
●
Stop by at #debian-systemd any time
●
Ask
[email protected]
●
We mean it. Please ask.
Finding documentation
●
Manpages:
systemd.service(5), systemd.exec(5), …
●
http://www.freedesktop.org/wiki/Software/systemd/
→
“The systemd for Administrators Blog Series”
→
“Package repositories of the various distributions”
Thanks! Any questions?
●
Thanks for your attention
●
Add systemd support today
♥
●
Questions?