[systemd-devel] shutdown: how to tell systemd to stop a service before killing other processes

Hans-Dieter Doll Hans-Dieter.Doll at drb.insel.de
Sun Aug 25 22:19:50 UTC 2019


Am 25.08.19 um 22:02 schrieb Andrei Borzenkov:
> 25.08.2019 19:57, Hans-Dieter Doll пишет:
>> On shutdown we need to stop a service before systemd begins to kill all processes it does not know.
>> The service is a process supervisor similar to init, which controls all our applications.
>> Our applications must be terminated by this supervisor, otherwise data loss and inconsistencies will occur.
>>
>> The problem is: aside from background processes started by the supervisor, we have applications started in a user
>> session, but which are also controlled by the supervisor.
>> This is something systemd cannot know, and thus it kills these applications in parallel to shutting down our service.
>> So we require systemd to wait for our service to terminate before it begins to kill other processes.
>>
>> From an arch-linux thread in 2017 I concluded this is not possible due to the design of systemd.
>>
>> But I cannot believe we are the only one requiring this.
>> So my question is: is there nowadays some mechanism available to accomplish this?
>>
> 
> If your application runs as part of user systemd instance and assuming
> recent enough systemd you should be able to order user at .service Before
> your supervisor service (via drop-in) so that supervisor will be stopped
> before any user sytsemd instance.

The supervisor (and thus the applications it starts) is part of systemd.

> If your application runs as user session process, I do not think it is
> possible. Session scope unit does not have any Before dependency nor is
> it templateable.

There are also interactive applications started as user sessions.
Some of these must not be killed but terminated by the supervisor,
otherwise we (i.e. our customers) run into trouble.

With pre systemd linux this was not an issue, because the init scripts where called
before anything else got killed. We thought systemd is backward compatible, but in
this respect it is not.
Thank you for clarifying. I only wanted to verify my understanding is right...

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 899 bytes
Desc: OpenPGP digital signature
URL: <https://lists.freedesktop.org/archives/systemd-devel/attachments/20190826/97f42e57/attachment.sig>


More information about the systemd-devel mailing list