]>
Commit | Line | Data |
---|---|---|
ccb0f0ea AM |
1 | #!/bin/sh |
2 | # | |
3 | # qemu-ga qemu-ga QEMU Guest Agent | |
4 | # | |
5 | # chkconfig: 345 12 88 | |
6 | # | |
7 | # description: qemu-ga QEMU Guest Agent | |
8 | ||
9 | # Source function library | |
10 | . /etc/rc.d/init.d/functions | |
11 | ||
12 | # Get service config - may override defaults | |
13 | [ -f /etc/sysconfig/qemu-ga ] && . /etc/sysconfig/qemu-ga | |
14 | ||
15 | pidfile="/var/run/qemu-ga.pid" | |
16 | ||
17 | # configtest itself | |
18 | # must return non-zero if check failed | |
19 | # output is discarded if checkconfig is ran without details | |
20 | configtest() { | |
21 | /usr/bin/qemu-ga -D | |
22 | return $? | |
23 | } | |
24 | ||
25 | # wrapper for configtest | |
26 | checkconfig() { | |
27 | local details=${1:-0} | |
28 | ||
29 | if [ $details = 1 ]; then | |
30 | # run config test and display report (status action) | |
31 | show "Checking %s configuration" "qemu-ga"; busy | |
32 | local out | |
33 | out=$(configtest 2>&1) | |
34 | RETVAL=$? | |
35 | if [ $RETVAL = 0 ]; then | |
36 | ok | |
37 | else | |
38 | fail | |
39 | fi | |
40 | [ "$out" ] && echo >&2 "$out" | |
41 | else | |
42 | # run config test and abort with nice message if failed | |
43 | # (for actions checking status before action). | |
44 | configtest >/dev/null 2>&1 | |
45 | RETVAL=$? | |
46 | if [ $RETVAL != 0 ]; then | |
47 | show "Checking %s configuration" "qemu-ga"; fail | |
48 | nls 'Configuration test failed. See details with %s "checkconfig"' $0 | |
49 | exit $RETVAL | |
50 | fi | |
51 | fi | |
52 | } | |
53 | ||
54 | start() { | |
55 | # Check if the service is already running? | |
56 | if [ -f /var/lock/subsys/qemu-ga ]; then | |
57 | msg_already_running "qemu-ga" | |
58 | return | |
59 | fi | |
60 | ||
61 | checkconfig | |
62 | msg_starting "qemu-ga" | |
63 | daemon /usr/bin/qemu-ga -d -l /var/log/qemu-ga | |
64 | RETVAL=$? | |
65 | [ $RETVAL -eq 0 ] && touch /var/lock/subsys/qemu-ga | |
66 | } | |
67 | ||
68 | stop() { | |
69 | if [ ! -f /var/lock/subsys/qemu-ga ]; then | |
70 | msg_not_running "qemu-ga" | |
71 | return | |
72 | fi | |
73 | ||
74 | # Stop daemons. | |
75 | msg_stopping "qemu-ga" | |
76 | killproc --pidfile $pidfile qemu-ga -TERM | |
77 | rm -f /var/lock/subsys/qemu-ga | |
78 | } | |
79 | ||
80 | condrestart() { | |
81 | if [ ! -f /var/lock/subsys/qemu-ga ]; then | |
82 | msg_not_running "qemu-ga" | |
83 | RETVAL=$1 | |
84 | return | |
85 | fi | |
86 | ||
87 | checkconfig | |
88 | stop | |
89 | start | |
90 | } | |
91 | ||
92 | RETVAL=0 | |
93 | # See how we were called. | |
94 | case "$1" in | |
95 | start) | |
96 | start | |
97 | ;; | |
98 | stop) | |
99 | stop | |
100 | ;; | |
101 | restart) | |
102 | checkconfig | |
103 | stop | |
104 | start | |
105 | ;; | |
106 | try-restart) | |
107 | condrestart 0 | |
108 | ;; | |
109 | force-reload) | |
110 | condrestart 7 | |
111 | ;; | |
112 | checkconfig|configtest) | |
113 | checkconfig 1 | |
114 | ;; | |
115 | status) | |
116 | status --pidfile $pidfile qemu-ga | |
117 | RETVAL=$? | |
118 | ;; | |
119 | *) | |
120 | msg_usage "$0 {start|stop|restart|try-restart|force-reload|checkconfig|status}" | |
121 | exit 3 | |
122 | esac | |
123 | ||
124 | exit $RETVAL |