VirtualBox

source: vbox/trunk/src/VBox/Installer/linux/vboxweb-service.sh@ 56299

Last change on this file since 56299 was 56299, checked in by vboxsync, 9 years ago

Installer: Updated (C) year.

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

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette