VirtualBox

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

Last change on this file since 93115 was 93115, checked in by vboxsync, 2 years ago

scm --update-copyright-year

  • Property svn:eol-style set to LF
  • Property svn:keywords set to Author Date Id Revision
File size: 6.2 KB
Line 
1#!/bin/sh
2# $Id: vboxweb-service.sh 93115 2022-01-01 11:31:46Z vboxsync $
3## @file
4# VirtualBox web service API daemon init script.
5#
6
7#
8# Copyright (C) 2006-2022 Oracle Corporation
9#
10# This file is part of VirtualBox Open Source Edition (OSE), as
11# available from http://www.virtualbox.org. This file is free software;
12# you can redistribute it and/or modify it under the terms of the GNU
13# General Public License (GPL) as published by the Free Software
14# Foundation, in version 2 as it comes in the "COPYING" file of the
15# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
16# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
17#
18
19# chkconfig: 345 35 65
20# description: VirtualBox web service API
21#
22### BEGIN INIT INFO
23# Provides: vboxweb-service
24# Required-Start: vboxdrv
25# Required-Stop: vboxdrv
26# Default-Start: 2 3 4 5
27# Default-Stop: 0 1 6
28# Description: VirtualBox web service API
29# X-Required-Target-Start: network-online
30### END INIT INFO
31
32PATH=$PATH:/bin:/sbin:/usr/sbin
33SCRIPTNAME=vboxweb-service.sh
34
35[ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg
36
37if [ -n "$INSTALL_DIR" ]; then
38 binary="$INSTALL_DIR/vboxwebsrv"
39 vboxmanage="$INSTALL_DIR/VBoxManage"
40else
41 binary="/usr/lib/virtualbox/vboxwebsrv"
42 vboxmanage="/usr/lib/virtualbox/VBoxManage"
43fi
44
45# silently exit if the package was uninstalled but not purged,
46# applies to Debian packages only (but shouldn't hurt elsewhere)
47[ ! -f /etc/debian_release -o -x $binary ] || exit 0
48
49[ -r /etc/default/virtualbox ] && . /etc/default/virtualbox
50
51PIDFILE="/var/run/${SCRIPTNAME}"
52
53# Preamble for Gentoo
54if [ "`which $0`" = "/sbin/rc" ]; then
55 shift
56fi
57
58begin_msg()
59{
60 test -n "${2}" && echo "${SCRIPTNAME}: ${1}."
61 logger -t "${SCRIPTNAME}" "${1}."
62}
63
64succ_msg()
65{
66 logger -t "${SCRIPTNAME}" "${1}."
67}
68
69fail_msg()
70{
71 echo "${SCRIPTNAME}: failed: ${1}." >&2
72 logger -t "${SCRIPTNAME}" "failed: ${1}."
73}
74
75start_daemon() {
76 usr="$1"
77 shift
78 su - $usr -c "$*"
79}
80
81killproc() {
82 killall $1
83 rm -f $PIDFILE
84}
85
86if which start-stop-daemon >/dev/null 2>&1; then
87 start_daemon() {
88 usr="$1"
89 shift
90 bin="$1"
91 shift
92 start-stop-daemon --background --chuid $usr --start --exec $bin -- $@
93 }
94
95 killproc() {
96 start-stop-daemon --stop --exec $@
97 }
98fi
99
100vboxdrvrunning() {
101 lsmod | grep -q "vboxdrv[^_-]"
102}
103
104check_single_user() {
105 if [ -n "$2" ]; then
106 fail_msg "VBOXWEB_USER must not contain multiple users!"
107 exit 1
108 fi
109}
110
111start() {
112 if ! test -f $PIDFILE; then
113 [ -z "$VBOXWEB_USER" ] && exit 0
114 begin_msg "Starting VirtualBox web service" console;
115 check_single_user $VBOXWEB_USER
116 vboxdrvrunning || {
117 fail_msg "VirtualBox kernel module not loaded!"
118 exit 0
119 }
120 PARAMS="--background"
121 [ -n "$VBOXWEB_HOST" ] && PARAMS="$PARAMS -H $VBOXWEB_HOST"
122 [ -n "$VBOXWEB_PORT" ] && PARAMS="$PARAMS -p $VBOXWEB_PORT"
123 [ -n "$VBOXWEB_SSL_KEYFILE" ] && PARAMS="$PARAMS -s -K $VBOXWEB_SSL_KEYFILE"
124 [ -n "$VBOXWEB_SSL_PASSWORDFILE" ] && PARAMS="$PARAMS -a $VBOXWEB_SSL_PASSWORDFILE"
125 [ -n "$VBOXWEB_SSL_CACERT" ] && PARAMS="$PARAMS -c $VBOXWEB_SSL_CACERT"
126 [ -n "$VBOXWEB_SSL_CAPATH" ] && PARAMS="$PARAMS -C $VBOXWEB_SSL_CAPATH"
127 [ -n "$VBOXWEB_SSL_DHFILE" ] && PARAMS="$PARAMS -D $VBOXWEB_SSL_DHFILE"
128 [ -n "$VBOXWEB_SSL_RANDFILE" ] && PARAMS="$PARAMS -r $VBOXWEB_SSL_RANDFILE"
129 [ -n "$VBOXWEB_TIMEOUT" ] && PARAMS="$PARAMS -t $VBOXWEB_TIMEOUT"
130 [ -n "$VBOXWEB_CHECK_INTERVAL" ] && PARAMS="$PARAMS -i $VBOXWEB_CHECK_INTERVAL"
131 [ -n "$VBOXWEB_THREADS" ] && PARAMS="$PARAMS -T $VBOXWEB_THREADS"
132 [ -n "$VBOXWEB_KEEPALIVE" ] && PARAMS="$PARAMS -k $VBOXWEB_KEEPALIVE"
133 [ -n "$VBOXWEB_AUTHENTICATION" ] && PARAMS="$PARAMS -A $VBOXWEB_AUTHENTICATION"
134 [ -n "$VBOXWEB_LOGFILE" ] && PARAMS="$PARAMS -F $VBOXWEB_LOGFILE"
135 [ -n "$VBOXWEB_ROTATE" ] && PARAMS="$PARAMS -R $VBOXWEB_ROTATE"
136 [ -n "$VBOXWEB_LOGSIZE" ] && PARAMS="$PARAMS -S $VBOXWEB_LOGSIZE"
137 [ -n "$VBOXWEB_LOGINTERVAL" ] && PARAMS="$PARAMS -I $VBOXWEB_LOGINTERVAL"
138 # set authentication method + password hash
139 if [ -n "$VBOXWEB_AUTH_LIBRARY" ]; then
140 su - "$VBOXWEB_USER" -c "$vboxmanage setproperty websrvauthlibrary \"$VBOXWEB_AUTH_LIBRARY\""
141 if [ $? -ne 0 ]; then
142 fail_msg "Error $? setting webservice authentication library to $VBOXWEB_AUTH_LIBRARY"
143 fi
144 fi
145 if [ -n "$VBOXWEB_AUTH_PWHASH" ]; then
146 su - "$VBOXWEB_USER" -c "$vboxmanage setextradata global \"VBoxAuthSimple/users/$VBOXWEB_USER\" \"$VBOXWEB_AUTH_PWHASH\""
147 if [ $? -ne 0 ]; then
148 fail_msg "Error $? setting webservice password hash"
149 fi
150 fi
151 # prevent inheriting this setting to VBoxSVC
152 unset VBOX_RELEASE_LOG_DEST
153 start_daemon $VBOXWEB_USER $binary $PARAMS > /dev/null 2>&1
154 # ugly: wait until the final process has forked
155 sleep .1
156 PID=`pidof $binary 2>/dev/null`
157 if [ -n "$PID" ]; then
158 echo "$PID" > $PIDFILE
159 RETVAL=0
160 succ_msg "VirtualBox web service started"
161 else
162 RETVAL=1
163 fail_msg "VirtualBox web service failed to start"
164 fi
165 fi
166 return $RETVAL
167}
168
169stop() {
170 if test -f $PIDFILE; then
171 begin_msg "Stopping VirtualBox web service" console;
172 killproc $binary
173 RETVAL=$?
174 # Be careful: wait 1 second, making sure that everything is cleaned up.
175 sleep 1
176 if ! pidof $binary > /dev/null 2>&1; then
177 rm -f $PIDFILE
178 succ_msg "VirtualBox web service stopped"
179 else
180 fail_msg "VirtualBox web service failed to stop"
181 fi
182 fi
183 return $RETVAL
184}
185
186restart() {
187 stop && start
188}
189
190status() {
191 echo -n "Checking for VBox Web Service"
192 if [ -f $PIDFILE ]; then
193 echo " ...running"
194 else
195 echo " ...not running"
196 fi
197}
198
199case "$1" in
200start)
201 start
202 ;;
203stop)
204 stop
205 ;;
206restart)
207 restart
208 ;;
209force-reload)
210 restart
211 ;;
212status)
213 status
214 ;;
215setup)
216 ;;
217cleanup)
218 ;;
219*)
220 echo "Usage: $0 {start|stop|restart|status}"
221 exit 1
222esac
223
224exit $RETVAL
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use