VirtualBox

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

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

Installers/linux: silence some unwanted output.

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 5.9 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: 345 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
29SCRIPTNAME=vboxweb-service
30
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
47PIDFILE="/var/run/${SCRIPTNAME}"
48
49# Preamble for Gentoo
50if [ "`which $0`" = "/sbin/rc" ]; then
51 shift
52fi
53
54begin_msg()
55{
56 test -n "${2}" && echo "${SCRIPTNAME}: ${1}."
57 logger "${SCRIPTNAME}: ${1}."
58}
59
60succ_msg()
61{
62 logger "${SCRIPTNAME}: done."
63}
64
65fail_msg()
66{
67 echo "${SCRIPTNAME}: failed: ${1}." >&2
68 logger "${SCRIPTNAME}: failed: ${1}."
69}
70
71start_daemon() {
72 usr="$1"
73 shift
74 su - $usr -c "$*"
75}
76
77killproc() {
78 killall $1
79 rm -f $PIDFILE
80}
81
82if which start-stop-daemon >/dev/null 2>&1; then
83 start_daemon() {
84 usr="$1"
85 shift
86 bin="$1"
87 shift
88 start-stop-daemon --background --chuid $usr --start --exec $bin -- $@
89 }
90
91 killproc() {
92 start-stop-daemon --stop --exec $@
93 }
94fi
95
96vboxdrvrunning() {
97 lsmod | grep -q "vboxdrv[^_-]"
98}
99
100check_single_user() {
101 if [ -n "$2" ]; then
102 fail_msg "VBOXWEB_USER must not contain multiple users!"
103 exit 1
104 fi
105}
106
107start() {
108 if ! test -f $PIDFILE; then
109 [ -z "$VBOXWEB_USER" ] && exit 0
110 begin_msg "Starting VirtualBox web service" console;
111 check_single_user $VBOXWEB_USER
112 vboxdrvrunning || {
113 fail_msg "VirtualBox kernel module not loaded!"
114 exit 0
115 }
116 PARAMS="--background"
117 [ -n "$VBOXWEB_HOST" ] && PARAMS="$PARAMS -H $VBOXWEB_HOST"
118 [ -n "$VBOXWEB_PORT" ] && PARAMS="$PARAMS -p $VBOXWEB_PORT"
119 [ -n "$VBOXWEB_SSL_KEYFILE" ] && PARAMS="$PARAMS -s -K $VBOXWEB_SSL_KEYFILE"
120 [ -n "$VBOXWEB_SSL_PASSWORDFILE" ] && PARAMS="$PARAMS -a $VBOXWEB_SSL_PASSWORDFILE"
121 [ -n "$VBOXWEB_SSL_CACERT" ] && PARAMS="$PARAMS -c $VBOXWEB_SSL_CACERT"
122 [ -n "$VBOXWEB_SSL_CAPATH" ] && PARAMS="$PARAMS -C $VBOXWEB_SSL_CAPATH"
123 [ -n "$VBOXWEB_SSL_DHFILE" ] && PARAMS="$PARAMS -D $VBOXWEB_SSL_DHFILE"
124 [ -n "$VBOXWEB_SSL_RANDFILE" ] && PARAMS="$PARAMS -r $VBOXWEB_SSL_RANDFILE"
125 [ -n "$VBOXWEB_TIMEOUT" ] && PARAMS="$PARAMS -t $VBOXWEB_TIMEOUT"
126 [ -n "$VBOXWEB_CHECK_INTERVAL" ] && PARAMS="$PARAMS -i $VBOXWEB_CHECK_INTERVAL"
127 [ -n "$VBOXWEB_THREADS" ] && PARAMS="$PARAMS -T $VBOXWEB_THREADS"
128 [ -n "$VBOXWEB_KEEPALIVE" ] && PARAMS="$PARAMS -k $VBOXWEB_KEEPALIVE"
129 [ -n "$VBOXWEB_AUTHENTICATION" ] && PARAMS="$PARAMS -A $VBOXWEB_AUTHENTICATION"
130 [ -n "$VBOXWEB_LOGFILE" ] && PARAMS="$PARAMS -F $VBOXWEB_LOGFILE"
131 [ -n "$VBOXWEB_ROTATE" ] && PARAMS="$PARAMS -R $VBOXWEB_ROTATE"
132 [ -n "$VBOXWEB_LOGSIZE" ] && PARAMS="$PARAMS -S $VBOXWEB_LOGSIZE"
133 [ -n "$VBOXWEB_LOGINTERVAL" ] && PARAMS="$PARAMS -I $VBOXWEB_LOGINTERVAL"
134 # set authentication method + password hash
135 if [ -n "$VBOXWEB_AUTH_LIBRARY" ]; then
136 su - "$VBOXWEB_USER" -c "$vboxmanage setproperty websrvauthlibrary \"$VBOXWEB_AUTH_LIBRARY\""
137 if [ $? -ne 0 ]; then
138 fail_msg "Error $? setting webservice authentication library to $VBOXWEB_AUTH_LIBRARY"
139 fi
140 fi
141 if [ -n "$VBOXWEB_AUTH_PWHASH" ]; then
142 su - "$VBOXWEB_USER" -c "$vboxmanage setextradata global \"VBoxAuthSimple/users/$VBOXWEB_USER\" \"$VBOXWEB_AUTH_PWHASH\""
143 if [ $? -ne 0 ]; then
144 fail_msg "Error $? setting webservice password hash"
145 fi
146 fi
147 # prevent inheriting this setting to VBoxSVC
148 unset VBOX_RELEASE_LOG_DEST
149 start_daemon $VBOXWEB_USER $binary $PARAMS > /dev/null 2>&1
150 # ugly: wait until the final process has forked
151 sleep .1
152 PID=`pidof $binary 2>/dev/null`
153 if [ -n "$PID" ]; then
154 echo "$PID" > $PIDFILE
155 RETVAL=0
156 succ_msg
157 else
158 RETVAL=1
159 fail_msg
160 fi
161 fi
162 return $RETVAL
163}
164
165stop() {
166 if test -f $PIDFILE; then
167 begin_msg "Stopping VirtualBox web service" console;
168 killproc $binary
169 RETVAL=$?
170 if ! pidof $binary > /dev/null 2>&1; then
171 rm -f $PIDFILE
172 succ_msg
173 else
174 fail_msg
175 fi
176 fi
177 return $RETVAL
178}
179
180restart() {
181 stop && start
182}
183
184status() {
185 echo -n "Checking for VBox Web Service"
186 if [ -f $PIDFILE ]; then
187 echo " ...running"
188 else
189 echo " ...not running"
190 fi
191}
192
193case "$1" in
194start)
195 start
196 ;;
197stop)
198 stop
199 ;;
200restart)
201 restart
202 ;;
203force-reload)
204 restart
205 ;;
206status)
207 status
208 ;;
209setup)
210 ;;
211cleanup)
212 ;;
213*)
214 echo "Usage: $0 {start|stop|restart|status}"
215 exit 1
216esac
217
218exit $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