On 08/06/2017 05:28 AM, Richard Hector wrote:
> On 06/08/17 04:43, Sven Hartge wrote:
>> Harald Dunkel <ha...@afaics.de> wrote:
>>> On Sat, 5 Aug 2017 11:56:07 +0900 Mark Fletcher <mark2...@gmail.com> 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 <service>
>>> 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.
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:
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.