On Sun, 21.09.14 23:40, Alexander Groleau (awg...@xbetanet.com) wrote: > Hello systemd users, > > I have been trying desperately for weeks to get my simple shutdown script > for a Libvirt guest to run before libvirtd is shut down, without success. > Essentially, I need the libvirt-windows.sh script to run before the > libvirtd service is terminated (which occurs right after systemd-logind > outputs its reboot message). How can I get my script into this initial > section of daemon shutdowns, at the top?
If you want to something to have something executed before another unit is stopped, then write a service that has: [Unit] After=otherservice.service [Service] Type=oneshot RemainAfterExit=true ExecStart=/bin/true ExecStop=/your/code [Install] WantedBy=otherservice.service Explanation: The ExecStart=/bin/true we just add because current systemd versions refuse to run service units that have no ExecStart= set. It is on the TODO list to allow services also when they have no ExecStart= but with an ExecStop=, but this has not been implemented yet. The ExecStop= is where you place your code. Type=oneshot + RemainAfterExit=true make sure the service gets started properly and then stays around without any processes. The After= orders the unit after the unit you want to be stopped before. Note that in systemd the shutdown order is always the inverse of the startup order. Hence, if you order your new unit with "After=" after the unit you want to be stopped before, then this has the desired effect. Finally, WantedBy= makes sure you can enable your new unit with "systemctl enable", and the right thing will happen. Lennart -- Lennart Poettering, Red Hat _______________________________________________ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel