<div dir="ltr">I have tried the following script as well during my adventures with no success:<div><br></div><div><div style="font-family:arial,sans-serif;font-size:13px">[Unit]</div><div style="font-family:arial,sans-serif;font-size:13px">Description=Start/Stop Libvirt Windows Guest</div><div style="font-family:arial,sans-serif;font-size:13px">Documentation=man:libvirtd(8)</div><div style="font-family:arial,sans-serif;font-size:13px">Documentation=<a href="http://libvirt.org/" target="_blank">http://libvirt.org</a></div><div style="font-family:arial,sans-serif;font-size:13px">After=libvirtd.service</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">[Service]</div><div style="font-family:arial,sans-serif;font-size:13px">ExecStart=/usr/bin/libvirt-windows.sh start</div><div style="font-family:arial,sans-serif;font-size:13px">ExecStop=/usr/bin/libvirt-windows.sh stop<br></div><div style="font-family:arial,sans-serif;font-size:13px">RemainAfterExit=yes</div><div style="font-family:arial,sans-serif;font-size:13px">Type=oneshot</div><div style="font-family:arial,sans-serif;font-size:13px">StandardOutput=journal+console</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">[Install]</div><div style="font-family:arial,sans-serif;font-size:13px">WantedBy=multi-user.target</div></div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">This works for boot (my sh script is run right after libvirtd is started); however, the libvirtd daemon, started by libvirtd.service, is always terminated well before my sh is run on shutdown/reboot. The reverse order is not happening as it logically should. I will post the journal for this script shortly.</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">So, still no luck :/</div><div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">Thanks,</div><div style="font-family:arial,sans-serif;font-size:13px">Alex</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Sep 22, 2014 at 1:49 AM, Andrei Borzenkov <span dir="ltr"><<a href="mailto:arvidjaar@gmail.com" target="_blank">arvidjaar@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Mon, Sep 22, 2014 at 7:40 AM, Alexander Groleau <<a href="mailto:awgneo@xbetanet.com">awgneo@xbetanet.com</a>> wrote:<br>
> Hello systemd users,<br>
><br>
> I have been trying desperately for weeks to get my simple shutdown script<br>
> for a Libvirt guest to run before libvirtd is shut down, without success.<br>
> Essentially, I need the libvirt-windows.sh script to run before the libvirtd<br>
> service is terminated (which occurs right after systemd-logind outputs its<br>
> reboot message). How can I get my script into this initial section of daemon<br>
> shutdowns, at the top?<br>
><br>
> Thanks so much. <3<br>
><br>
> -Alex<br>
><br>
> Here is my shutdown systemd service configuration:<br>
><br>
> [Unit]<br>
> Description=Stop Libvirt Windows Guest<br>
> Documentation=man:libvirtd(8)<br>
> Documentation=<a href="http://libvirt.org" target="_blank">http://libvirt.org</a><br>
> Before=shutdown.target<br>
> DefaultDependencies=no<br>
><br>
<br>
</span>Why? Do you have special reasons to avoid default dependencies? What<br>
are these reasons? I suggest removing it - it is always better to<br>
start with default configuration before customizing it.<br>
<br>
Also you do not specify any dependency to other services, so your<br>
service and libvirtd service are stopped concurrently. To be stopped<br>
before some other service it needs to be started *after* this service.<br>
I.e.<br>
<br>
After=your-virtd.service<br>
<br>
> [Service]<br>
> ExecStart=/usr/bin/libvirt-windows.sh stop<br>
<br>
That's usually does not work, at least when using default<br>
dependencies. During shutdown services are stopped. And you cannot<br>
tell it to wait for starting one service before stopping another<br>
service (I wish it could). So try<br>
<br>
RemainAfterExit=true<br>
ExecStop=/usr/bin/libvirt-windows.sh stop<br>
<br>
Not sure if ExecStart is mandatory; if yes, just use /usr/bin/true.<br>
<br>
> Type=oneshot<br>
> StandardOutput=journal+console<br>
><br>
> [Install]<br>
> WantedBy=shutdown.target<br>
><br>
<br>
No, you must start it on on boot for above stopping on shutdown to work, so use<br>
<br>
WantedBy=default.target (or multi-user.target or graphical.target<br>
depending on your configuration)<br>
<div><div class="h5"><br>
> Here is my journalctl log:<br>
><br>
> Sep 21 23:14:53 Xerxes9 systemd-logind[340]: System is rebooting.<br>
> Sep 21 23:14:53 Xerxes9 libvirtd[605]: End of file while reading data:<br>
> Input/output error // HERE IS LIBVIRTD TERMINATING<br>
> Sep 21 23:14:53 Xerxes9 systemd[1]: Failed to reset devices.list on<br>
> /system.slice: Invalid argument<br>
> Sep 21 23:14:53 Xerxes9 bluetoothd[458]: Terminating<br>
> Sep 21 23:14:53 Xerxes9 avahi-daemon[335]: Got SIGTERM, quitting.<br>
> Sep 21 23:14:53 Xerxes9 ntpd[606]: ntpd exiting on signal 15 (Terminated)<br>
> Sep 21 23:14:53 Xerxes9 avahi-daemon[335]: Leaving mDNS multicast group on<br>
> interface virbr0.IPv4 with address 192.168.122.1.<br>
> Sep 21 23:14:53 Xerxes9 ModemManager[338]: <info> Caught signal, shutting<br>
> down...<br>
> Sep 21 23:14:53 Xerxes9 avahi-daemon[335]: Leaving mDNS multicast group on<br>
> interface br0.IPv4 with address 192.168.1.2.<br>
> Sep 21 23:14:53 Xerxes9 NetworkManager[334]: <info> ModemManager disappeared<br>
> from bus<br>
> Sep 21 23:14:53 Xerxes9 bluetoothd[458]: Stopping SDP server<br>
> Sep 21 23:14:53 Xerxes9 bluetoothd[458]: Exit<br>
> Sep 21 23:14:53 Xerxes9 ModemManager[338]: <info> ModemManager is shut down<br>
> Sep 21 23:14:53 Xerxes9 avahi-daemon[335]: avahi-daemon 0.6.31 exiting.<br>
> Sep 21 23:14:53 Xerxes9 systemd[681]: Stopping Default.<br>
> Sep 21 23:14:53 Xerxes9 systemd[681]: Stopped target Default.<br>
> Sep 21 23:14:53 Xerxes9 systemd[681]: Stopping Basic System.<br>
> Sep 21 23:14:53 Xerxes9 systemd[681]: Stopped target Basic System.<br>
> Sep 21 23:14:53 Xerxes9 systemd[681]: Stopping Paths.<br>
> Sep 21 23:14:53 Xerxes9 systemd[681]: Stopped target Paths.<br>
> Sep 21 23:14:53 Xerxes9 systemd[681]: Stopping Timers.<br>
> Sep 21 23:14:53 Xerxes9 systemd[681]: Stopped target Timers.<br>
> Sep 21 23:14:53 Xerxes9 systemd[681]: Stopping Sockets.<br>
> Sep 21 23:14:53 Xerxes9 systemd[681]: Stopped target Sockets.<br>
> Sep 21 23:14:53 Xerxes9 systemd[681]: Starting Shutdown.<br>
> Sep 21 23:14:53 Xerxes9 systemd[681]: Reached target Shutdown.<br>
> Sep 21 23:14:53 Xerxes9 systemd[419]: Stopping Default.<br>
> Sep 21 23:14:53 Xerxes9 systemd[681]: Starting Exit the Session...<br>
> Sep 21 23:14:53 Xerxes9 systemd[419]: Stopped target Default.<br>
> Sep 21 23:14:53 Xerxes9 systemd[419]: Stopping Basic System.<br>
> Sep 21 23:14:53 Xerxes9 systemd[419]: Stopped target Basic System.<br>
> Sep 21 23:14:53 Xerxes9 systemd[419]: Stopping Paths.<br>
> Sep 21 23:14:53 Xerxes9 systemd[419]: Stopped target Paths.<br>
> Sep 21 23:14:53 Xerxes9 systemd[419]: Stopping Timers.<br>
> Sep 21 23:14:53 Xerxes9 systemd[419]: Stopped target Timers.<br>
> Sep 21 23:14:53 Xerxes9 systemd[419]: Stopping Sockets.<br>
> Sep 21 23:14:53 Xerxes9 systemd[419]: Stopped target Sockets.<br>
> Sep 21 23:14:53 Xerxes9 systemd[419]: Starting Shutdown.<br>
> Sep 21 23:14:53 Xerxes9 systemd[419]: Reached target Shutdown.<br>
> Sep 21 23:14:53 Xerxes9 systemd[419]: Starting Exit the Session...<br>
> Sep 21 23:14:53 Xerxes9 systemd[419]: Received SIGRTMIN+24 from PID 1202<br>
> (kill).<br>
> Sep 21 23:14:53 Xerxes9 systemd[681]: Received SIGRTMIN+24 from PID 1197<br>
> (kill).<br>
> Sep 21 23:14:53 Xerxes9 systemd[682]: pam_unix(systemd-user:session):<br>
> session closed for user awgneo<br>
> Sep 21 23:14:53 Xerxes9 systemd[420]: pam_unix(systemd-user:session):<br>
> session closed for user lightdm<br>
> Sep 21 23:14:53 Xerxes9 systemd[1]: pulseaudio.service: main process exited,<br>
> code=exited, status=1/FAILURE<br>
> Sep 21 23:14:53 Xerxes9 systemd[1]: Unit pulseaudio.service entered failed<br>
> state.<br>
> Sep 21 23:14:53 Xerxes9 libvirt-windows.sh[1195]: error: failed to connect<br>
> to the hypervisor // HERE IS MY SCRIPT FAILING<br>
> Sep 21 23:14:53 Xerxes9 libvirt-windows.sh[1195]: error: Failed to connect<br>
> socket to '/var/run/libvirt/libvirt-sock': No such file or directory<br>
> ...<br>
><br>
><br>
</div></div>> _______________________________________________<br>
> systemd-devel mailing list<br>
> <a href="mailto:systemd-devel@lists.freedesktop.org">systemd-devel@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/systemd-devel" target="_blank">http://lists.freedesktop.org/mailman/listinfo/systemd-devel</a><br>
><br>
</blockquote></div><br></div>