Thank you for taking the time to ensure that your package is working fine with systemd.
Using debhelper with dh_systemd
Add Build-Depends on dh-systemd (>= 1.5)
If you are using dh(1), add the systemd addon via dh --with systemd in your debian/rules. This will run the dh_systemd_enable(1) and dh_systemd_start(1) helpers at the correct time during build. You can use the known override mechanism to specify custom options for those commands. Please refer to their man pages for the list of available options.
- If you are using plain debhelper, make sure to run dh_systemd_enable *before* dh_installinit and dh_systemd_start *after* dh_installinit
After rebuilding, your package will have additional code in the postinst, prerm and postrm maintainer scripts. A careful look at that code cannot hurt.
These examples might be helpful to look at when using dh-systemd in your package:
kanla: http://anonscm.debian.org/gitweb/?p=collab-maint/kanla.git;a=commitdiff;h=1f752f4 (entirely new service file)
vsftpd: 713857 (service file present, use dh-systemd)
nginx: 713853 (removes custom systemctl calls, use dh-systemd instead)
lighttpd: 713859 (service file present, use dh-systemd)
thinkfan: 713878 (does not enable unit files by default)
systemd unit files naming and installation
When you are installing a systemd service file alongside of your SysV init script, you should name it correspondingly. E.g. for /etc/init.d/apache2 the corresponding service file should be named /lib/systemd/system/apache2.service. This way, systemd will automatically prefer the native service file over the SysV init script and use that to start the service. If the names do not match, say your service file is provided by upstream and named NetworkManager.service and your existing SysV init script is called /etc/init.d/network-manager, you can either rename one of the two or you simply use an Alias=. This instruction tells systemctl enable to create a symlink. Augment the service file like this:
If your service file is not provided by upstream and you ship it as part of your debian package, name it debian/$pkg.service and dh_installinit will install it to the correct location. For more information please refer to the dh_installinit(1) man page.
socket and D-Bus activated services
For socket and D-Bus activated services we recommed to use --restart-after-upgrade if your daemon supports that. If your daemon uses the default behaviour (stop in prerm, start in postinst), mask the .service file, so the service is not started on incoming requests while the upgrade is ongoing.
TODO: Add code snippets
Switching to systemd on a fresh Debian wheezy installation
# libpam-systemd is installed explicitly, just in case you have recommends turned off. apt-get install systemd libpam-systemd sed -i 's,^GRUB_CMDLINE_LINUX=",GRUB_CMDLINE_LINUX="init=/bin/systemd ,g' /etc/default/grub update-grub reboot
If anything goes wrong, just remove the init=/bin/systemd argument when booting your kernel.
Avoid Accept=yes in .socket files
Avoid using Accept=yes in .socket files, because service(8) cannot stop that service correctly. E.g. you have approx.socket and approx@.service, which gets expanded to approx@1-::1:9999-::1:44903.service, then service approx stop will not work.
In case you are missing some information, please contact pkg-systemd-maintainers via IRC in #debian-systemd on irc.debian.org or via email at https://lists.alioth.debian.org/mailman/listinfo/pkg-systemd-maintainers
We will update this wiki page with the answers to frequently asked questions.