Re: [systemd-devel] after=user.slice not enforced

2016-11-24 Thread Michael Chapman

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

2016-11-24 Thread Kai Krakow
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

2016-11-23 Thread Cédric BRINER
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

2016-11-23 Thread Lennart Poettering
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

2016-11-23 Thread 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.


> 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


[systemd-devel] after=user.slice not enforced

2016-11-22 Thread Cédric BRINER
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.

# cat sapRunning.service
[Unit]
Description=SAP Service to ensure stopsap during shutdown
After=local-fs.target network-online.target remote-fs.target user.slice
ora_lsnr_DEV.service

[Service]
ExecStart=/usr/local/bin/sapRunning
ExecStop=/usr/local/bin/stop-sapRunning
Restart=no
TimeoutStopSec=5min

[Install]
WantedBy=multi-user.target

# systemctl status
 CGroup: /
   ├─1 /usr/lib/systemd/systemd --switched-root --system
--deserialize 2
   ├─user.slice
   │ ├─user-0.slice
   │ │ └─session-2.scope
   │ │   ├─15483 sshd: root@pts/0
   │ │   ├─15485 -bash
   │ │   ├─15783 /usr/bin/perl /usr/local/bin/write-sysv-test.pl
   │ │   ├─15800 systemctl status
   │ │   └─15801 less


# systemctl status sysv-test.service
● sysv-test.service - sysv-test
   Loaded: loaded (/etc/systemd/system/sysv-test.service; enabled;
vendor preset: disabled)
   Active: active (exited) since Tue 2016-11-22 10:18:39 CET; 12min ago
  Process: 13688 ExecStart=/usr/bin/true (code=exited, status=0/SUCCESS)
 Main PID: 13688 (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/sysv-test.service

Nov 22 10:18:39 spinelle1 systemd[1]: Started sysv-test.
Nov 22 10:18:39 spinelle1 systemd[1]: Starting sysv-test...


So what did we missed so that the verb stop of sapRunning.service can
not see this write-sysv-test.pl anymore ?

Regards.


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