dh_installsystemd: don't start on install, but do restart on upgrade - if used
Dear list readers,
I have a question about dh_installsystemd. Sorry if this mailing list is
not the best place; I was unable to find a packaging-specific mailing
list for non-Debian-developers, and the kind folks on IRC did not
possess the answer to my question.
I use debhelper's dh_installsystemd to install a systemd unit. Here is
the behaviour I'm after:
- The unit *is not* started on install.
- If the unit is used, it *is* restarted on upgrade.
In this case, 'used' could mean one of two things, both of which are
fine with me:
- The unit is activated/started at upgrade time.
- The unit is enabled. (Probably neater in case the unit happens to be
deactivated at upgrade time, for whatever reason.)
With dh_installsystemd's `--no-start`, the unit is not started on
install - which I want. But it stops the unit on upgrade, and
-understandably- doesn't start it. I have confirmed this behaviour with
and without `--no-enable`.
Question: how do I let my unit not be started on install, while
restarting it on upgrades (instead of just stopping, as is the case
now), on the condition it's 'used' (definition above)? Should I do my
own thing in postinst? Or does debhelper provide the ideal combination
of flags that I haven't come across yet in dh_installsystemd(1)?
Follow-up question: if I have to start the unit on upgrade in postinst,
is the following acceptable? I'm particularly doubtful about using
deb-systemd-invoke outside debhelper.
```
if [ "$1" = "configure" ] ; then
if [ -d /run/systemd/system ]; then
systemctl --system daemon-reload >/dev/null || true
# $2 = <most-recently-configured-version> = upgrade (not
first install)
if [ -n "$2" ]; then
deb-systemd-invoke restart
'real-paths-watcher.service' >/dev/null || true
fi
fi
fi
```
With kind regards,
William David Edwards
Reply to: