VirtualBox

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

Last change on this file since 41365 was 41365, checked in by vboxsync, 13 years ago

Linux/Solaris installers: Added authentication method + PW hash to webservice configuration.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 9.4 KB
Line 
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
28PATH=$PATH:/bin:/sbin:/usr/sbin
29DEBIAN=%DEBIAN%
30NOLSB=%NOLSB%
31
32[ -f /lib/lsb/init-functions ] || NOLSB=yes
33[ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg
34
35if [ -n "$INSTALL_DIR" ]; then
36 binary="$INSTALL_DIR/vboxwebsrv"
37 vboxmanage="$INSTALL_DIR/VBoxManage"
38else
39 binary="/usr/lib/%PACKAGE%/vboxwebsrv"
40 vboxmanage="/usr/lib/%PACKAGE%/VBoxManage"
41fi
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
49system=unknown
50if [ -f /etc/redhat-release ]; then
51 system=redhat
52 PIDFILE="/var/lock/subsys/vboxweb-service"
53elif [ -f /etc/SuSE-release ]; then
54 system=suse
55 PIDFILE="/var/lock/subsys/vboxweb-service"
56elif [ -f /etc/debian_version ]; then
57 system=debian
58 PIDFILE="/var/run/vboxweb-service"
59elif [ -f /etc/gentoo-release ]; then
60 system=gentoo
61 PIDFILE="/var/run/vboxweb-service"
62elif [ -f /etc/arch-release ]; then
63 system=arch
64 PIDFILE="/var/run/vboxweb-service"
65elif [ -f /etc/slackware-version ]; then
66 system=slackware
67 PIDFILE="/var/run/vboxweb-service"
68elif [ -f /etc/lfs-release ]; then
69 system=lfs
70 PIDFILE="/var/run/vboxweb-service.pid"
71else
72 system=other
73 if [ -d /var/run -a -w /var/run ]; then
74 PIDFILE="/var/run/vboxweb-service"
75 fi
76fi
77
78if [ -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 }
90fi
91
92if [ "$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
112fi
113
114if [ "$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
134fi
135
136if [ "$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
158fi
159
160if [ "$system" = "gentoo" ]; then
161 . /sbin/functions.sh
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
186fi
187
188if [ "$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
212fi
213
214if [ "$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 }
235fi
236
237if [ "$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 }
258fi
259
260if [ "$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
272fi
273
274vboxdrvrunning() {
275 lsmod | grep -q "vboxdrv[^_-]"
276}
277
278check_single_user() {
279 if [ -n "$2" ]; then
280 fail_msg "VBOXWEB_USER must not contain multiple users!"
281 exit 1
282 fi
283}
284
285start() {
286 if ! test -f $PIDFILE; then
287 [ -z "$VBOXWEB_USER" ] && exit 0
288 begin_msg "Starting VirtualBox web service";
289 check_single_user $VBOXWEB_USER
290 vboxdrvrunning || {
291 fail_msg "VirtualBox kernel module not loaded!"
292 exit 0
293 }
294 PARAMS="--background"
295 [ -n "$VBOXWEB_HOST" ] && PARAMS="$PARAMS -H $VBOXWEB_HOST"
296 [ -n "$VBOXWEB_PORT" ] && PARAMS="$PARAMS -p $VBOXWEB_PORT"
297 [ -n "$VBOXWEB_SSL_KEYFILE" ] && PARAMS="$PARAMS -s -K $VBOXWEB_SSL_KEYFILE"
298 [ -n "$VBOXWEB_SSL_PASSWORDFILE" ] && PARAMS="$PARAMS -a $VBOXWEB_SSL_PASSWORDFILE"
299 [ -n "$VBOXWEB_SSL_CACERT" ] && PARAMS="$PARAMS -c $VBOXWEB_SSL_CACERT"
300 [ -n "$VBOXWEB_SSL_CAPATH" ] && PARAMS="$PARAMS -C $VBOXWEB_SSL_CAPATH"
301 [ -n "$VBOXWEB_SSL_DHFILE" ] && PARAMS="$PARAMS -D $VBOXWEB_SSL_DHFILE"
302 [ -n "$VBOXWEB_SSL_RANDFILE" ] && PARAMS="$PARAMS -r $VBOXWEB_SSL_RANDFILE"
303 [ -n "$VBOXWEB_TIMEOUT" ] && PARAMS="$PARAMS -t $VBOXWEB_TIMEOUT"
304 [ -n "$VBOXWEB_CHECK_INTERVAL" ] && PARAMS="$PARAMS -i $VBOXWEB_CHECK_INTERVAL"
305 [ -n "$VBOXWEB_THREADS" ] && PARAMS="$PARAMS -T $VBOXWEB_THREADS"
306 [ -n "$VBOXWEB_KEEPALIVE" ] && PARAMS="$PARAMS -k $VBOXWEB_KEEPALIVE"
307 [ -n "$VBOXWEB_AUTHENTICATION" ] && PARAMS="$PARAMS -A $VBOXWEB_AUTHENTICATION"
308 [ -n "$VBOXWEB_LOGFILE" ] && PARAMS="$PARAMS -F $VBOXWEB_LOGFILE"
309 [ -n "$VBOXWEB_ROTATE" ] && PARAMS="$PARAMS -R $VBOXWEB_ROTATE"
310 [ -n "$VBOXWEB_LOGSIZE" ] && PARAMS="$PARAMS -S $VBOXWEB_LOGSIZE"
311 [ -n "$VBOXWEB_LOGINTERVAL" ] && PARAMS="$PARAMS -I $VBOXWEB_LOGINTERVAL"
312 # set authentication method + password hash
313 if [ -n "$VBOXWEB_AUTH_LIBRARY" ]; then
314 vboxmanage setproperty websrvauthlibrary $VBOXWEB_AUTH_LIBRARY
315 if [ $? -ne 0 ]; then
316 fail_msg "Error setting webservice authentication library to $VBOXWEB_AUTH_LIBRARY"
317 fi
318 fi
319 if [ -n "$VBOXWEB_AUTH_PWHASH" ]; then
320 vboxmanage setextradata global VBoxAuthSimple/users/$VBOXWEB_USER $VBOXWEB_AUTH_PWHASH
321 if [ $? -ne 0 ]; then
322 fail_msg "Error setting webservice password hash"
323 fi
324 fi
325 # prevent inheriting this setting to VBoxSVC
326 unset VBOX_RELEASE_LOG_DEST
327 start_daemon $VBOXWEB_USER $binary $PARAMS > /dev/null 2>&1
328 # ugly: wait until the final process has forked
329 sleep .1
330 PID=`pidof $binary 2>/dev/null`
331 if [ -n "$PID" ]; then
332 echo "$PID" > $PIDFILE
333 RETVAL=0
334 succ_msg
335 else
336 RETVAL=1
337 fail_msg
338 fi
339 fi
340 return $RETVAL
341}
342
343stop() {
344 if test -f $PIDFILE; then
345 begin_msg "Stopping VirtualBox web service";
346 killproc $binary
347 RETVAL=$?
348 if ! pidof $binary > /dev/null 2>&1; then
349 rm -f $PIDFILE
350 succ_msg
351 else
352 fail_msg
353 fi
354 fi
355 return $RETVAL
356}
357
358restart() {
359 stop && start
360}
361
362status() {
363 echo -n "Checking for VBox Web Service"
364 if [ -f $PIDFILE ]; then
365 echo " ...running"
366 else
367 echo " ...not running"
368 fi
369}
370
371case "$1" in
372start)
373 start
374 ;;
375stop)
376 stop
377 ;;
378restart)
379 restart
380 ;;
381force-reload)
382 restart
383 ;;
384status)
385 status
386 ;;
387setup)
388 ;;
389cleanup)
390 ;;
391*)
392 echo "Usage: $0 {start|stop|restart|status}"
393 exit 1
394esac
395
396exit $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