[vbox-dev] [PATCH] minor fix to address vboxweb-service.sh assuming only a single instance of vboxwebsrv
Julien Levi
julienlevi at gmail.com
Wed Aug 23 23:16:22 UTC 2017
Hello,
Currently the vboxweb-service.sh init script assumes that only a single
instance of vboxwebsrv will be running on the system – if another user
starts their own instance of vboxwebsrv the script will fail to work
properly (it will shut down instances it did not launch and/or will fail to
create an instance of vboxwebsrv if any other user of the system has
already launched it under their own account).
I experienced concurrency issues at boot when another user launched
vboxwebsrv in their crontab with @reboot. vboxweb-service.sh only checks
for the process name, not the userid under which the process is running so
can report the service as defined in the config files ($VBOXWEB_USER,
$VBOXWEB_HOST etc) has started when in fact it has not.
Attached is modified version of vboxweb-service.sh that addresses this
issue - it ignores other instances of vboxwebsrv and limits itself to
managing instances of vboxwebsrv launched as the user defined by
VBOXWEB_USER in the config files. It's a minor modification, but bear in
mind I've only tested it on my own Debian 8 system.
I also notice that vboxwebsrv does not exit if it can not bind a socket, is
this a bug or by design? This seems odd as what is the point of a web
service that cannot talk to the network? It makes it harder to handle the
situation where another process has bound the socket. The modified
vboxwebservice.sh attached doesn't address that scenario as the service
does technically start up.
Longer term it may be neater for the vboxweb-service script to handle
launching vboxweb under multiple different userids.
kind regards,
Julien
The attached patch is published under the terms of the MIT license.
--- vboxweb-service.sh.orig 2017-08-23 21:55:02.092336635 +0200
+++ vboxweb-service.sh 2017-08-22 12:56:31.957280153 +0200
@@ -75,7 +75,9 @@
}
killproc() {
- killall $1
+ usr="$1"
+ shift
+ killall --user $usr $*
rm -f $PIDFILE
}
@@ -85,11 +87,15 @@
shift
bin="$1"
shift
- start-stop-daemon --background --chuid $usr --start --exec $bin --
$@
+ start-stop-daemon --background --chuid $usr --start --exec $bin
--user $usr -- $@
}
killproc() {
- start-stop-daemon --stop --exec $@
+ usr="$1"
+ shift
+ bin="$1"
+ shift
+ start-stop-daemon --stop --exec $bin --user $usr
}
fi
@@ -149,7 +155,7 @@
start_daemon $VBOXWEB_USER $binary $PARAMS > /dev/null 2>&1
# ugly: wait until the final process has forked
sleep .1
- PID=`pidof $binary 2>/dev/null`
+ PID=`pgrep --full --uid $VBOXWEB_USER $binary 2>/dev/null`
if [ -n "$PID" ]; then
echo "$PID" > $PIDFILE
RETVAL=0
@@ -165,11 +171,11 @@
stop() {
if test -f $PIDFILE; then
begin_msg "Stopping VirtualBox web service" console;
- killproc $binary
+ killproc $VBOXWEB_USER $binary
RETVAL=$?
# Be careful: wait 1 second, making sure that everything is
cleaned up.
sleep 1
- if ! pidof $binary > /dev/null 2>&1; then
+ if ! pgrep --full --uid $VBOXWEB_USER $binary > /dev/null 2>&1;
then
rm -f $PIDFILE
succ_msg "VirtualBox web service stopped"
else
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.virtualbox.org/pipermail/vbox-dev/attachments/20170824/c61965c3/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vboxweb-service.sh
Type: application/x-sh
Size: 6546 bytes
Desc: not available
URL: <http://www.virtualbox.org/pipermail/vbox-dev/attachments/20170824/c61965c3/attachment.sh>
More information about the vbox-dev
mailing list