1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # VirtualBox balloon control daemon init script.
|
---|
4 | #
|
---|
5 | # Copyright (C) 2006-2012 Oracle Corporation
|
---|
6 | #
|
---|
7 | # This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
8 | # available from http://www.virtualbox.org. This file is free software;
|
---|
9 | # you can redistribute it and/or modify it under the terms of the GNU
|
---|
10 | # General Public License (GPL) as published by the Free Software
|
---|
11 | # Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
12 | # VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
13 | # hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
14 | #
|
---|
15 |
|
---|
16 | # chkconfig: 35 35 65
|
---|
17 | # description: VirtualBox balloon control daemon
|
---|
18 | #
|
---|
19 | ### BEGIN INIT INFO
|
---|
20 | # Provides: vboxballoonctrl-service
|
---|
21 | # Required-Start: vboxdrv
|
---|
22 | # Required-Stop: vboxdrv
|
---|
23 | # Default-Start: 2 3 4 5
|
---|
24 | # Default-Stop: 0 1 6
|
---|
25 | # Description: VirtualBox balloon control daemon
|
---|
26 | ### END INIT INFO
|
---|
27 |
|
---|
28 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
29 |
|
---|
30 | [ -f /lib/lsb/init-functions -a -f /etc/debian_release ] || NOLSB=yes
|
---|
31 | [ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg
|
---|
32 |
|
---|
33 | if [ -n "$INSTALL_DIR" ]; then
|
---|
34 | binary="$INSTALL_DIR/VBoxBalloonCtrl"
|
---|
35 | else
|
---|
36 | binary="/usr/lib/virtualbox/VBoxBalloonCtrl"
|
---|
37 | fi
|
---|
38 |
|
---|
39 | # silently exit if the package was uninstalled but not purged,
|
---|
40 | # applies to Debian packages only (but shouldn't hurt elsewhere)
|
---|
41 | [ ! -f /etc/debian_release -o -x $binary ] || exit 0
|
---|
42 |
|
---|
43 | [ -r /etc/default/virtualbox ] && . /etc/default/virtualbox
|
---|
44 |
|
---|
45 | system=unknown
|
---|
46 | if [ -f /etc/redhat-release ]; then
|
---|
47 | system=redhat
|
---|
48 | PIDFILE="/var/lock/subsys/vboxballoonctrl-service"
|
---|
49 | elif [ -f /etc/SuSE-release ]; then
|
---|
50 | system=suse
|
---|
51 | PIDFILE="/var/lock/subsys/vboxballoonctrl-service"
|
---|
52 | elif [ -f /etc/debian_version ]; then
|
---|
53 | system=debian
|
---|
54 | PIDFILE="/var/run/vboxballoonctrl-service"
|
---|
55 | elif [ -f /etc/gentoo-release ]; then
|
---|
56 | system=gentoo
|
---|
57 | PIDFILE="/var/run/vboxballoonctrl-service"
|
---|
58 | elif [ -f /etc/arch-release ]; then
|
---|
59 | system=arch
|
---|
60 | PIDFILE="/var/run/vboxballoonctrl-service"
|
---|
61 | elif [ -f /etc/slackware-version ]; then
|
---|
62 | system=slackware
|
---|
63 | PIDFILE="/var/run/vboxballoonctrl-service"
|
---|
64 | elif [ -f /etc/lfs-release ]; then
|
---|
65 | system=lfs
|
---|
66 | PIDFILE="/var/run/vboxballoonctrl-service.pid"
|
---|
67 | else
|
---|
68 | system=other
|
---|
69 | if [ -d /var/run -a -w /var/run ]; then
|
---|
70 | PIDFILE="/var/run/vboxballoonctrl-service"
|
---|
71 | fi
|
---|
72 | fi
|
---|
73 |
|
---|
74 | if [ -z "$NOLSB" ]; then
|
---|
75 | . /lib/lsb/init-functions
|
---|
76 | fail_msg() {
|
---|
77 | echo ""
|
---|
78 | log_failure_msg "$1"
|
---|
79 | }
|
---|
80 | succ_msg() {
|
---|
81 | log_success_msg " done."
|
---|
82 | }
|
---|
83 | begin_msg() {
|
---|
84 | log_daemon_msg "$@"
|
---|
85 | }
|
---|
86 | fi
|
---|
87 |
|
---|
88 | if [ "$system" = "redhat" ]; then
|
---|
89 | . /etc/init.d/functions
|
---|
90 | if [ -n "$NOLSB" ]; then
|
---|
91 | start_daemon() {
|
---|
92 | usr="$1"
|
---|
93 | shift
|
---|
94 | daemon --user $usr $@
|
---|
95 | }
|
---|
96 | fail_msg() {
|
---|
97 | echo_failure
|
---|
98 | echo
|
---|
99 | }
|
---|
100 | succ_msg() {
|
---|
101 | echo_success
|
---|
102 | echo
|
---|
103 | }
|
---|
104 | begin_msg() {
|
---|
105 | echo -n "$1"
|
---|
106 | }
|
---|
107 | fi
|
---|
108 | fi
|
---|
109 |
|
---|
110 | if [ "$system" = "suse" ]; then
|
---|
111 | . /etc/rc.status
|
---|
112 | start_daemon() {
|
---|
113 | usr="$1"
|
---|
114 | shift
|
---|
115 | su - $usr -c "$*"
|
---|
116 | }
|
---|
117 | if [ -n "$NOLSB" ]; then
|
---|
118 | fail_msg() {
|
---|
119 | rc_failed 1
|
---|
120 | rc_status -v
|
---|
121 | }
|
---|
122 | succ_msg() {
|
---|
123 | rc_reset
|
---|
124 | rc_status -v
|
---|
125 | }
|
---|
126 | begin_msg() {
|
---|
127 | echo -n "$1"
|
---|
128 | }
|
---|
129 | fi
|
---|
130 | fi
|
---|
131 |
|
---|
132 | if [ "$system" = "debian" ]; then
|
---|
133 | start_daemon() {
|
---|
134 | usr="$1"
|
---|
135 | shift
|
---|
136 | bin="$1"
|
---|
137 | shift
|
---|
138 | start-stop-daemon --background --chuid $usr --start --exec $bin -- $@
|
---|
139 | }
|
---|
140 | killproc() {
|
---|
141 | start-stop-daemon --stop --exec $@
|
---|
142 | }
|
---|
143 | if [ -n "$NOLSB" ]; then
|
---|
144 | fail_msg() {
|
---|
145 | echo " ...fail!"
|
---|
146 | }
|
---|
147 | succ_msg() {
|
---|
148 | echo " ...done."
|
---|
149 | }
|
---|
150 | begin_msg() {
|
---|
151 | echo -n "$1"
|
---|
152 | }
|
---|
153 | fi
|
---|
154 | fi
|
---|
155 |
|
---|
156 | if [ "$system" = "gentoo" ]; then
|
---|
157 | if [ -f /sbin/functions.sh ]; then
|
---|
158 | . /sbin/functions.sh
|
---|
159 | elif [ -f /etc/init.d/functions.sh ]; then
|
---|
160 | . /etc/init.d/functions.sh
|
---|
161 | fi
|
---|
162 | start_daemon() {
|
---|
163 | usr="$1"
|
---|
164 | shift
|
---|
165 | bin="$1"
|
---|
166 | shift
|
---|
167 | start-stop-daemon --background --chuid $usr --start --exec $bin -- $@
|
---|
168 | }
|
---|
169 | killproc() {
|
---|
170 | start-stop-daemon --stop --exec $@
|
---|
171 | }
|
---|
172 | if [ -n "$NOLSB" ]; then
|
---|
173 | fail_msg() {
|
---|
174 | echo " ...fail!"
|
---|
175 | }
|
---|
176 | succ_msg() {
|
---|
177 | echo " ...done."
|
---|
178 | }
|
---|
179 | begin_msg() {
|
---|
180 | echo -n "$1"
|
---|
181 | }
|
---|
182 | if [ "`which $0`" = "/sbin/rc" ]; then
|
---|
183 | shift
|
---|
184 | fi
|
---|
185 | fi
|
---|
186 | fi
|
---|
187 |
|
---|
188 | if [ "$system" = "arch" ]; then
|
---|
189 | USECOLOR=yes
|
---|
190 | . /etc/rc.d/functions
|
---|
191 | start_daemon() {
|
---|
192 | usr="$1"
|
---|
193 | shift
|
---|
194 | su - $usr -c "$*"
|
---|
195 | test $? -eq 0 && add_daemon rc.`basename $2`
|
---|
196 | }
|
---|
197 | killproc() {
|
---|
198 | killall $@
|
---|
199 | rm_daemon `basename $@`
|
---|
200 | }
|
---|
201 | if [ -n "$NOLSB" ]; then
|
---|
202 | fail_msg() {
|
---|
203 | stat_fail
|
---|
204 | }
|
---|
205 | succ_msg() {
|
---|
206 | stat_done
|
---|
207 | }
|
---|
208 | begin_msg() {
|
---|
209 | stat_busy "$1"
|
---|
210 | }
|
---|
211 | fi
|
---|
212 | fi
|
---|
213 |
|
---|
214 | if [ "$system" = "slackware" ]; then
|
---|
215 | killproc() {
|
---|
216 | killall $1
|
---|
217 | rm -f $PIDFILE
|
---|
218 | }
|
---|
219 | if [ -n "$NOLSB" ]; then
|
---|
220 | fail_msg() {
|
---|
221 | echo " ...fail!"
|
---|
222 | }
|
---|
223 | succ_msg() {
|
---|
224 | echo " ...done."
|
---|
225 | }
|
---|
226 | begin_msg() {
|
---|
227 | echo -n "$1"
|
---|
228 | }
|
---|
229 | fi
|
---|
230 | start_daemon() {
|
---|
231 | usr="$1"
|
---|
232 | shift
|
---|
233 | su - $usr -c "$*"
|
---|
234 | }
|
---|
235 | fi
|
---|
236 |
|
---|
237 | if [ "$system" = "lfs" ]; then
|
---|
238 | . /etc/rc.d/init.d/functions
|
---|
239 | if [ -n "$NOLSB" ]; then
|
---|
240 | fail_msg() {
|
---|
241 | echo_failure
|
---|
242 | }
|
---|
243 | succ_msg() {
|
---|
244 | echo_ok
|
---|
245 | }
|
---|
246 | begin_msg() {
|
---|
247 | echo $1
|
---|
248 | }
|
---|
249 | fi
|
---|
250 | start_daemon() {
|
---|
251 | usr="$1"
|
---|
252 | shift
|
---|
253 | su - $usr -c "$*"
|
---|
254 | }
|
---|
255 | status() {
|
---|
256 | statusproc $1
|
---|
257 | }
|
---|
258 | fi
|
---|
259 |
|
---|
260 | if [ "$system" = "other" ]; then
|
---|
261 | if [ -n "$NOLSB" ]; then
|
---|
262 | fail_msg() {
|
---|
263 | echo " ...fail!"
|
---|
264 | }
|
---|
265 | succ_msg() {
|
---|
266 | echo " ...done."
|
---|
267 | }
|
---|
268 | begin_msg() {
|
---|
269 | echo -n "$1"
|
---|
270 | }
|
---|
271 | fi
|
---|
272 | fi
|
---|
273 |
|
---|
274 | vboxdrvrunning() {
|
---|
275 | lsmod | grep -q "vboxdrv[^_-]"
|
---|
276 | }
|
---|
277 |
|
---|
278 | check_single_user() {
|
---|
279 | if [ -n "$2" ]; then
|
---|
280 | fail_msg "VBOXBALLOONCTRL_USER must not contain multiple users!"
|
---|
281 | exit 1
|
---|
282 | fi
|
---|
283 | }
|
---|
284 |
|
---|
285 | start() {
|
---|
286 | if ! test -f $PIDFILE; then
|
---|
287 | [ -z "$VBOXBALLOONCTRL_USER" ] && exit 0
|
---|
288 | begin_msg "Starting VirtualBox balloon control service";
|
---|
289 | check_single_user $VBOXBALLOONCTRL_USER
|
---|
290 | vboxdrvrunning || {
|
---|
291 | fail_msg "VirtualBox kernel module not loaded!"
|
---|
292 | exit 0
|
---|
293 | }
|
---|
294 | PARAMS="--background"
|
---|
295 | [ -n "$VBOXBALLOONCTRL_INTERVAL" ] && PARAMS="$PARAMS --balloon-interval $VBOXBALLOONCTRL_INTERVAL"
|
---|
296 | [ -n "$VBOXBALLOONCTRL_INCREMENT" ] && PARAMS="$PARAMS --balloon-inc $VBOXBALLOONCTRL_INCREMENT"
|
---|
297 | [ -n "$VBOXBALLOONCTRL_DECREMENT" ] && PARAMS="$PARAMS --balloon-dec $VBOXBALLOONCTRL_DECREMENT"
|
---|
298 | [ -n "$VBOXBALLOONCTRL_LOWERLIMIT" ] && PARAMS="$PARAMS --balloon-lower-limit $VBOXBALLOONCTRL_LOWERLIMIT"
|
---|
299 | [ -n "$VBOXBALLOONCTRL_ROTATE" ] && PARAMS="$PARAMS -R $VBOXBALLOONCTRL_ROTATE"
|
---|
300 | [ -n "$VBOXBALLOONCTRL_LOGSIZE" ] && PARAMS="$PARAMS -S $VBOXBALLOONCTRL_LOGSIZE"
|
---|
301 | [ -n "$VBOXBALLOONCTRL_LOGINTERVAL" ] && PARAMS="$PARAMS -I $VBOXBALLOONCTRL_LOGINTERVAL"
|
---|
302 | # prevent inheriting this setting to VBoxSVC
|
---|
303 | unset VBOX_RELEASE_LOG_DEST
|
---|
304 | start_daemon $VBOXBALLOONCTRL_USER $binary $PARAMS > /dev/null 2>&1
|
---|
305 | # ugly: wait until the final process has forked
|
---|
306 | sleep .1
|
---|
307 | PID=`pidof $binary 2>/dev/null`
|
---|
308 | if [ -n "$PID" ]; then
|
---|
309 | echo "$PID" > $PIDFILE
|
---|
310 | RETVAL=0
|
---|
311 | succ_msg
|
---|
312 | else
|
---|
313 | RETVAL=1
|
---|
314 | fail_msg
|
---|
315 | fi
|
---|
316 | fi
|
---|
317 | return $RETVAL
|
---|
318 | }
|
---|
319 |
|
---|
320 | stop() {
|
---|
321 | if test -f $PIDFILE; then
|
---|
322 | begin_msg "Stopping VirtualBox balloon control service";
|
---|
323 | killproc $binary
|
---|
324 | RETVAL=$?
|
---|
325 | if ! pidof $binary > /dev/null 2>&1; then
|
---|
326 | rm -f $PIDFILE
|
---|
327 | succ_msg
|
---|
328 | else
|
---|
329 | fail_msg
|
---|
330 | fi
|
---|
331 | fi
|
---|
332 | return $RETVAL
|
---|
333 | }
|
---|
334 |
|
---|
335 | restart() {
|
---|
336 | stop && start
|
---|
337 | }
|
---|
338 |
|
---|
339 | status() {
|
---|
340 | echo -n "Checking for VBox balloon control service"
|
---|
341 | if [ -f $PIDFILE ]; then
|
---|
342 | echo " ...running"
|
---|
343 | else
|
---|
344 | echo " ...not running"
|
---|
345 | fi
|
---|
346 | }
|
---|
347 |
|
---|
348 | case "$1" in
|
---|
349 | start)
|
---|
350 | start
|
---|
351 | ;;
|
---|
352 | stop)
|
---|
353 | stop
|
---|
354 | ;;
|
---|
355 | restart)
|
---|
356 | restart
|
---|
357 | ;;
|
---|
358 | force-reload)
|
---|
359 | restart
|
---|
360 | ;;
|
---|
361 | status)
|
---|
362 | status
|
---|
363 | ;;
|
---|
364 | setup)
|
---|
365 | ;;
|
---|
366 | cleanup)
|
---|
367 | ;;
|
---|
368 | *)
|
---|
369 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
370 | exit 1
|
---|
371 | esac
|
---|
372 |
|
---|
373 | exit $RETVAL
|
---|