Web lists-archives.com

Re: howto restart a service in postinst script (Stretch and newer)

Hi there,

On 08/04/2017 12:30 PM, Harald Dunkel wrote:
> What is the right way to restart a service from the postinst
> script for Stretch and newer?

The same way as before: if it has both an init script and a
systemd service, just call

invoke-rc.d script restart


invoke-rc.d script restart || :

depending on whether you want errors to be fatal or not.

You could also take a look at what debhelper generates for
you if you use dh_installinit:


(#ERROR_HANDLER# is "exit $?" - without the quotes - by default.)

> Reason for asking is: opensmtpd died once too often when it got
> restarted via invoke-rc.d from a postinst script on my desktop 
> PC.

I just looked at the opensmtpd package: it uses debhelper compat
9, so it defaults to the following behavior on upgrades:

 - prerm of the old package: stops the service
 - dpkg unpacks the new binaries
 - postinst of the new package: starts the service again

See https://wiki.debian.org/MaintainerScripts#Upgrading for a
detailed graph on the order in which the maintainer scripts are
executed in on upgrade.

If restarting opensmtpd fails in your case, this is either

 - a bug in your configuration that leads to opensmtp failing
   to start again


 - a bug in the package (either in how upgrades are handled
   or in how the package works)

But without further details (i.e. what error message was given,
both in the APT output and in the system logs) I don't think
this can be diagnosed further. I can only tell you that from
what I can see the postinst script does the right thing and
that if there's a bug in the package, it's not there but in
some other place.