1 | #!/bin/sh
|
---|
2 | #
|
---|
3 | # Linux Additions Guest Additions service daemon init script.
|
---|
4 | #
|
---|
5 | # Copyright (C) 2006-2010 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 Additions service
|
---|
18 | #
|
---|
19 | ### BEGIN INIT INFO
|
---|
20 | # Provides: vboxweb-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 Additions Service
|
---|
26 | ### END INIT INFO
|
---|
27 |
|
---|
28 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
29 | DEBIAN=%DEBIAN%
|
---|
30 | NOLSB=%NOLSB%
|
---|
31 |
|
---|
32 | [ -f /lib/lsb/init-functions ] || NOLSB=yes
|
---|
33 | [ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg
|
---|
34 |
|
---|
35 | if [ -n "$INSTALL_DIR" ]; then
|
---|
36 | binary="$INSTALL_DIR/vboxwebsrv"
|
---|
37 | else
|
---|
38 | binary="/usr/lib/%PACKAGE%/vboxwebsrv"
|
---|
39 | fi
|
---|
40 |
|
---|
41 | # silently exit if the package was uninstalled but not purged,
|
---|
42 | # applies to Debian packages only
|
---|
43 | [ -z "$DEBIAN" -o -x $binary ] || exit 0
|
---|
44 |
|
---|
45 | [ -r /etc/default/%PACKAGE% ] && . /etc/default/%PACKAGE%
|
---|
46 |
|
---|
47 | system=unknown
|
---|
48 | if [ -f /etc/redhat-release ]; then
|
---|
49 | system=redhat
|
---|
50 | PIDFILE="/var/lock/subsys/vboxweb-service"
|
---|
51 | elif [ -f /etc/SuSE-release ]; then
|
---|
52 | system=suse
|
---|
53 | PIDFILE="/var/lock/subsys/vboxweb-service"
|
---|
54 | elif [ -f /etc/debian_version ]; then
|
---|
55 | system=debian
|
---|
56 | PIDFILE="/var/run/vboxweb-service"
|
---|
57 | elif [ -f /etc/gentoo-release ]; then
|
---|
58 | system=gentoo
|
---|
59 | PIDFILE="/var/run/vboxweb-service"
|
---|
60 | elif [ -f /etc/arch-release ]; then
|
---|
61 | system=arch
|
---|
62 | PIDFILE="/var/run/vboxweb-service"
|
---|
63 | elif [ -f /etc/slackware-version ]; then
|
---|
64 | system=slackware
|
---|
65 | PIDFILE="/var/run/vboxweb-service"
|
---|
66 | elif [ -f /etc/lfs-release ]; then
|
---|
67 | system=lfs
|
---|
68 | PIDFILE="/var/run/vboxweb-service.pid"
|
---|
69 | else
|
---|
70 | system=other
|
---|
71 | if [ -d /var/run -a -w /var/run ]; then
|
---|
72 | PIDFILE="/var/run/vboxweb-service"
|
---|
73 | fi
|
---|
74 | fi
|
---|
75 |
|
---|
76 | if [ -z "$NOLSB" ]; then
|
---|
77 | . /lib/lsb/init-functions
|
---|
78 | fail_msg() {
|
---|
79 | echo ""
|
---|
80 | log_failure_msg "$1"
|
---|
81 | }
|
---|
82 | succ_msg() {
|
---|
83 | log_success_msg " done."
|
---|
84 | }
|
---|
85 | begin_msg() {
|
---|
86 | log_daemon_msg "$@"
|
---|
87 | }
|
---|
88 | fi
|
---|
89 |
|
---|
90 | if [ "$system" = "redhat" ]; then
|
---|
91 | . /etc/init.d/functions
|
---|
92 | if [ -n "$NOLSB" ]; then
|
---|
93 | start_daemon() {
|
---|
94 | usr="$1"
|
---|
95 | shift
|
---|
96 | daemon --user $usr $@
|
---|
97 | }
|
---|
98 | fail_msg() {
|
---|
99 | echo_failure
|
---|
100 | echo
|
---|
101 | }
|
---|
102 | succ_msg() {
|
---|
103 | echo_success
|
---|
104 | echo
|
---|
105 | }
|
---|
106 | begin_msg() {
|
---|
107 | echo -n "$1"
|
---|
108 | }
|
---|
109 | fi
|
---|
110 | fi
|
---|
111 |
|
---|
112 | if [ "$system" = "suse" ]; then
|
---|
113 | . /etc/rc.status
|
---|
114 | start_daemon() {
|
---|
115 | usr="$1"
|
---|
116 | shift
|
---|
117 | su - $usr -c "$*"
|
---|
118 | }
|
---|
119 | if [ -n "$NOLSB" ]; then
|
---|
120 | fail_msg() {
|
---|
121 | rc_failed 1
|
---|
122 | rc_status -v
|
---|
123 | }
|
---|
124 | succ_msg() {
|
---|
125 | rc_reset
|
---|
126 | rc_status -v
|
---|
127 | }
|
---|
128 | begin_msg() {
|
---|
129 | echo -n "$1"
|
---|
130 | }
|
---|
131 | fi
|
---|
132 | fi
|
---|
133 |
|
---|
134 | if [ "$system" = "debian" ]; then
|
---|
135 | start_daemon() {
|
---|
136 | usr="$1"
|
---|
137 | shift
|
---|
138 | bin="$1"
|
---|
139 | shift
|
---|
140 | start-stop-daemon --background --chuid $usr --start --exec $bin -- $@
|
---|
141 | }
|
---|
142 | killproc() {
|
---|
143 | start-stop-daemon --stop --exec $@
|
---|
144 | }
|
---|
145 | if [ -n "$NOLSB" ]; then
|
---|
146 | fail_msg() {
|
---|
147 | echo " ...fail!"
|
---|
148 | }
|
---|
149 | succ_msg() {
|
---|
150 | echo " ...done."
|
---|
151 | }
|
---|
152 | begin_msg() {
|
---|
153 | echo -n "$1"
|
---|
154 | }
|
---|
155 | fi
|
---|
156 | fi
|
---|
157 |
|
---|
158 | if [ "$system" = "gentoo" ]; then
|
---|
159 | . /sbin/functions.sh
|
---|
160 | start_daemon() {
|
---|
161 | usr="$1"
|
---|
162 | shift
|
---|
163 | bin="$1"
|
---|
164 | shift
|
---|
165 | start-stop-daemon --background --chuid $usr --start --exec $bin -- $@
|
---|
166 | }
|
---|
167 | killproc() {
|
---|
168 | start-stop-daemon --stop --exec $@
|
---|
169 | }
|
---|
170 | if [ -n "$NOLSB" ]; then
|
---|
171 | fail_msg() {
|
---|
172 | echo " ...fail!"
|
---|
173 | }
|
---|
174 | succ_msg() {
|
---|
175 | echo " ...done."
|
---|
176 | }
|
---|
177 | begin_msg() {
|
---|
178 | echo -n "$1"
|
---|
179 | }
|
---|
180 | if [ "`which $0`" = "/sbin/rc" ]; then
|
---|
181 | shift
|
---|
182 | fi
|
---|
183 | fi
|
---|
184 | fi
|
---|
185 |
|
---|
186 | if [ "$system" = "arch" ]; then
|
---|
187 | USECOLOR=yes
|
---|
188 | . /etc/rc.d/functions
|
---|
189 | start_daemon() {
|
---|
190 | usr="$1"
|
---|
191 | shift
|
---|
192 | su - $usr -c "$*"
|
---|
193 | test $? -eq 0 && add_daemon rc.`basename $2`
|
---|
194 | }
|
---|
195 | killproc() {
|
---|
196 | killall $@
|
---|
197 | rm_daemon `basename $@`
|
---|
198 | }
|
---|
199 | if [ -n "$NOLSB" ]; then
|
---|
200 | fail_msg() {
|
---|
201 | stat_fail
|
---|
202 | }
|
---|
203 | succ_msg() {
|
---|
204 | stat_done
|
---|
205 | }
|
---|
206 | begin_msg() {
|
---|
207 | stat_busy "$1"
|
---|
208 | }
|
---|
209 | fi
|
---|
210 | fi
|
---|
211 |
|
---|
212 | if [ "$system" = "slackware" ]; then
|
---|
213 | killproc() {
|
---|
214 | killall $1
|
---|
215 | rm -f $PIDFILE
|
---|
216 | }
|
---|
217 | if [ -n "$NOLSB" ]; then
|
---|
218 | fail_msg() {
|
---|
219 | echo " ...fail!"
|
---|
220 | }
|
---|
221 | succ_msg() {
|
---|
222 | echo " ...done."
|
---|
223 | }
|
---|
224 | begin_msg() {
|
---|
225 | echo -n "$1"
|
---|
226 | }
|
---|
227 | fi
|
---|
228 | start_daemon() {
|
---|
229 | usr="$1"
|
---|
230 | shift
|
---|
231 | su - $usr -c "$*"
|
---|
232 | }
|
---|
233 | fi
|
---|
234 |
|
---|
235 | if [ "$system" = "lfs" ]; then
|
---|
236 | . /etc/rc.d/init.d/functions
|
---|
237 | if [ -n "$NOLSB" ]; then
|
---|
238 | fail_msg() {
|
---|
239 | echo_failure
|
---|
240 | }
|
---|
241 | succ_msg() {
|
---|
242 | echo_ok
|
---|
243 | }
|
---|
244 | begin_msg() {
|
---|
245 | echo $1
|
---|
246 | }
|
---|
247 | fi
|
---|
248 | start_daemon() {
|
---|
249 | usr="$1"
|
---|
250 | shift
|
---|
251 | su - $usr -c "$*"
|
---|
252 | }
|
---|
253 | status() {
|
---|
254 | statusproc $1
|
---|
255 | }
|
---|
256 | fi
|
---|
257 |
|
---|
258 | if [ "$system" = "other" ]; then
|
---|
259 | if [ -n "$NOLSB" ]; then
|
---|
260 | fail_msg() {
|
---|
261 | echo " ...fail!"
|
---|
262 | }
|
---|
263 | succ_msg() {
|
---|
264 | echo " ...done."
|
---|
265 | }
|
---|
266 | begin_msg() {
|
---|
267 | echo -n "$1"
|
---|
268 | }
|
---|
269 | fi
|
---|
270 | fi
|
---|
271 |
|
---|
272 | vboxdrvrunning() {
|
---|
273 | lsmod | grep -q "vboxdrv[^_-]"
|
---|
274 | }
|
---|
275 |
|
---|
276 | check_single_user() {
|
---|
277 | if [ -n "$2" ]; then
|
---|
278 | fail_msg "VBOXWEB_USER must not contain multiple users!"
|
---|
279 | exit 1
|
---|
280 | fi
|
---|
281 | }
|
---|
282 |
|
---|
283 | start() {
|
---|
284 | if ! test -f $PIDFILE; then
|
---|
285 | [ -z "$VBOXWEB_USER" ] && exit 0
|
---|
286 | begin_msg "Starting VirtualBox web service";
|
---|
287 | check_single_user $VBOXWEB_USER
|
---|
288 | vboxdrvrunning || {
|
---|
289 | fail_msg "VirtualBox kernel module not loaded!"
|
---|
290 | exit 0
|
---|
291 | }
|
---|
292 | PARAMS="--background"
|
---|
293 | [ -n "$VBOXWEB_HOST" ] && PARAMS="$PARAMS -H $VBOXWEB_HOST"
|
---|
294 | [ -n "$VBOXWEB_PORT" ] && PARAMS="$PARAMS -p $VBOXWEB_PORT"
|
---|
295 | [ -n "$VBOXWEB_TIMEOUT" ] && PARAMS="$PARAMS -t $VBOXWEB_TIMEOUT"
|
---|
296 | [ -n "$VBOXWEB_CHECK_INTERVAL" ] && PARAMS="$PARAMS -i $VBOXWEB_CHECK_INTERVAL"
|
---|
297 | [ -n "$VBOXWEB_THREADS" ] && PARAMS="$PARAMS -T $VBOXWEB_THREADS"
|
---|
298 | [ -n "$VBOXWEB_KEEPALIVE" ] && PARAMS="$PARAMS -k $VBOXWEB_KEEPALIVE"
|
---|
299 | [ -n "$VBOXWEB_LOGFILE" ] && PARAMS="$PARAMS -F $VBOXWEB_LOGFILE"
|
---|
300 | # prevent inheriting this setting to VBoxSVC
|
---|
301 | unset VBOX_RELEASE_LOG_DEST
|
---|
302 | start_daemon $VBOXWEB_USER $binary $PARAMS > /dev/null 2>&1
|
---|
303 | # ugly: wait until the final process has forked
|
---|
304 | sleep .1
|
---|
305 | PID=`pidof $binary 2>/dev/null`
|
---|
306 | if [ -n "$PID" ]; then
|
---|
307 | echo "$PID" > $PIDFILE
|
---|
308 | RETVAL=0
|
---|
309 | succ_msg
|
---|
310 | else
|
---|
311 | RETVAL=1
|
---|
312 | fail_msg
|
---|
313 | fi
|
---|
314 | fi
|
---|
315 | return $RETVAL
|
---|
316 | }
|
---|
317 |
|
---|
318 | stop() {
|
---|
319 | if test -f $PIDFILE; then
|
---|
320 | begin_msg "Stopping VirtualBox web service";
|
---|
321 | killproc $binary
|
---|
322 | RETVAL=$?
|
---|
323 | if ! pidof $binary > /dev/null 2>&1; then
|
---|
324 | rm -f $PIDFILE
|
---|
325 | succ_msg
|
---|
326 | else
|
---|
327 | fail_msg
|
---|
328 | fi
|
---|
329 | fi
|
---|
330 | return $RETVAL
|
---|
331 | }
|
---|
332 |
|
---|
333 | restart() {
|
---|
334 | stop && start
|
---|
335 | }
|
---|
336 |
|
---|
337 | status() {
|
---|
338 | echo -n "Checking for VBox Web Service"
|
---|
339 | if [ -f $PIDFILE ]; then
|
---|
340 | echo " ...running"
|
---|
341 | else
|
---|
342 | echo " ...not running"
|
---|
343 | fi
|
---|
344 | }
|
---|
345 |
|
---|
346 | case "$1" in
|
---|
347 | start)
|
---|
348 | start
|
---|
349 | ;;
|
---|
350 | stop)
|
---|
351 | stop
|
---|
352 | ;;
|
---|
353 | restart)
|
---|
354 | restart
|
---|
355 | ;;
|
---|
356 | status)
|
---|
357 | status
|
---|
358 | ;;
|
---|
359 | setup)
|
---|
360 | ;;
|
---|
361 | cleanup)
|
---|
362 | ;;
|
---|
363 | *)
|
---|
364 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
365 | exit 1
|
---|
366 | esac
|
---|
367 |
|
---|
368 | exit $RETVAL
|
---|