Discussion:
[systemd-devel] blocking service on shutdown
Ralf Sieger
2018-09-02 13:37:16 UTC
Permalink
_______________________________________________
systemd-devel mailing list
systemd-***@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Reindl Harald
2018-09-02 14:17:44 UTC
Permalink
I want my system to pause on shutdown to wait till my backup has
finished if it is running.
 
[Unit]
Description=borg shutdown wait
[Service]
Type=oneshot
ExecStart=/bin/true
RemainAfterExit=true
ExecStop=/usr/local/bin/wait_borg
TimeoutStopSec=600
[Install]
WantedBy=multi-user.target
 
I'm using ubuntu 18.04, systemd 237
 
Manually stopping the service via
systemctl stop borg_wrapper
does wait and thus works.
 
But its not working on normal shutdown/poweroff ...
From the logs I can't even see an entry with
"Stopping borg shutdown wait" in syslog.
 
Does anyone has an idea?
what exactly does "/usr/local/bin/wait_borg"?
why are the no dependecnies to the services it waits for?

"TimeoutStopSec=600" alone does nothing then prevent systemd kills the
whole service bfore that timeout is reached at shutdown
Ralf Sieger
2018-09-02 14:41:29 UTC
Permalink
_______________________________________________
systemd-devel mailing list
systemd-***@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Reindl Harald
2018-09-02 17:51:38 UTC
Permalink
Hi Harald,
 
Post by Reindl Harald
what exactly does "/usr/local/bin/wait_borg"?
Small script which terminates whn no "borg" processes exist any more.
Post by Reindl Harald
why are the no dependecnies to the services it waits for?
The process it waits for is not a service but a normal user program.
 
Post by Reindl Harald
"TimeoutStopSec=600" alone does nothing then prevent systemd kills the
whole service bfore that timeout is reached at shutdown
You mean at shutdown this timeout is ignored?
no, i did not say that - i said it's the timeout after ExecStop will be
killed

the service below waits as expected until ExecStop has finish which is
when VMare Workstation powered off the guest after shtdown within it
triggered by open-vm-tools and has a limit of 5 minutes to do so

--------------

[***@srv-rhsoft:~]$ cat /etc/systemd/system/guest-testserver.service
[Unit]
Description=VMware-Guest Testserver
PartOf=vmware-guest.target
Requisite=vmware.service
After=vmware-vmnet.service iptables.service

[Service]
Type=oneshot
RemainAfterExit=yes
Nice=19
IOSchedulingClass=idle
User=vmware
Group=vmware
ExecStart=/usr/bin/vmrun -T ws start '/vms/testserver/config.vmx' nogui
ExecReload=-/usr/bin/vmrun -T ws reset '/vms/testserver/config.vmx'
nogui soft
ExecStop=-/usr/bin/vmrun -T ws stop '/vms/testserver/config.vmx' nogui soft
TimeoutSec=300
ReadOnlyPaths=/etc
ReadOnlyPaths=/usr
CapabilityBoundingSet=~CAP_AUDIT_CONTROL CAP_AUDIT_WRITE CAP_SYS_ADMIN
CAP_SYS_BOOT CAP_SYS_PTRACE

IPAddressDeny=any
IPAddressAllow=localhost

[Install]
WantedBy=vmware-guest.target
Michael Biebl
2018-09-02 17:15:42 UTC
Permalink
Hi,
I want my system to pause on shutdown to wait till my backup has finished if
it is running.
I would suggest using an inhibitor lock when running your backup.
See https://www.freedesktop.org/wiki/Software/systemd/inhibit/

That's exactly the use-case it was designed for.
--
Why is it that all of the instruments seeking intelligent life in the
universe are pointed away from Earth?
Ralf Sieger
2018-09-04 16:17:21 UTC
Permalink
_______________________________________________
systemd-devel mailing list
systemd-***@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Michael Biebl
2018-09-04 16:40:06 UTC
Permalink
Hi Michael,
- block will let shutdown, etc. fail, I do only need a pause/wait
- delay does not work with reboot
It should work for shutdown, i.e. reboot.
--
Why is it that all of the instruments seeking intelligent life in the
universe are pointed away from Earth?
Ralf Sieger
2018-09-04 16:53:56 UTC
Permalink
_______________________________________________
systemd-devel mailing list
systemd-***@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Michael Biebl
2018-09-05 16:00:26 UTC
Permalink
Well, it does wait when I press the power button on the case.
It does not wait if I enter as root poweroff or reboot.
I assume the first one goes through the logind while the second case does straight to systemd...
You are correct. Inhibitors (currently) only block if the request
comes from an unprivileged user.
I guess the reason behind that is, that you could circumvent that
anyway, if you are root.

See https://github.com/systemd/systemd/issues/2680

Personally I would find it useful if systemd-inhibit would have a
switch to also respect inhibitors for root.
--
Why is it that all of the instruments seeking intelligent life in the
universe are pointed away from Earth?
Amit Saha
2018-09-02 22:04:18 UTC
Permalink
Hi Ralf,
Hi,
I want my system to pause on shutdown to wait till my backup has finished
if it is running.
[Unit]
Description=borg shutdown wait
[Service]
Type=oneshot
ExecStart=/bin/true
RemainAfterExit=true
ExecStop=/usr/local/bin/wait_borg
TimeoutStopSec=600
[Install]
WantedBy=multi-user.target
I'm using ubuntu 18.04, systemd 237
Manually stopping the service via
systemctl stop borg_wrapper
does wait and thus works.
But its not working on normal shutdown/poweroff ...
From the logs I can't even see an entry with
"Stopping borg shutdown wait" in syslog.
Does anyone has an idea?
I had to achieve something similar a while back and this is how I ended up
doing:

https://echorand.me/doing-something-before-systemd-shuts-your-supervisord-down.html

Hope it helps.
Regards,
Ralf
_______________________________________________
systemd-devel mailing list
https://lists.freedesktop.org/mailman/listinfo/systemd-devel
Reindl Harald
2018-09-03 00:20:03 UTC
Permalink
Post by Amit Saha
I had to achieve something similar a while back and this is how I ended
up doing: 
https://echorand.me/doing-something-before-systemd-shuts-your-supervisord-down.html
when "ExecStop=/bin/sleep 300" is the solution if want my problems back
Lennart Poettering
2018-09-10 18:48:46 UTC
Permalink
Hi,
I want my system to pause on shutdown to wait till my backup has finished
if it is running.
[Unit]
Description=borg shutdown wait
[Service]
Type=oneshot
ExecStart=/bin/true
RemainAfterExit=true
ExecStop=/usr/local/bin/wait_borg
TimeoutStopSec=600
[Install]
WantedBy=multi-user.target
I'm using ubuntu 18.04, systemd 237
Manually stopping the service via
systemctl stop borg_wrapper
does wait and thus works.
But its not working on normal shutdown/poweroff ...
From the logs I can't even see an entry with
"Stopping borg shutdown wait" in syslog.
Does anyone has an idea?
Note that you need to start (i.e. enable) the service first for this
to work. In systemd only stuff that is started gets stopped...

I presume "wait_borg" talks to some other service "borg" waiting for
it to complet what it is doing? Note that with the above you are not
ordering the main "borg" service against your wait service, which
means the "borg" service might get stopped in parallel with your wait
service. You probably want a "After=borg.service" or so in the
[Service] section of your wait service (this is because the shutdown
order of services is always the reverse of the start-up order of
services in systemd, and with After=borg.service you hence say that
your service shall be terminated first, and borg.service shall be
terminated only after it finished.

Lennart
--
Lennart Poettering, Red Hat
Loading...