IMPORTANT NOTE: The following works for me under Ubuntu. It should work as is under Debian. RPM based distros prevent the auto-start by default, but it may still get you closer to your goal.
In most cases, you want to install it in the multi-user.target
using the install section as follow:
[Install]
WantedBy=multi-user.target
This means the your-package.postinst
script will automatically start the daemon for you.
Note that if you have your own your-package.postinst
script, you have to make sure to include the Debian helper as in:
#!/bin/sh
#DEBHELPER#
...your own script here...
Without the #DEBHELPER#
pattern, the packager will not add the default code and as a result your daemon won't get enabled and started automatically. The code added there will enable and start the service:
systemctl enable <service-name>
systemctl start <service-name>
unless the service is static
(does not have an [Install]
section as shown above.) A static service requires a special command line to be enabled and that's not available by default:
systemctl add-wants multi-user.target <service-name>
As we can see, the command includes multi-user.target
which the default #DEBHELPER#
(systemd, really) has no clue about unless you have an [Install]
section.
Update: In newer versions, the systemd extension is now part of the installation mechanism and the following is not required anymore. For Ubuntu, I think that started with 22.04, maybe 21.10.
The package must also be built with the systemd
extension. This means having the following in your debian/rules
file:
%:
dh $@ --with systemd --parallel
That should get you set.
Just in case, if you wanted to not start the newly installed service, you can actually prevent such by adding the following:
override_dh_installsystemd:
dh_installsystemd --no-start --no-disable
Mix and match as required by your system.