Is it possible to query systemd target?

Stefan Bader stefan.bader at
Wed Jan 13 15:10:26 UTC 2016

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?

Long version:

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). 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. And for doing that I might as well introduce a proper xen.service.

Maybe I could use something like "systemctl is-system-running" though that might
be ugly. So I thought I better ask whether anybody had a similar problem and
solved it nicely in the past.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <>

More information about the ubuntu-devel mailing list