How can I configure vboxweb to listen on specific adress on Ubuntu 16.04?

5,846

Solution 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

Solution 2

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

Share:
5,846

Related videos on Youtube

DB9
Author by

DB9

Updated on September 18, 2022

Comments

  • DB9
    DB9 over 1 year

    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.

  • DB9
    DB9 almost 8 years
    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.
  • mrlitsta
    mrlitsta about 5 years
    Oops, wrong solution...
  • mrlitsta
    mrlitsta about 5 years
    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
    mrlitsta about 5 years
    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
    mrlitsta about 5 years
    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.