<div dir="ltr"><div>Hello,</div><div><br></div><div>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).</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>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.</div><div><br></div><div>Longer term it may be neater for the vboxweb-service script to handle launching vboxweb under multiple different userids.</div><div><br></div><div>kind regards,</div><div><br></div><div>Julien</div><div><br></div><div>The attached patch is published under the terms of the MIT license.<br></div><div><br></div><div><div>--- vboxweb-service.sh.orig<span style="white-space:pre">   </span>2017-08-23 21:55:02.092336635 +0200</div><div>+++ vboxweb-service.sh<span style="white-space:pre">     </span>2017-08-22 12:56:31.957280153 +0200</div><div>@@ -75,7 +75,9 @@</div><div> }</div><div> </div><div> killproc() {</div><div>-    killall $1</div><div>+    usr="$1"</div><div>+    shift    </div><div>+    killall --user $usr $*</div><div>     rm -f $PIDFILE</div><div> }</div><div> </div><div>@@ -85,11 +87,15 @@</div><div>         shift</div><div>         bin="$1"</div><div>         shift</div><div>-        start-stop-daemon --background --chuid $usr --start --exec $bin -- $@</div><div>+        start-stop-daemon --background --chuid $usr --start --exec $bin --user $usr -- $@</div><div>     }</div><div> </div><div>     killproc() {</div><div>-        start-stop-daemon --stop --exec $@</div><div>+        usr="$1"</div><div>+        shift</div><div>+        bin="$1"</div><div>+        shift                        </div><div>+        start-stop-daemon --stop --exec $bin --user $usr</div><div>     }</div><div> fi</div><div> </div><div>@@ -149,7 +155,7 @@</div><div>         start_daemon $VBOXWEB_USER $binary $PARAMS > /dev/null 2>&1</div><div>         # ugly: wait until the final process has forked</div><div>         sleep .1</div><div>-        PID=`pidof $binary 2>/dev/null`</div><div>+        PID=`pgrep --full --uid $VBOXWEB_USER $binary 2>/dev/null`</div><div>         if [ -n "$PID" ]; then</div><div>             echo "$PID" > $PIDFILE</div><div>             RETVAL=0</div><div>@@ -165,11 +171,11 @@</div><div> stop() {</div><div>     if test -f $PIDFILE; then</div><div>         begin_msg "Stopping VirtualBox web service" console;</div><div>-        killproc $binary</div><div>+        killproc $VBOXWEB_USER $binary</div><div>         RETVAL=$?</div><div>         # Be careful: wait 1 second, making sure that everything is cleaned up.</div><div>         sleep 1</div><div>-        if ! pidof $binary > /dev/null 2>&1; then</div><div>+        if ! pgrep --full --uid $VBOXWEB_USER $binary > /dev/null 2>&1; then</div><div>             rm -f $PIDFILE</div><div>             succ_msg "VirtualBox web service stopped"</div><div>         else</div></div><div><br></div></div>