Sunday, November 17, 2013

Vboxwebsrv with systemd on openSUSE

This works if you need to restart vboxwebsrv using systemd in openSUSE. Some folks  will raise some eye browse with this configuration for sure :-). The USER-NAME in the entry below is the username of the user who will access vboxwebsrv.

Create a unit file in /etc.

  •  /etc/systemd/system/VBoxWeb.service 

why etc? because according to the man pages somewhere that if a local admin will make a unit file it should be in /etc because the order of which the unit file to be executed. Meaning if you have conflicting unit files in /usr and in /etc then the latter will be prioritize. Note that packages (*.rpm) unit files are in /usr.

Put the entry below inside that unit file.

 Description=VirtualBox Web Service

 ExecStartPre=/bin/bash -c 'if [[ -e $PIDFile ]]; then rm -f "$PIDFile"; fi'

 ExecStart=/usr/bin/vboxwebsrv --pidfile "$PIDFile" --background


 This is not a shell script! That is what systemd folks will say for sure ;-). The ExecStartPre in that unit file is removing (deleting) the pid file so when vboxwebsv should restart  you will not get any errors. The EnvironmentFile entry is like sourcing a shell script. In this case it is sourcing the unit file itself, hence the variable PIDFile. Note that with systemd 208 which is the default fro 13.1 the ExecPre line in that unit file is not required anymore, seems systemd is much smarter now a days! :-). 12.3 below you might still need it.

Create the temporary files and directories.

  •  echo "d /run/VBoxWeb 0755 USER-NAME vboxusers" > /etc/tmpfiles.d/VBoxWeb.conf 

  •  mkdir /run/VBoxWeb 

Change the permission.

  •  chown USER-NAME:vboxusers /run/VBoxWeb 

  •  chmod 755 /run/VBoxWeb 

Disable the vboxwebsrv service that came with VirtualBox package.

  •  chkconfig vboxweb-service off 


  •  systemctl disable vboxweb-service.service 

Start your newly created (unit file)  Daemon.

  •  systemctl start VBoxWeb.service 

Enable your newly created (unit file)  Daemon.

  •  systemctl enable VBoxWeb.service

This is very useful when you are using phpvirtualbox and you are restarting the vms every once in a while.