[31794] | 1 | #!/bin/sh
|
---|
[69246] | 2 | # $Id: vboxweb-service.sh 93115 2022-01-01 11:31:46Z vboxsync $
|
---|
| 3 | ## @file
|
---|
[36480] | 4 | # VirtualBox web service API daemon init script.
|
---|
[31794] | 5 | #
|
---|
[69246] | 6 |
|
---|
| 7 | #
|
---|
[93115] | 8 | # Copyright (C) 2006-2022 Oracle Corporation
|
---|
[31794] | 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 |
|
---|
[56752] | 19 | # chkconfig: 345 35 65
|
---|
[36480] | 20 | # description: VirtualBox web service API
|
---|
[31794] | 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
|
---|
[36480] | 28 | # Description: VirtualBox web service API
|
---|
[82263] | 29 | # X-Required-Target-Start: network-online
|
---|
[31794] | 30 | ### END INIT INFO
|
---|
| 31 |
|
---|
| 32 | PATH=$PATH:/bin:/sbin:/usr/sbin
|
---|
[58326] | 33 | SCRIPTNAME=vboxweb-service.sh
|
---|
[31794] | 34 |
|
---|
| 35 | [ -f /etc/vbox/vbox.cfg ] && . /etc/vbox/vbox.cfg
|
---|
| 36 |
|
---|
| 37 | if [ -n "$INSTALL_DIR" ]; then
|
---|
| 38 | binary="$INSTALL_DIR/vboxwebsrv"
|
---|
[41365] | 39 | vboxmanage="$INSTALL_DIR/VBoxManage"
|
---|
[31794] | 40 | else
|
---|
[43365] | 41 | binary="/usr/lib/virtualbox/vboxwebsrv"
|
---|
| 42 | vboxmanage="/usr/lib/virtualbox/VBoxManage"
|
---|
[31794] | 43 | fi
|
---|
| 44 |
|
---|
| 45 | # silently exit if the package was uninstalled but not purged,
|
---|
[43365] | 46 | # applies to Debian packages only (but shouldn't hurt elsewhere)
|
---|
| 47 | [ ! -f /etc/debian_release -o -x $binary ] || exit 0
|
---|
[31794] | 48 |
|
---|
[43365] | 49 | [ -r /etc/default/virtualbox ] && . /etc/default/virtualbox
|
---|
[31794] | 50 |
|
---|
[57945] | 51 | PIDFILE="/var/run/${SCRIPTNAME}"
|
---|
[31794] | 52 |
|
---|
[57945] | 53 | # Preamble for Gentoo
|
---|
| 54 | if [ "`which $0`" = "/sbin/rc" ]; then
|
---|
| 55 | shift
|
---|
[31794] | 56 | fi
|
---|
| 57 |
|
---|
[57945] | 58 | begin_msg()
|
---|
| 59 | {
|
---|
| 60 | test -n "${2}" && echo "${SCRIPTNAME}: ${1}."
|
---|
[58326] | 61 | logger -t "${SCRIPTNAME}" "${1}."
|
---|
[57945] | 62 | }
|
---|
[31794] | 63 |
|
---|
[57945] | 64 | succ_msg()
|
---|
| 65 | {
|
---|
[58326] | 66 | logger -t "${SCRIPTNAME}" "${1}."
|
---|
[57945] | 67 | }
|
---|
[31794] | 68 |
|
---|
[57945] | 69 | fail_msg()
|
---|
| 70 | {
|
---|
| 71 | echo "${SCRIPTNAME}: failed: ${1}." >&2
|
---|
[58326] | 72 | logger -t "${SCRIPTNAME}" "failed: ${1}."
|
---|
[57945] | 73 | }
|
---|
| 74 |
|
---|
| 75 | start_daemon() {
|
---|
| 76 | usr="$1"
|
---|
| 77 | shift
|
---|
| 78 | su - $usr -c "$*"
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | killproc() {
|
---|
| 82 | killall $1
|
---|
| 83 | rm -f $PIDFILE
|
---|
| 84 | }
|
---|
| 85 |
|
---|
[57985] | 86 | if which start-stop-daemon >/dev/null 2>&1; then
|
---|
[32470] | 87 | start_daemon() {
|
---|
| 88 | usr="$1"
|
---|
| 89 | shift
|
---|
| 90 | bin="$1"
|
---|
| 91 | shift
|
---|
[32538] | 92 | start-stop-daemon --background --chuid $usr --start --exec $bin -- $@
|
---|
[31794] | 93 | }
|
---|
| 94 |
|
---|
| 95 | killproc() {
|
---|
| 96 | start-stop-daemon --stop --exec $@
|
---|
| 97 | }
|
---|
| 98 | fi
|
---|
| 99 |
|
---|
| 100 | vboxdrvrunning() {
|
---|
| 101 | lsmod | grep -q "vboxdrv[^_-]"
|
---|
| 102 | }
|
---|
| 103 |
|
---|
[32470] | 104 | check_single_user() {
|
---|
| 105 | if [ -n "$2" ]; then
|
---|
| 106 | fail_msg "VBOXWEB_USER must not contain multiple users!"
|
---|
| 107 | exit 1
|
---|
| 108 | fi
|
---|
| 109 | }
|
---|
| 110 |
|
---|
[31794] | 111 | start() {
|
---|
| 112 | if ! test -f $PIDFILE; then
|
---|
| 113 | [ -z "$VBOXWEB_USER" ] && exit 0
|
---|
[57945] | 114 | begin_msg "Starting VirtualBox web service" console;
|
---|
[32470] | 115 | check_single_user $VBOXWEB_USER
|
---|
[31794] | 116 | vboxdrvrunning || {
|
---|
| 117 | fail_msg "VirtualBox kernel module not loaded!"
|
---|
| 118 | exit 0
|
---|
| 119 | }
|
---|
[32473] | 120 | PARAMS="--background"
|
---|
[31794] | 121 | [ -n "$VBOXWEB_HOST" ] && PARAMS="$PARAMS -H $VBOXWEB_HOST"
|
---|
| 122 | [ -n "$VBOXWEB_PORT" ] && PARAMS="$PARAMS -p $VBOXWEB_PORT"
|
---|
[40130] | 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"
|
---|
[31794] | 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"
|
---|
[40130] | 133 | [ -n "$VBOXWEB_AUTHENTICATION" ] && PARAMS="$PARAMS -A $VBOXWEB_AUTHENTICATION"
|
---|
[31794] | 134 | [ -n "$VBOXWEB_LOGFILE" ] && PARAMS="$PARAMS -F $VBOXWEB_LOGFILE"
|
---|
[36480] | 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"
|
---|
[41365] | 138 | # set authentication method + password hash
|
---|
| 139 | if [ -n "$VBOXWEB_AUTH_LIBRARY" ]; then
|
---|
[41369] | 140 | su - "$VBOXWEB_USER" -c "$vboxmanage setproperty websrvauthlibrary \"$VBOXWEB_AUTH_LIBRARY\""
|
---|
[41365] | 141 | if [ $? -ne 0 ]; then
|
---|
[41366] | 142 | fail_msg "Error $? setting webservice authentication library to $VBOXWEB_AUTH_LIBRARY"
|
---|
[41365] | 143 | fi
|
---|
| 144 | fi
|
---|
| 145 | if [ -n "$VBOXWEB_AUTH_PWHASH" ]; then
|
---|
[41369] | 146 | su - "$VBOXWEB_USER" -c "$vboxmanage setextradata global \"VBoxAuthSimple/users/$VBOXWEB_USER\" \"$VBOXWEB_AUTH_PWHASH\""
|
---|
[41365] | 147 | if [ $? -ne 0 ]; then
|
---|
[41366] | 148 | fail_msg "Error $? setting webservice password hash"
|
---|
[41365] | 149 | fi
|
---|
| 150 | fi
|
---|
[32559] | 151 | # prevent inheriting this setting to VBoxSVC
|
---|
| 152 | unset VBOX_RELEASE_LOG_DEST
|
---|
[32470] | 153 | start_daemon $VBOXWEB_USER $binary $PARAMS > /dev/null 2>&1
|
---|
[32555] | 154 | # ugly: wait until the final process has forked
|
---|
| 155 | sleep .1
|
---|
[32251] | 156 | PID=`pidof $binary 2>/dev/null`
|
---|
[32555] | 157 | if [ -n "$PID" ]; then
|
---|
| 158 | echo "$PID" > $PIDFILE
|
---|
| 159 | RETVAL=0
|
---|
[58326] | 160 | succ_msg "VirtualBox web service started"
|
---|
[32555] | 161 | else
|
---|
| 162 | RETVAL=1
|
---|
[58326] | 163 | fail_msg "VirtualBox web service failed to start"
|
---|
[32555] | 164 | fi
|
---|
[31794] | 165 | fi
|
---|
| 166 | return $RETVAL
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | stop() {
|
---|
| 170 | if test -f $PIDFILE; then
|
---|
[57945] | 171 | begin_msg "Stopping VirtualBox web service" console;
|
---|
[31794] | 172 | killproc $binary
|
---|
| 173 | RETVAL=$?
|
---|
[60532] | 174 | # Be careful: wait 1 second, making sure that everything is cleaned up.
|
---|
| 175 | sleep 1
|
---|
[32251] | 176 | if ! pidof $binary > /dev/null 2>&1; then
|
---|
| 177 | rm -f $PIDFILE
|
---|
[58326] | 178 | succ_msg "VirtualBox web service stopped"
|
---|
[32627] | 179 | else
|
---|
[58326] | 180 | fail_msg "VirtualBox web service failed to stop"
|
---|
[32251] | 181 | fi
|
---|
[31794] | 182 | fi
|
---|
| 183 | return $RETVAL
|
---|
| 184 | }
|
---|
| 185 |
|
---|
| 186 | restart() {
|
---|
| 187 | stop && start
|
---|
| 188 | }
|
---|
| 189 |
|
---|
| 190 | status() {
|
---|
| 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 |
|
---|
| 199 | case "$1" in
|
---|
| 200 | start)
|
---|
| 201 | start
|
---|
| 202 | ;;
|
---|
| 203 | stop)
|
---|
| 204 | stop
|
---|
| 205 | ;;
|
---|
| 206 | restart)
|
---|
| 207 | restart
|
---|
| 208 | ;;
|
---|
[34603] | 209 | force-reload)
|
---|
| 210 | restart
|
---|
| 211 | ;;
|
---|
[31794] | 212 | status)
|
---|
| 213 | status
|
---|
| 214 | ;;
|
---|
| 215 | setup)
|
---|
| 216 | ;;
|
---|
| 217 | cleanup)
|
---|
| 218 | ;;
|
---|
| 219 | *)
|
---|
| 220 | echo "Usage: $0 {start|stop|restart|status}"
|
---|
| 221 | exit 1
|
---|
| 222 | esac
|
---|
| 223 |
|
---|
| 224 | exit $RETVAL
|
---|