Re: [systemd-devel] after=user.slice not enforced
On Thu, 24 Nov 2016, Kai Krakow wrote: Am Wed, 23 Nov 2016 09:14:34 +0100 schrieb Cédric BRINER : Hi, For the context, we are trying to stop a daemon launched by a user... Hi, sapRunning service contains a "After=user.slice". But at the shutdown, a process (write-sysv-test.pl) running in user.slice is killed before the end of the sapRunning's stop. Slices are a concept for resource management, and that's what they should be used for. Do not user them for anything else, such as ordering purposes. In systemd shutdown ordering is the inverse of start-up ordering, and After= and Before= declare the latter. This means that if your service has After=user.slice, this means at shutdown your service will be stopped first and user.slice second. Thanks for the clarification. But this has not the expected impact. We were wishing with the "After=user.slice", that the stop sapRunning will occur before any user commands are stopped. Does using "After=user.slice" propagate also on all the *childs*. That way we could ensure that our stop services' commmand is launched as the first ever before any kill ? The question still remain for us, how can we do to have a daemon launched by hand, that can be handled by systemd for its stopping. I think you could maybe use targets as synchronizations points... Maybe make a target that starts after multi-user.target and requires it. Then put your service as wanted by this new target (maybe also using after and requires), let's call it sap-started.target. Then make that the default target at boot. That way, on shutdown, it should first stop and wait for sap-started.target, and only then pull down the rest of the system. Simply ordering target units won't help. At boot, systemd does not wait for the first target to be reached before considering starting the units wanted by the second target. Similarly, at shutdown it will not wait for the second group of units to be stopped before stopping the first group of units -- indeed, the target units themselves could be stopped almost immediately. What you can do is have something like this: [Unit] After=multi-user.target [Install] WantedBy=multi-user.target Normally, this unit would be Before=multi-user.target (this is an implicit dependency added when a target Wants= something). By adding an explicit After=multi-user.target dependency, however, you can override this. A unit with this dependency will be "started late" and "stopped early". However, this doesn't really do anything to order it with respect to user sessions. As described elsewhere in this thread, there's no clean way to do that. - Michael___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] after=user.slice not enforced
Am Wed, 23 Nov 2016 09:14:34 +0100 schrieb Cédric BRINER : > Hi, > > For the context, we are trying to stop a daemon launched by a user... > > >> Hi, > >> > >> sapRunning service contains a "After=user.slice". But at the > >> shutdown, a process (write-sysv-test.pl) running in user.slice is > >> killed before the end of the sapRunning's stop. > > > > Slices are a concept for resource management, and that's what they > > should be used for. Do not user them for anything else, such as > > ordering purposes. > > > > In systemd shutdown ordering is the inverse of start-up ordering, > > and After= and Before= declare the latter. This means that if your > > service has After=user.slice, this means at shutdown your service > > will be stopped first and user.slice second. > Thanks for the clarification. > > But this has not the expected impact. We were wishing with the > "After=user.slice", that the stop sapRunning will occur before any > user commands are stopped. > > Does using "After=user.slice" propagate also on all the *childs*. That > way we could ensure that our stop services' commmand is launched as > the first ever before any kill ? > > The question still remain for us, how can we do to have a daemon > launched by hand, that can be handled by systemd for its stopping. I think you could maybe use targets as synchronizations points... Maybe make a target that starts after multi-user.target and requires it. Then put your service as wanted by this new target (maybe also using after and requires), let's call it sap-started.target. Then make that the default target at boot. That way, on shutdown, it should first stop and wait for sap-started.target, and only then pull down the rest of the system. But what's the purpose of stopping user processes only after this service was stopped? This does make no sense to me. I'd instead define proper dependencies. -- Regards, Kai Replies to list-only preferred. ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] after=user.slice not enforced
Hi, >> But this has not the expected impact. We were wishing with the >> "After=user.slice", that the stop sapRunning will occur before any user >> commands are stopped. >> >> Does using "After=user.slice" propagate also on all the >> *children*. That way we could ensure that our stop services' >> commmand is launched as the first ever before any kill ? > > No it does not. Unit dependencies apply to each unit individually and > they do not propagate That confirm my thoughts! >> The question still remain for us, how can we do to have a daemon >> launched by hand, that can be handled by systemd for its stopping. > > You cannot. Either systemd execs your daemon and then also stops > it. Or you exec it, and then you stop it. There's no concept for > making systemd adopt foreign services... Many thanks. What you said is very clear and helpfull. > (Not sure I grok what you want to do, but do note that "systemd-run" > may be used to invoke binaries as services without prepping a unit > file for it, instead providing all the definitions on the command > line) I'll get to a look at this also. > Lennart cED -- Cédric BRINER, Ing. EPFL & HES +41 (0)22 / 379 71 83 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] after=user.slice not enforced
On Wed, 23.11.16 09:14, Cédric BRINER (cedric.bri...@unige.ch) wrote: > Hi, > > For the context, we are trying to stop a daemon launched by a user... > > >> Hi, > >> > >> sapRunning service contains a "After=user.slice". But at the shutdown, a > >> process (write-sysv-test.pl) running in user.slice is killed before the > >> end of the sapRunning's stop. > > > > Slices are a concept for resource management, and that's what they > > should be used for. Do not user them for anything else, such as > > ordering purposes. > > > > In systemd shutdown ordering is the inverse of start-up ordering, and > > After= and Before= declare the latter. This means that if your service > > has After=user.slice, this means at shutdown your service will be > > stopped first and user.slice second. > Thanks for the clarification. > > But this has not the expected impact. We were wishing with the > "After=user.slice", that the stop sapRunning will occur before any user > commands are stopped. > > Does using "After=user.slice" propagate also on all the > *children*. That way we could ensure that our stop services' > commmand is launched as the first ever before any kill ? No it does not. Unit dependencies apply to each unit individually and they do not propagate > The question still remain for us, how can we do to have a daemon > launched by hand, that can be handled by systemd for its stopping. You cannot. Either systemd execs your daemon and then also stops it. Or you exec it, and then you stop it. There's no concept for making systemd adopt foreign services... (Not sure I grok what you want to do, but do note that "systemd-run" may be used to invoke binaries as services without prepping a unit file for it, instead providing all the definitions on the command line) systemd provides a clean, well-defined execution environment to every service, as such it really doesn't permit sysv-like behaviour that daemon processes are forked off random user processes. Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] after=user.slice not enforced
Hi, For the context, we are trying to stop a daemon launched by a user... >> Hi, >> >> sapRunning service contains a "After=user.slice". But at the shutdown, a >> process (write-sysv-test.pl) running in user.slice is killed before the >> end of the sapRunning's stop. > > Slices are a concept for resource management, and that's what they > should be used for. Do not user them for anything else, such as > ordering purposes. > > In systemd shutdown ordering is the inverse of start-up ordering, and > After= and Before= declare the latter. This means that if your service > has After=user.slice, this means at shutdown your service will be > stopped first and user.slice second. Thanks for the clarification. But this has not the expected impact. We were wishing with the "After=user.slice", that the stop sapRunning will occur before any user commands are stopped. Does using "After=user.slice" propagate also on all the *childs*. That way we could ensure that our stop services' commmand is launched as the first ever before any kill ? The question still remain for us, how can we do to have a daemon launched by hand, that can be handled by systemd for its stopping. > Lennart cED -- Cédric BRINER, Ing. EPFL & HES +41 (0)22 / 379 71 83 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] after=user.slice not enforced
On Tue, 22.11.16 16:53, Cédric BRINER (cedric.bri...@unige.ch) wrote: > Hi, > > sapRunning service contains a "After=user.slice". But at the shutdown, a > process (write-sysv-test.pl) running in user.slice is killed before the > end of the sapRunning's stop. Slices are a concept for resource management, and that's what they should be used for. Do not user them for anything else, such as ordering purposes. In systemd shutdown ordering is the inverse of start-up ordering, and After= and Before= declare the latter. This means that if your service has After=user.slice, this means at shutdown your service will be stopped first and user.slice second. Lennart -- Lennart Poettering, Red Hat ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/systemd-devel