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