What I do is create a .../debian
folder in my projects and create a .service
file for the daemon. I also add one command line option like so in the .../debian/rules
file:
%:
dh $@ --with systemd --parallel
That option tells the system to use systemd
to handle the .service
file (otherwise it falls back on SYS-V).
The one other thing to remember to do is add the #DEBHELPER#
in your post/pre inst/rm scripts. These are very important since that's what actually makes it all work.
For example, here is a configuration in a postinst
script:
#!/bin/sh
if [ "$1" = "configure" ]
then
# Turn on IP forwarding
echo 1 > /proc/sys/net/ipv4/ip_forward
fi
#DEBHELPER#
The position in your script will depend on what you do in your script. i.e. if you want to run a command after the service was started, then place the #DEBHELPER#
before. If you need to finish up configuration that your service is going to use, then place the #DEBHELPER#
after that configuration.
I have example in my Snap! project.
Note: if you have a project with more than one daemon, you can use the .../debian
folder trick for one of them. The other, you have to install by hand (on your own).