Wednesday 13 January 2016

Is it possible to query systemd target?

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBCgAGBQJWlmjpAAoJEOhnXe7L7s6jpuMP/1ZyGpeUZHZ60IwQFNWq9b2u
dhCpyy2GSlgOcYSxydymnX8UEa64aVgCf00fnpaBUOSC1aCM8S2dgEpatvD25C6h
qDljaNBIR0/Tx/keBg0aRAP+LJSxP3IFLw8/yqvUcKCjrWH0harxaH8AaFnUVern
AOMtLCO7WfVQUMXzEztaiguXXAzftYO1mt/m6mOqbCd3cVTFYsF3cp79twjl6aDL
uBZZjwDqjDAPTcJt/r5b4S1QGT8aQQcTgmTdkVToHPJeRrk8gG5wQjt6Lu+Eb2Bi
dpOlJwE/GcNxhH5kB/aElm/aB6m5W88NinKdac/RSEvdVDzuGj3EM15+51qGV2+C
l/1AwWvSW0BlAwoS4zgVgwrbutvlZwX4miyVTAObcvJLy6ULUMrAxTgarx+1VFhC
9dnG4CTnpUWA0B9g0stokuJeubiQ+SkBnRhaOFqHGiEb2BA02at8neKyFwLfSWkz
myKSfYQ3hvEblMBXdMV3Jd7z9UmFPxFUMiyv2ZQ2zirVLDeZW4M/dFIFDf/adXj+
uRLJ+C1natlGeJ0hOKSWPIP5lTFoh7FLhyJw1NzbvN6GGGiasVmIgBCvS/Xu1y8L
7dPwdXdC84LMlqJmu0pVfhbppjnpUhQj582LJlDJtGlOyOQUv0anAbktl58uyP7U
gid4ZGJ4STsu9tPgz4QZ
=t6ae
-----END PGP SIGNATURE-----
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?

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.

-Stefan