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

2017-08-07 Thread Harald Dunkel
Hi Christian,

On Sun, 6 Aug 2017 09:34:31 +0200
Christian Seiler  wrote:

> 
> For things that are only available on systemd (for example if you
> have split the service additionally for systemd, while sysvinit is
> still just a single script) you should use the code that is
> generated from dh_systemd in postinst, which you can see e.g. here:
> 
> http://sources.debian.net/src/debhelper/10.2.5/autoscripts/postinst-systemd-restart/
> 

this appears to be another misunderstanding: I am not restarting 
the packages own service, but *another* service, e.g. opensmtpd. 
My package has just provided the necessary config file.

opensmtpd is not the only package that is just stopped on "invoke-rc.d 
restart" sometimes. I have seen similar problems with sssd and 
zabbix-agent. 

Is it possible that there is a race condition? Do systemd and sysvinit
wait till the old service has exited before restarting a new one?
Esp. opensmtpd, sssd and zabbix-agent manage a set of child services. 
Killing the parent might not be sufficient for cleanup before starting 
a new service.


Regards
Harri



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

2017-08-06 Thread Christian Seiler
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

or

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:

http://sources.debian.net/src/debhelper/10.2.5/autoscripts/postinst-init/

(#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

or 

 - 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.

Regards,
Christian



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

2017-08-06 Thread Christian Seiler
On 08/06/2017 05:28 AM, Richard Hector wrote:
> On 06/08/17 04:43, Sven Hartge wrote:
>> Harald Dunkel  wrote:
>>> On Sat, 5 Aug 2017 11:56:07 +0900 Mark Fletcher  wrote:
 On Fri, Aug 04, 2017 at 12:30:25PM +0200, Harald Dunkel wrote:
>>
> What is the right way to restart a service from the postinst
> script for Stretch and newer?
>>
 I may be misunderstanding your question but on a system that has 
 migrated to systemd, you can restart a service with: 

 systemctl restart 
>>
>>> I think you missed the point. To run it from a postinst script we need
>>> a universal(!) way to restart a service, regardless whether systemd or
>>> sysvinit-core or whatever is installed.
>>
>> invoke-rc.d does just that and is included in postinst by
>> dh_installinit for both SysV-init *and* systemd.
> 
> I've only looked through it briefly, but it looks like it invokes the
> initscript regardless of whether systemd is in use

No. You should only use it for things that also have an init script
so that it doesn't fail on sysvinit systems, but it will invoke
systemd directly if the system is currently systemd.

http://sources.debian.net/src/init-system-helpers/1.48/script/invoke-rc.d/#L542-L592

For things that are only available on systemd (for example if you
have split the service additionally for systemd, while sysvinit is
still just a single script) you should use the code that is
generated from dh_systemd in postinst, which you can see e.g. here:

http://sources.debian.net/src/debhelper/10.2.5/autoscripts/postinst-systemd-restart/

Note that it is important _not_ to call the init script or
systemctl directly from any maintainer scripts, as policy dictates
that the administrator should be able to use a custom script or
program in /usr/sbin/policy-rc.d to influence whether maintainer
scripts actually perform any actions. (For example, in chroots
you can use that to completely disable services from being started
from maintainer scripts.) Both invoke-rc.d and deb-systemd-invoke
will take care of that.

Regards,
Christian



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

2017-08-05 Thread Richard Hector
On 06/08/17 04:43, Sven Hartge wrote:
> Harald Dunkel  wrote:
>> On Sat, 5 Aug 2017 11:56:07 +0900 Mark Fletcher  wrote:
>>> On Fri, Aug 04, 2017 at 12:30:25PM +0200, Harald Dunkel wrote:
> 
 What is the right way to restart a service from the postinst
 script for Stretch and newer?
> 
>>> I may be misunderstanding your question but on a system that has 
>>> migrated to systemd, you can restart a service with: 
>>>
>>> systemctl restart 
> 
>> I think you missed the point. To run it from a postinst script we need
>> a universal(!) way to restart a service, regardless whether systemd or
>> sysvinit-core or whatever is installed.
> 
> invoke-rc.d does just that and is included in postinst by
> dh_installinit for both SysV-init *and* systemd.

I've only looked through it briefly, but it looks like it invokes the
initscript regardless of whether systemd is in use - systemd can run
init scripts, after all - and so it relies on an init script being
present. I guess that's ok if you're the packager, because you can
provide one.

Regardless, I'd tend to ask packaging questions on debian-mentors.

Richard



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

2017-08-05 Thread Sven Hartge
Harald Dunkel  wrote:
> On Sat, 5 Aug 2017 11:56:07 +0900 Mark Fletcher  wrote:
>> On Fri, Aug 04, 2017 at 12:30:25PM +0200, Harald Dunkel wrote:

>>> What is the right way to restart a service from the postinst
>>> script for Stretch and newer?

>> I may be misunderstanding your question but on a system that has 
>> migrated to systemd, you can restart a service with: 
>> 
>> systemctl restart 

> I think you missed the point. To run it from a postinst script we need
> a universal(!) way to restart a service, regardless whether systemd or
> sysvinit-core or whatever is installed.

invoke-rc.d does just that and is included in postinst by
dh_installinit for both SysV-init *and* systemd.

Grüße,
Sven.

-- 
Sigmentation fault. Core dumped.



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

2017-08-04 Thread Mark Fletcher
On Fri, Aug 04, 2017 at 12:30:25PM +0200, Harald Dunkel wrote:
> Hi folks,
> 
> the Debian Policy Manual still talks about "run levels" and
> "init.d scripts" on 
> https://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit .
> No word about systemd and others.
> 
> What is the right way to restart a service from the postinst
> script for Stretch and newer?
> 
> 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 may be misunderstanding your question but on a system that has 
migrated to systemd, you can restart a service with: 

systemctl restart 

For example:

systemctl restart mysql 

restarts a mysql instance if there is one on your machine (it may be 
called mariadb instead, but the mysql service still works, at least on 
my machine it does)

If you are at the end of a script that previously stopped the service, 
you can start it again with

systemctl start 

If the service isn't starting automatically on boot, and you want it to, 
you can get that (if the service is properly set up) with:

systemctl enable 

All these commands have to run with root privilege, either from a root 
shell or via sudo.

Mark



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

2017-08-04 Thread Harald Dunkel
Hi folks,

the Debian Policy Manual still talks about "run levels" and
"init.d scripts" on 
https://www.debian.org/doc/debian-policy/ch-opersys.html#s-sysvinit .
No word about systemd and others.

What is the right way to restart a service from the postinst
script for Stretch and newer?

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.


Every helpful comment is highly appreciated
Harri