Is it possible to query systemd target?
Stefan Bader
stefan.bader at canonical.com
Wed Jan 13 17:06:01 UTC 2016
On 13.01.2016 17:55, Martin Pitt wrote:
> Hey Stefan,
>
> Stefan Bader [2016-01-13 16:10 +0100]:
>> TL;DR
>> Is it possible to know from a script called via a systemd.service whether a stop
>> action was manually triggered (systemctl) or as part of shutdown/reboot or poweroff?
>
> This is a really slippery slope, and sounds like a big race condition.
> IMHO, if someone or something stops a unit, it should stop. But we can
> arrange for a unit to not get stopped during shutdown, which is IMO a
> cleaner approach to this problem.
Unfortunately the other way round (see below).
>
>> Right now (at least Wily+Xenial) there is a non fatal but annoying problem with
>> Xen. On shutdown/reboot systemd tries to unmount several file systems. One of
>> which is /proc/xen. Right now Xen still uses /etc/init.d/xen for start/stop. The
>> same script is also called via invoke-rc.d from *.prerm/*.postinst (which might
>> be another place to modernize at some point). And because of that there is one
>> daemon (xenstored) that must be kept running on stop (otherwise state info on
>> guests running during the upgrade is lost).
>
> I'm a bit lost here -- what does the xen init.d script have to do with
> cleaning up mounts during shutdown? When you say "systemd tries to
> unmount several file systems", that's happening very late after every
> service has stopped and it basically does the equivalent of "umount -a",
> right? (This is "umount.target", see man systemd.special.)
Right so something (likely the umount.target) does the umount late on shutdown
after all services stopped. xen currently is not a service but sysV script. It
was called but does not stop that one daemon (because the same script is called
on pkg upgrade). And because the daemon keeps the mount busy umount -a fails.
>
> Or do you mean that the xen init script does the umount, but
> has some heuristics to know whether it's during shutdown or during a
> manual "stop"?
>
>> And since xenstored keeps the /proc/xen mount busy there is always a
>> failed unmount on shutdown/reboot. Harmless but not pretty. So I
>> wondered whether I might be able to improve this for Xenial.
>
> This should be possible to do with providing an explicit (instead of
> autogenerated) /lib/systemd/system/proc-xen.mount unit which does not
> do the default "Conflicts=umount.target". This should then keep the
> mount alive all the time. I'll try this tomorrow morning (sorry, need
> to run now). But let's first clarify what you need here.
Right now I quickly hacked the init.d script to stop xenstored when "systemctl
is-system-running" returns anything else than running. This seems to be doing
what I need. If that is an acceptable way of doing this.
-Stefan
>
> Thanks,
>
> Martin
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <https://lists.ubuntu.com/archives/ubuntu-devel/attachments/20160113/76b2cc33/attachment.pgp>
More information about the ubuntu-devel
mailing list