summaryrefslogtreecommitdiffstats
path: root/recipes-extended/libvirt/libvirt/libvirtd.sh
diff options
context:
space:
mode:
Diffstat (limited to 'recipes-extended/libvirt/libvirt/libvirtd.sh')
-rwxr-xr-xrecipes-extended/libvirt/libvirt/libvirtd.sh103
1 files changed, 103 insertions, 0 deletions
diff --git a/recipes-extended/libvirt/libvirt/libvirtd.sh b/recipes-extended/libvirt/libvirt/libvirtd.sh
new file mode 100755
index 00000000..29dbf391
--- /dev/null
+++ b/recipes-extended/libvirt/libvirt/libvirtd.sh
@@ -0,0 +1,103 @@
1#!/bin/sh
2### BEGIN INIT INFO
3# Provides: libvirtd
4# Required-Start: $local_fs $network dbus
5# Required-Stop: $local_fs $network dbus
6# Default-Start: 2 3 4 5
7# Default-Stop: 0 1 6
8### END INIT INFO
9
10if [ -f /lib/lsb/init-functions ]
11then
12 . /lib/lsb/init-functions
13else
14 # int log_begin_message (char *message)
15 log_begin_msg () {
16 if [ -z "$1" ]; then
17 return 1
18 fi
19 echo " * $@"
20 }
21
22 # int log_end_message (int exitstatus)
23 log_end_msg () {
24
25 # If no arguments were passed, return
26 [ -z "$1" ] && return 1
27
28 # Only do the fancy stuff if we have an appropriate terminal
29 # and if /usr is already mounted
30 TPUT=/usr/bin/tput
31 EXPR=/usr/bin/expr
32 if [ -x $TPUT ] && [ -x $EXPR ] && $TPUT hpa 60 >/dev/null 2>&1; then
33 COLS=`$TPUT cols`
34 if [ -n "$COLS" ]; then
35 COL=`$EXPR $COLS - 7`
36 else
37 COL=73
38 fi
39 UP=`$TPUT cuu1`
40 END=`$TPUT hpa $COL`
41 START=`$TPUT hpa 0`
42 RED=`$TPUT setaf 1`
43 NORMAL=`$TPUT op`
44 if [ $1 -eq 0 ]; then
45 echo "$UP$END[ ok ]"
46 else
47 echo -e "$UP$START $RED*$NORMAL$END[${RED}fail${NORMAL}]"
48 fi
49 else
50 if [ $1 -eq 0 ]; then
51 echo " ...done."
52 else
53 echo " ...fail!"
54 fi
55 fi
56 return $1
57 }
58
59 log_warning_msg () {
60 if log_use_fancy_output; then
61 YELLOW=`$TPUT setaf 3`
62 NORMAL=`$TPUT op`
63 echo "$YELLOW*$NORMAL $@"
64 else
65 echo "$@"
66 fi
67 }
68
69fi
70
71case "$1" in
72 start)
73 if [ -e /var/run/libvirtd.pid ]; then
74 if [ -d /proc/$(cat /var/run/libvirtd.pid) ]; then
75 echo "virtualization library already started; not starting."
76 else
77 echo "Removing stale PID file /var/run/libvirtd.pid."
78 rm -f /var/run/libvirtd.pid
79 fi
80 fi
81 log_begin_msg "Starting virtualization library daemon: libvirtd"
82 if [ ! -e /var/run/libvirtd.pid ]; then
83 start-stop-daemon -K -x /usr/bin/dnsmasq --pidfile /var/run/libvirt/network/default.pid
84 fi
85 start-stop-daemon --start --quiet --pidfile /var/run/libvirtd.pid --exec /usr/sbin/libvirtd -- --daemon --listen
86 log_end_msg $?
87 ;;
88 stop)
89 log_begin_msg "Stopping virtualization library daemon: libvirtd"
90 start-stop-daemon --stop --quiet --retry 3 --exec /usr/sbin/libvirtd --pidfile /var/run/libvirtd.pid
91 log_end_msg $?
92 rm -f /var/run/libvirtd.pid
93 ;;
94 restart)
95 $0 stop
96 sleep 1
97 $0 start
98 ;;
99 *)
100 echo "Usage: $0 {start|stop|restart}"
101 exit 1
102 ;;
103esac