3 .
/etc
/conf.d
/libvirtd-guests
7 LIBVIRTD_LISTFILE
="/var/state/libvirtd/vm-list"
9 # get guest state by name
10 libvirt_get_guest_state
()
12 virsh
$LIBVIRTD_URI dominfo
"$1" |
grep -E '^State:' |
awk '{print $2}'
15 # list IDs of running guests
18 virsh
$LIBVIRTD_URI list |
awk 'NR > 2 {print $2}'
21 # suspend guest by name
24 virsh
$LIBVIRTD_URI $LIBVIRTD_BYPASS_CACHE managedsave
"$1" >/dev
/null
25 timeout
=$LIBVIRTD_SHUTDOWN_TIMEOUT
26 while [ "$timeout" -gt 0 ]; do
28 timeout
=$
((timeout
- 1))
29 state
=`libvirt_get_guest_state "$1"`
30 [ "x$state" == "xshut" ] && return 0
35 # shutdown guest by name
38 virsh
$LIBVIRTD_URI shutdown
"$1" >/dev
/null
39 timeout
=$LIBVIRTD_SHUTDOWN_TIMEOUT
40 while [ "$timeout" -gt 0 ]; do
42 timeout
=$
((timeout
- 1))
43 state
=`libvirt_get_guest_state "$1"`
44 [ "x$state" != "xshut" ] && return 0
52 virsh
$LIBVIRTD_URI $LIBVIRTD_BYPASS_CACHE start
"$1" >/dev
/null
58 mkdir
-p `dirname $LIBVIRTD_LISTFILE`
59 echo -n >$LIBVIRTD_LISTFILE
60 for i
in `libvirt_list`; do
61 if [ "x$LIBVIRTD_STOP_ACTION" == "xsuspend" ]; then
62 stat_busy
"Suspending libvirtd/$i guest"
65 stat_busy
"Shutting libvirtd/$i guest down"
68 [ $?
-eq 0 ] && stat_done || stat_fail
69 echo $i >>$LIBVIRTD_LISTFILE
76 if [ -f $LIBVIRTD_LISTFILE ]; then
77 for i
in `cat $LIBVIRTD_LISTFILE`; do
78 stat_busy
"Starting/resuming libvirtd/$i guest"
80 [ $?
-eq 0 ] && { sleep $LIBVIRTD_START_DELAY; stat_done
; } || stat_fail
83 rm -f $LIBVIRTD_LISTFILE
92 add_daemon libvirtd-guests
96 rm_daemon libvirtd-guests
104 echo $
"Usage: $0 {start|stop|restart}"