[systemd-devel] Cannot get Shutdown Script to Run (Libvirt Virtual Machine Shutdown)

Alexander Groleau awgneo at xbetanet.com
Sun Sep 21 22:57:46 PDT 2014


I have tried the following script as well during my adventures with no
success:

[Unit]
Description=Start/Stop Libvirt Windows Guest
Documentation=man:libvirtd(8)
Documentation=http://libvirt.org
After=libvirtd.service

[Service]
ExecStart=/usr/bin/libvirt-windows.sh start
ExecStop=/usr/bin/libvirt-windows.sh stop
RemainAfterExit=yes
Type=oneshot
StandardOutput=journal+console

[Install]
WantedBy=multi-user.target

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.

So, still no luck :/

Thanks,
Alex

On Mon, Sep 22, 2014 at 1:49 AM, Andrei Borzenkov <arvidjaar at gmail.com>
wrote:

> On Mon, Sep 22, 2014 at 7:40 AM, Alexander Groleau <awgneo at 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?
> >
> > Thanks so much. <3
> >
> > -Alex
> >
> > Here is my shutdown systemd service configuration:
> >
> > [Unit]
> > Description=Stop Libvirt Windows Guest
> > Documentation=man:libvirtd(8)
> > Documentation=http://libvirt.org
> > Before=shutdown.target
> > DefaultDependencies=no
> >
>
> Why? Do you have special reasons to avoid default dependencies? What
> are these reasons? I suggest removing it - it is always better to
> start with default configuration before customizing it.
>
> Also you do not specify any dependency to other services, so your
> service and libvirtd service are stopped concurrently. To be stopped
> before some other service it needs to be started *after* this service.
> I.e.
>
> After=your-virtd.service
>
> > [Service]
> > ExecStart=/usr/bin/libvirt-windows.sh stop
>
> That's usually does not work, at least when using default
> dependencies. During shutdown services are stopped. And you cannot
> tell it to wait for starting one service before stopping another
> service (I wish it could). So try
>
> RemainAfterExit=true
> ExecStop=/usr/bin/libvirt-windows.sh stop
>
> Not sure if ExecStart is mandatory; if yes, just use /usr/bin/true.
>
> > Type=oneshot
> > StandardOutput=journal+console
> >
> > [Install]
> > WantedBy=shutdown.target
> >
>
> No, you must start it on on boot for above stopping on shutdown to work,
> so use
>
> WantedBy=default.target (or multi-user.target or graphical.target
> depending on your configuration)
>
> > Here is my journalctl log:
> >
> > Sep 21 23:14:53 Xerxes9 systemd-logind[340]: System is rebooting.
> > Sep 21 23:14:53 Xerxes9 libvirtd[605]: End of file while reading data:
> > Input/output error // HERE IS LIBVIRTD TERMINATING
> > Sep 21 23:14:53 Xerxes9 systemd[1]: Failed to reset devices.list on
> > /system.slice: Invalid argument
> > Sep 21 23:14:53 Xerxes9 bluetoothd[458]: Terminating
> > Sep 21 23:14:53 Xerxes9 avahi-daemon[335]: Got SIGTERM, quitting.
> > Sep 21 23:14:53 Xerxes9 ntpd[606]: ntpd exiting on signal 15 (Terminated)
> > Sep 21 23:14:53 Xerxes9 avahi-daemon[335]: Leaving mDNS multicast group
> on
> > interface virbr0.IPv4 with address 192.168.122.1.
> > Sep 21 23:14:53 Xerxes9 ModemManager[338]: <info>  Caught signal,
> shutting
> > down...
> > Sep 21 23:14:53 Xerxes9 avahi-daemon[335]: Leaving mDNS multicast group
> on
> > interface br0.IPv4 with address 192.168.1.2.
> > Sep 21 23:14:53 Xerxes9 NetworkManager[334]: <info> ModemManager
> disappeared
> > from bus
> > Sep 21 23:14:53 Xerxes9 bluetoothd[458]: Stopping SDP server
> > Sep 21 23:14:53 Xerxes9 bluetoothd[458]: Exit
> > Sep 21 23:14:53 Xerxes9 ModemManager[338]: <info>  ModemManager is shut
> down
> > Sep 21 23:14:53 Xerxes9 avahi-daemon[335]: avahi-daemon 0.6.31 exiting.
> > Sep 21 23:14:53 Xerxes9 systemd[681]: Stopping Default.
> > Sep 21 23:14:53 Xerxes9 systemd[681]: Stopped target Default.
> > Sep 21 23:14:53 Xerxes9 systemd[681]: Stopping Basic System.
> > Sep 21 23:14:53 Xerxes9 systemd[681]: Stopped target Basic System.
> > Sep 21 23:14:53 Xerxes9 systemd[681]: Stopping Paths.
> > Sep 21 23:14:53 Xerxes9 systemd[681]: Stopped target Paths.
> > Sep 21 23:14:53 Xerxes9 systemd[681]: Stopping Timers.
> > Sep 21 23:14:53 Xerxes9 systemd[681]: Stopped target Timers.
> > Sep 21 23:14:53 Xerxes9 systemd[681]: Stopping Sockets.
> > Sep 21 23:14:53 Xerxes9 systemd[681]: Stopped target Sockets.
> > Sep 21 23:14:53 Xerxes9 systemd[681]: Starting Shutdown.
> > Sep 21 23:14:53 Xerxes9 systemd[681]: Reached target Shutdown.
> > Sep 21 23:14:53 Xerxes9 systemd[419]: Stopping Default.
> > Sep 21 23:14:53 Xerxes9 systemd[681]: Starting Exit the Session...
> > Sep 21 23:14:53 Xerxes9 systemd[419]: Stopped target Default.
> > Sep 21 23:14:53 Xerxes9 systemd[419]: Stopping Basic System.
> > Sep 21 23:14:53 Xerxes9 systemd[419]: Stopped target Basic System.
> > Sep 21 23:14:53 Xerxes9 systemd[419]: Stopping Paths.
> > Sep 21 23:14:53 Xerxes9 systemd[419]: Stopped target Paths.
> > Sep 21 23:14:53 Xerxes9 systemd[419]: Stopping Timers.
> > Sep 21 23:14:53 Xerxes9 systemd[419]: Stopped target Timers.
> > Sep 21 23:14:53 Xerxes9 systemd[419]: Stopping Sockets.
> > Sep 21 23:14:53 Xerxes9 systemd[419]: Stopped target Sockets.
> > Sep 21 23:14:53 Xerxes9 systemd[419]: Starting Shutdown.
> > Sep 21 23:14:53 Xerxes9 systemd[419]: Reached target Shutdown.
> > Sep 21 23:14:53 Xerxes9 systemd[419]: Starting Exit the Session...
> > Sep 21 23:14:53 Xerxes9 systemd[419]: Received SIGRTMIN+24 from PID 1202
> > (kill).
> > Sep 21 23:14:53 Xerxes9 systemd[681]: Received SIGRTMIN+24 from PID 1197
> > (kill).
> > Sep 21 23:14:53 Xerxes9 systemd[682]: pam_unix(systemd-user:session):
> > session closed for user awgneo
> > Sep 21 23:14:53 Xerxes9 systemd[420]: pam_unix(systemd-user:session):
> > session closed for user lightdm
> > Sep 21 23:14:53 Xerxes9 systemd[1]: pulseaudio.service: main process
> exited,
> > code=exited, status=1/FAILURE
> > Sep 21 23:14:53 Xerxes9 systemd[1]: Unit pulseaudio.service entered
> failed
> > state.
> > Sep 21 23:14:53 Xerxes9 libvirt-windows.sh[1195]: error: failed to
> connect
> > to the hypervisor  // HERE IS MY SCRIPT FAILING
> > Sep 21 23:14:53 Xerxes9 libvirt-windows.sh[1195]: error: Failed to
> connect
> > socket to '/var/run/libvirt/libvirt-sock': No such file or directory
> > ...
> >
> >
> > _______________________________________________
> > systemd-devel mailing list
> > systemd-devel at lists.freedesktop.org
> > http://lists.freedesktop.org/mailman/listinfo/systemd-devel
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20140922/36b2fc0c/attachment-0001.html>


More information about the systemd-devel mailing list