I am creating a Debian package for a software application which gets executed from a service script and could like to know the best way to do this.
My current thoughts are for the package to copy the executable to /usr/bin
, and the service to /etc/systemd/system/
, and have a postinst
script to execute
systemctl enable myapp.service
Is this the correct approach or is there a more 'standard' procedure for handling services within Debian package management?
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: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: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).