How to package a systemd service?

I'm trying to package a mono application to run as a systemd service.

I've followed the instructions here: https://wiki.debian.org/Teams/pkg-systemd/Packaging

I've added dh-systemd (>= 1.5) to my debian control file build depends.

I've added --with=systemd to my rules file as follows:

%:
    dh $@ --with=cli --with=systemd

I've added my service file to my debian folder called mypackage.service with the following contents:

[Unit]
Description=My Service Description
After=network-online.target

[Service]
Type=simple
ExecStart=/usr/bin/mono /usr/lib/mypackage/myservice.exe

[Install]
WantedBy=multi-user.target

However building gives the following lintian warnings and errors:

Now running lintian...
E: mypackage: postrm-does-not-call-updaterc.d-for-init.d-script     etc/init.d/mypackage
W: mypackage: init.d-script-not-marked-as-conffile etc/init.d/mypackage
E: mypackage: init.d-script-not-included-in-package etc/init.d/mypackage

This is confusing me for several reasons

  1. These warning are about init.d which is the old system which is replaced by systemd, are these errors and warnings just wrong, does debuild think I'm using init.d because I've configured my package wrong?
  2. I was under the impression that the --with=systemd would create these scripts for me.

Update

The generated postrm file is as follows:

#!/bin/sh
set -e
# Automatically added by dh_systemd_start
if [ -d /run/systemd/system ]; then
    systemctl --system daemon-reload >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_systemd_enable
if [ "$1" = "remove" ]; then
    if [ -x "/usr/bin/deb-systemd-helper" ]; then
        deb-systemd-helper mask mypackage.service >/dev/null
    fi
fi

if [ "$1" = "purge" ]; then
     if [ -x "/usr/bin/deb-systemd-helper" ]; then
        deb-systemd-helper purge mypackage.service >/dev/null
        deb-systemd-helper unmask mypackage.service >/dev/null
    fi
fi
# End automatically added section

the generated prerm file is as follows:

#!/bin/sh
set -e
# Automatically added by dh_systemd_start
if [ -d /run/systemd/system ]; then
    deb-systemd-invoke stop mypackage.service >/dev/null
fi
# End automatically added section
# Automatically added by dh_installinit
if [ -x "/etc/init.d/mypackage" ] || [ -e "/etc/init/mypackage.conf" ]; then
    invoke-rc.d mypackage stop || exit $?
fi
# End automatically added section

The package actually installs fine and the service starts correctly. The lintian errors are worrying, and I'd like to get to the bottom of them.


I ran into this issue as well. This is what I've come up with:

You'll want to override the dh_installinit and dh_systemd_start, this is an example from my network bridge service:

#!/usr/bin/make -f

PKGDIR=debian/tmp

%:
    dh $@ --with systemd

override_dh_installinit:
    dh_systemd_enable -popenstack --name=openstack openstack.service
    dh_installinit -popenstack --no-start --noscripts
    dh_systemd_start -popenstack --no-restart-on-upgrade

override_dh_systemd_start:
    echo "Not running dh_systemd_start"

The full source of my package can be found here: https://github.com/Ubuntu-Solutions-Engineering/openstack-deb/tree/master/debian

I also used https://github.com/lxc/lxd-pkg-ubuntu/blob/dpm-xenial/debian/rules as a reference.

Hopefully this will get you going as it did take me a little while to figure this out.


When not including SysV or Upstart init scripts, instruct dh_installinit to not modify the postinst/postrm/prerm scripts. dh_systemd will handle it.

override_dh_installinit:
    dh_installinit --noscripts

This applies to debhelper compatibility level < 10 and with 10 even though dh_systemd has been merged into debhelper.

According to https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=800043 debhelper compatibility level 11 >= this will have this fixed.