2

By default vboxweb.service is only listening on the ipv6 local address ::1. I need this service to listen on all ipv4 addresses so I can use the service remotely.

user@vboxhost:~$ netstat -nl |grep 18083 tcp6       0      0 ::1:18083
:::*                    LISTEN

Editing the /etc/default/virtualbox config file as per Virtualbox documentation (chapter 9.21.1) does not seem to work:

user@vboxhost:~$ cat /etc/default/virtualbox 
# Defaults for virtualbox initscript
# sourced by /etc/init.d/virtualbox
# installed at /etc/default/virtualbox by the maintainer scripts

#
# This is a POSIX shell fragment
#

# Set this to 1 if you would like the virtualbox modules to be loaded by
# the init script.
LOAD_VBOXDRV_MODULE=1

# SHUTDOWN_USERS="foo bar"  
#   check for running VMs of user 'foo' and user 'bar'
#   'all' checks for all active users
# SHUTDOWN=poweroff
# SHUTDOWN=acpibutton
# SHUTDOWN=savestate
#   select one of these shutdown methods for running VMs
#   acpibutton and savestate causes the init script to wait
#   30 seconds for the VMs to shutdown
SHUTDOWN_USERS=""
SHUTDOWN=poweroff

# Custom vboxweb config
VBOXWEB_USER=vbox
VBOXWEB_HOST=0.0.0.0
VBOXWEB_PORT=18083

No change after restarting the service:

user@vboxhost:~$ sudo systemctl restart vboxweb.service 
user@vboxhost:~$ netstat -nl |grep 18083
tcp6       0      0 ::1:18083               :::*                    LISTEN 

I've also tried to change the port via /etc/default/virtualbox, this also does not work.

Note: I edited the /lib/systemd/system/vboxweb.service startscript to pass the '--host 0.0.0.0' argument. this works, but I don think this is the right approach.

3 Answers 3

1

I think your change to /etc/init.d/virtualbox does not work because that is not sourced by systemd. Try this.

  1. Create a directory named `/etc/systemd/service/vboxweb.service.d
  2. In it, create a file named custom-host.conf.

The contents of the file would be:

[Service]
Environment=VBOXWEB_HOST=0.0.0.0

Then:

systemctl daemon-reload
systemctl restart vboxweb

Using these kinds of files is described at in man systemd.unit:

Along with a unit file foo.service, a "drop-in" directory foo.service.d/ may exist. All files with the suffix ".conf" from this directory will be parsed after the file itself is parsed. This is useful to alter or add configuration settings for a unit, without having to modify unit files. Each drop-in file must have appropriate section headers. Note that for instantiated units, this logic will first look for the instance ".d/" subdirectory and read its ".conf" files, followed by the template ".d/" subdirectory and the ".conf" files there. Also note that settings from the "[Install]" section are not honoured in drop-in unit files, and have no effect.

Setting environment variables is documented in man systemd.exec

4
  • Thanks, but this does not seem to work.
    – DB9
    Jul 2, 2016 at 14:31
  • Thanks, but this does not seem to work. It seems vboxwebsrv does not look at environment variables. It looks like there used to be an /etc/init.d/vboxweb-service startup script. My guess is this would somehow parse the /etc/default/virtualbox file for VBOXWEB settings. vboxwebsrv itself seems not to have any functionality to load a config file. The current systemd config does not have the reading of /etc/default/virtualbox in place. In other words, I need to look into systemd configuration how I can configure executable args in a nice way.
    – DB9
    Jul 2, 2016 at 14:37
  • Oops, wrong solution...
    – mrlitsta
    Mar 7, 2019 at 18:31
  • I made a comment on the solution that worked for me, but this does look like a good longer-term solution to the Launchpad bug I filed: bugs.launchpad.net/ubuntu/+source/virtualbox/+bug/1819045.
    – mrlitsta
    Mar 7, 2019 at 18:38
1

I was able to get my phpVirtualBox working by following the tips above, and also by running

vboxbmanage setproperty websrvauthlibrary null

Next, I also changed where the PID file is written to. Here's the [Service] block from /lib/systemd/system/vboxweb.service:

[Service]
User=vbox
Group=vboxusers
Type=forking
ExecStart=/usr/bin/vboxwebsrv --host=0.0.0.0 --pidfile /home/vboxadmin/.vboxweb.pid --background
PIDFile=/home/vboxadmin/.vboxweb.pid
2
  • Still present in 18.04 and later. I filed a bug: bugs.launchpad.net/ubuntu/+source/virtualbox/+bug/1819045. It looks like the Oracle package systemd.unit file still uses the old init script, which picks up the environment variable. Perhaps the virtualbox package maintainer should use the solution proposed by @mark-stosberg?
    – mrlitsta
    Mar 7, 2019 at 18:34
  • I should mention that I was able to get mine to work without changing vboxmanage setproperty websrvauthlibrary null, but simply by hardcoding --host=0.0.0.0 in the systemd unit file.
    – mrlitsta
    Mar 7, 2019 at 18:40
0

So, closest I've come to solving this thing is this:

Edit /lib/systemd/system/vboxweb.service to start the service with the --host=0.0.0.0 option. I also configured the service to start as non-root user vbox for a little more security.

[Unit]
Description=VirtualBox Web Service
After=network.target

[Service]
Type=forking
ExecStart=/usr/bin/vboxwebsrv --pidfile /run/vboxweb/vboxweb.pid --host=0.0.0.0 --background
PIDFile=/run/vboxweb/vboxweb.pid
User=vbox
Group=vboxusers

[Install]
WantedBy=multi-user.target

Create and set correct permessions for /run/vboxweb:

sudo mkdir /run/vboxweb
sudo chown vbox:vboxusers /run/vboxweb
sudo chmod 755 /run/vboxweb/

Daemon reload systemd and restart vboxweb service:

sudo systemctl daemon-reload
sudo systemctl restart vboxweb.service

The service is now listening on 0.0.0.0 and running as user vbox:

user@vboxhost:~$ netstat -nl |grep 18083
tcp        0      0 0.0.0.0:18083           0.0.0.0:*               LISTEN     


user@vboxhost:~$ ps -ef |grep vboxweb
vbox      2905     1  0 17:08 ?        00:00:00 /usr/lib/virtualbox/vboxwebsrv --pidfile /run/vboxweb/vboxweb.pid --host=0.0.0.0 --background

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .