|
0 |
#! /bin/sh
|
|
1 |
#
|
|
2 |
# Init skript for libvirtd
|
|
3 |
#
|
|
4 |
# (c) 2007 Guido Guenther <agx@sigxcpu.org>
|
|
5 |
# based on the skeletons that comes with dh_make
|
|
6 |
#
|
|
7 |
### BEGIN INIT INFO
|
|
8 |
# Provides: libvirtd
|
|
9 |
# Required-Start: $network $local_fs
|
|
10 |
# Required-Stop:
|
|
11 |
# Default-Start: 2 3 4 5
|
|
12 |
# Default-Stop: 0 1 6
|
|
13 |
# Short-Description: libvirt management daemon
|
|
14 |
### END INIT INFO
|
|
15 |
|
|
16 |
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
|
|
17 |
DAEMON=/usr/sbin/libvirtd
|
|
18 |
NAME=libvirtd
|
|
19 |
DESC="libvirt management daemon"
|
|
20 |
|
|
21 |
test -x $DAEMON || exit 0
|
|
22 |
. /lib/lsb/init-functions
|
|
23 |
|
|
24 |
PIDFILE=/var/run/$NAME.pid
|
|
25 |
DODTIME=1 # Time to wait for the server to die, in seconds
|
|
26 |
|
|
27 |
# Include libvirtd defaults if available
|
|
28 |
if [ -f /etc/default/libvirt-bin ] ; then
|
|
29 |
. /etc/default/libvirt-bin
|
|
30 |
fi
|
|
31 |
|
|
32 |
set -e
|
|
33 |
|
|
34 |
check_start_libvirtd_option() {
|
|
35 |
if [ ! "$start_libvirtd" = "yes" ]; then
|
|
36 |
log_warning_msg "Not starting libvirt management daemon libvirtd, disabled via /etc/default/libvirt-bin"
|
|
37 |
return 1
|
|
38 |
else
|
|
39 |
return 0
|
|
40 |
fi
|
|
41 |
}
|
|
42 |
|
|
43 |
running_pid()
|
|
44 |
{
|
|
45 |
# Check if a given process pid's cmdline matches a given name
|
|
46 |
pid=$1
|
|
47 |
name=$2
|
|
48 |
[ -z "$pid" ] && return 1
|
|
49 |
[ ! -d /proc/$pid ] && return 1
|
|
50 |
cmd=`cat /proc/$pid/cmdline | tr "\000" "\n"|head -n 1 |cut -d : -f 1`
|
|
51 |
# Is this the expected child?
|
|
52 |
[ "$cmd" != "$name" ] && return 1
|
|
53 |
return 0
|
|
54 |
}
|
|
55 |
|
|
56 |
running()
|
|
57 |
{
|
|
58 |
# Check if the process is running looking at /proc
|
|
59 |
# (works for all users)
|
|
60 |
# No pidfile, probably no daemon present
|
|
61 |
[ ! -f "$PIDFILE" ] && return 1
|
|
62 |
# Obtain the pid and check it against the binary name
|
|
63 |
pid=`cat $PIDFILE`
|
|
64 |
running_pid $pid $DAEMON || return 1
|
|
65 |
return 0
|
|
66 |
}
|
|
67 |
|
|
68 |
force_stop() {
|
|
69 |
# Forcefully kill the process
|
|
70 |
[ ! -f "$PIDFILE" ] && return
|
|
71 |
if running ; then
|
|
72 |
kill -15 $pid
|
|
73 |
# Is it really dead?
|
|
74 |
[ -n "$DODTIME" ] && sleep "$DODTIME"s
|
|
75 |
if running ; then
|
|
76 |
kill -9 $pid
|
|
77 |
[ -n "$DODTIME" ] && sleep "$DODTIME"s
|
|
78 |
if running ; then
|
|
79 |
echo "Cannot kill $LABEL (pid=$pid)!"
|
|
80 |
exit 1
|
|
81 |
fi
|
|
82 |
fi
|
|
83 |
fi
|
|
84 |
rm -f $PIDFILE
|
|
85 |
return 0
|
|
86 |
}
|
|
87 |
|
|
88 |
case "$1" in
|
|
89 |
start)
|
|
90 |
if check_start_libvirtd_option; then
|
|
91 |
log_daemon_msg "Starting $DESC" "$NAME"
|
|
92 |
if running ; then
|
|
93 |
log_progress_msg "already running"
|
|
94 |
log_end_msg 0
|
|
95 |
exit 0
|
|
96 |
fi
|
|
97 |
start-stop-daemon --start --quiet --pidfile $PIDFILE \
|
|
98 |
--exec $DAEMON -- $libvirtd_opts
|
|
99 |
running && log_end_msg 0 || log_end_msg 1
|
|
100 |
fi
|
|
101 |
;;
|
|
102 |
stop)
|
|
103 |
log_daemon_msg "Stopping $DESC" "$NAME"
|
|
104 |
if ! running ; then
|
|
105 |
log_progress_msg "not running"
|
|
106 |
log_end_msg 0
|
|
107 |
exit 0
|
|
108 |
fi
|
|
109 |
start-stop-daemon --stop --quiet --pidfile $PIDFILE \
|
|
110 |
--exec $DAEMON
|
|
111 |
log_end_msg 0
|
|
112 |
;;
|
|
113 |
force-stop)
|
|
114 |
log_daemon_msg "Forcefully stopping $DESC" "$NAME"
|
|
115 |
force_stop
|
|
116 |
! running && log_end_msg 0 || log_end_msg 1
|
|
117 |
;;
|
|
118 |
force-reload)
|
|
119 |
# check wether $DAEMON is running. If so, restart
|
|
120 |
start-stop-daemon --stop --test --quiet --pidfile \
|
|
121 |
/var/run/$NAME.pid --exec $DAEMON \
|
|
122 |
&& $0 restart || exit 0
|
|
123 |
;;
|
|
124 |
restart)
|
|
125 |
if check_start_libvirtd_option; then
|
|
126 |
log_daemon_msg "Restarting $DESC" "$DAEMON"
|
|
127 |
start-stop-daemon --oknodo --stop --quiet --pidfile \
|
|
128 |
/var/run/$NAME.pid --exec $DAEMON
|
|
129 |
[ -n "$DODTIME" ] && sleep $DODTIME
|
|
130 |
start-stop-daemon --start --quiet --pidfile \
|
|
131 |
/var/run/$NAME.pid --exec $DAEMON -- $libvirtd_opts
|
|
132 |
running && log_end_msg 0 || log_end_msg 1
|
|
133 |
fi
|
|
134 |
;;
|
|
135 |
status)
|
|
136 |
log_daemon_msg "Checking status of $DESC" "$NAME"
|
|
137 |
if running ; then
|
|
138 |
log_progress_msg "running"
|
|
139 |
log_end_msg 0
|
|
140 |
else
|
|
141 |
log_progress_msg "not running"
|
|
142 |
log_end_msg 1
|
|
143 |
fi
|
|
144 |
;;
|
|
145 |
*)
|
|
146 |
N=/etc/init.d/libvirt-bin
|
|
147 |
# echo "Usage: $N {start|stop|restart|reload|force-reload}" >&2
|
|
148 |
echo "Usage: $N {start|stop|restart|force-reload|status|force-stop}" >&2
|
|
149 |
exit 1
|
|
150 |
;;
|
|
151 |
esac
|
|
152 |
|
|
153 |
exit 0
|