[systemd-devel] Systemd and Qemu
Bartek Rekke
bojleros at gmail.com
Tue Sep 3 11:32:35 PDT 2013
Hello!
I'am running Archlinux (recent version) including Systemd and Qemu.
Since killing qemu directly is highly destructive for guest os I want to
shut it gracefully. I think it is obvious nessesity To do so I decided to
use 'net rpc' or qemu monitor command. Both requires networking to be up
and running.
Since My distro does not supply service file at all I wrote several service
files on my own. Without success. I have encouraged following problems:
1. Service file follows:
cut------
[Unit]
Description=QEMU virtual machine %i
After=network.target
Before=shutdown.target reboot.target poweroff.target halt.target
[Service]
Type=forking
KillMode=none
SendSIGKILL=yes
#Environment="type=system-x86-64" "haltcmd=kill -INT $MAINPID"
PIDFile=/run/qemu/%i.pid
EnvironmentFile=/etc/conf.d/qemu.d/%i
ExecStart=/usr/bin/qemu-system-x86_64 -name %i -daemonize -pidfile
/run/qemu/%i.pid -nographic $options
ExecStop=/bin/sh -c ${haltcmd}
TimeoutStartSec=10
TimeoutStopSec=120
[Install]
WantedBy=multi-user.target
cut------
haltcmd="/usr/bin/echo 'system_powerdown' | /usr/bin/nc localhost $port"
Using this setup I am able to start vm at startup or manually from console.
Stopping from console also works. I can see guest stopping as expected. But
after invoking poweroff/reboot systemd does not wait for qemu process to
close.....
2. To workaround problems described in 1 I wrote bash script. See service
file below:
cut---
[Unit]
Description=QEMU virtual machine %i
After=network.target
Before=shutdown.target reboot.target poweroff.target halt.target
[Service]
#Type=oneshot
ExecStart=/etc/rc.d/qemu start %i
ExecStop=/etc/rc.d/qemu stop %i
RemainAfterExit=true
KillMode=none
#TimeoutStartSec=10sec
TimeoutSec="80sec"
[Install]
WantedBy=multi-user.target
cut--
Script qemu when invoked with 'start' runs qemu in daeon mode and exits
with 0 status. This work fine during system startup and manual invoking.
When run with 'stop' 'qemu' script send signal to guest os via net rpc or
qemu monitor. In this case script 'qemu' stay active until timeout occurs
or qemu vm proces stops.
This way when invoked from commandline (systemctl stop qemu at vm) systemctl
exit after actual guest powerdown.
Seems ok but when I issue poweroff/reboot guest is killed in a brutal way.
It is because (afaik) systemd turns network off before closing qemu. It is
clear that this problem is caused by startup/poweroff sequence. During
startup it is required to setup networking before starting any listening
daeon. But when system is going to poweroff/reboot seqence should be: first
close daemons and then turn off network.
Reasuming:
1. I am looking for an advice how to setup different startup and powerdown
sequences. Is it possible at all ??
2. Is it possible to wait for process to exit ? I think this behaviour is
essential when shutting down guest os in a proper way.
3. I know that this is not a proper mailing list but if another way of
making poweroff on quest exists please - let me know.
Thanks
Bartek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/systemd-devel/attachments/20130903/766f1cb1/attachment.html>
More information about the systemd-devel
mailing list