Page 1 of 2

[solved] vboxweb-service won´t start as unprivileged user

Posted: 24. Mar 2011, 14:40
by larsen
Hi,

I have a Debian Squeeze box with virtualbox-4.0 installed from the virtualbox.org APT source. Now, I want to use vboxweb-service so I can manage my VMs with phpVirtualBox. I already got it running as a daemon after creating the file "/etc/default/virtualbox".

Unfortunately, it only works when I use "VBOXWEB_USER=root" - setting it to "VBOXWEB_USER=vbox" doesn´t work:

Code: Select all

root@vmserver:/home# /etc/init.d/vboxweb-service start
Starting VirtualBox web service:
 failed!
The user "vbox" has been created by me and its primary group is "vboxusers". The home dir "/home/vbox/" also exists.

What else do I have to do to make this work?


Lars

Re: vboxweb-service won´t start as unprivileged user

Posted: 26. Mar 2011, 01:55
by Perryg
Why are you starting the service as root? Start it as normal user (your vbox you created)
If you can't start it as normal user you will not be able to run it as normal user and must have permission issues.

Re: vboxweb-service won´t start as unprivileged user

Posted: 28. Mar 2011, 15:12
by larsen
I have changed it to VBOXWEB_USER=vbox, stopped the already running service, then "su - vbox" and tried to start it:

Code: Select all

vbox@atl-vmserver:~$ /etc/init.d/vboxweb-service start
Starting VirtualBox web service:
 failed!
There is no further info in "/var/log/vboxweb" why the service could not be started, but I can start it with:

Code: Select all

su vbox -c '/usr/bin/vboxwebsrv -H 192.168.120.140'
Nevertheless, there is an init script so I want to use that so the service is also started automatically at boot time and can be stopped/restarted with the "normal" ways/tools. How can I achieve that?

Re: vboxweb-service won´t start as unprivileged user

Posted: 28. Mar 2011, 20:24
by Sasquatch
On what port is it configured to run? If it's on a port below 1024, then that's the problem. Another reason could be that it's configured to run on a port that already has something running on, like a proxy.

Re: vboxweb-service won´t start as unprivileged user

Posted: 28. Mar 2011, 21:19
by Perryg
You could post your /etc/default/virtualbox so we can see what the problem is.
Does /etc/init.d/vboxweb-service exist ?

Re: vboxweb-service won´t start as unprivileged user

Posted: 29. Mar 2011, 11:00
by larsen
It´s using the default port 18083 (not specifically configured). Nothing else is configured to run on that port (The IP has been changed from .140 to .5 in the meantime).

Code: Select all

atl-vmserver:~# cat /etc/default/virtualbox
#VBOXWEB_USER=root
VBOXWEB_USER=vbox
VBOXWEB_HOST=192.168.120.5
VBOXWEB_LOGFILE=/var/log/vboxweb

Code: Select all

atl-vmserver:~# ll /etc/init.d/vbox*
-rwxr-xr-x 1 root root 11460 Feb 17 18:22 /etc/init.d/vboxdrv
-rwxr-xr-x 1 root root  8131 Feb 17 18:22 /etc/init.d/vboxweb-service
I was working on another problem yesterday and I am not sure what I have changed that could affect this (if anything), but now I get another error message and it´s a little bit more informative than the "failed" before =)

Code: Select all

vbox@atl-vmserver:~$ /etc/init.d/vboxweb-service start
Starting VirtualBox web service:/etc/init.d/vboxweb-service: 369: cannot create /var/run/vboxweb-service: Permission denied
done..
Of course, that´s correct:

Code: Select all

vbox@atl-vmserver:~$ ll -d /var/run/
drwxr-xr-x 6 root root 4096 Mar 29 10:42 /var/run/
Now, I don´t think that it would be a good idea to give vbox write permissions on /var/run, would it? Also, wouldn´t the normal(TM) way be to start the service as root on system boot and configure a user to later switch to dropping privileges (like Apache does)?

Re: vboxweb-service won´t start as unprivileged user

Posted: 29. Mar 2011, 14:34
by Perryg
The user name that starts the service needs to be the one that is logged into the machine, or if not you should at least have the user in the vboxusers group. ( I have not tested yet) I would think that you would also need to set the VBOX_HOME for the vbox user, but here again I have not tested this either.
Try putting atl-vmserver in the /etc/default/virtualbox file instead of vbox and see if that allows it to start.
remove the VBOX_LOGFILE= for now.
See if this works.

Re: vboxweb-service won´t start as unprivileged user

Posted: 29. Mar 2011, 15:35
by larsen
"atl-vmserver" is the hostname, not the username. I have now added "vbox" to the group "vboxusers", removed VBOX_LOGFILE, and set VBOX_HOME (/home/vbox/.VirtualBox) as requested, but as I supposed this didn´t change the permission problem.

Only root has write permissions so I don´t see how an unprivileged user should be able to use the init script. It´s possible to start the webservice manually with that user, but only root can use the init script.

Do you have a server running VirtualBox or do you manually start it?

Re: vboxweb-service won´t start as unprivileged user

Posted: 29. Mar 2011, 15:41
by Perryg
It starts all by itself and uses the init.d with normal user able to access. I am currently compiling a huge project on the server but yes I do have it all working.
Give me a bit and I will see if I can reproduce you problem. One question, when you log into the server what name do you use, is it vbox?

Re: vboxweb-service won´t start as unprivileged user

Posted: 29. Mar 2011, 15:49
by larsen
Thanks a lot for your help!

I log into the server as root and then I could start VirtualBox with:

Code: Select all

su vbox -c '/usr/bin/vboxwebsrv -H 192.168.120.5 --background'
But I want that everything is started automatically.

Re: vboxweb-service won´t start as unprivileged user

Posted: 29. Mar 2011, 18:03
by Perryg
OK compile finally stopped and I got a chance to check. I seem to remember running to this and the fix for me was to actually use my user environment for the log file (or not use the log file).

I did check and it is saving in /home/<user>/vboxweb/vboxweb.log and the service does auto start with no error.

If you would rather have this in a different location you would need to contact http://code.google.com/p/phpvirtualbox/ Click on issues and ask them.

Re: vboxweb-service won´t start as unprivileged user

Posted: 29. Mar 2011, 18:46
by larsen
How do you automatically start VirtualBox?
With the script "/etc/init.d/vboxweb-service" that is started at boot time as root and then using the user specified in "/etc/default/virtualbox"?

Re: vboxweb-service won´t start as unprivileged user

Posted: 29. Mar 2011, 18:55
by Perryg
I login as me (normal user)
/etc/init.d/vboxweb-service /etc/default/virtualbox are configured
My user name is in the vboxusers group.

/etc/default/virtualbox

Code: Select all

VBOXWEB_USER=perry
VBOXWEB_PORT=xxxxx
VBOXWEB_LOGFILE=/home/perry/vboxweb/vboxweb.log
If this does not auto start for you you may need to run sudo update-rc.d vboxweb-service defaults
see: http://code.google.com/p/phpvirtualbox/ ... onfigLinux

Re: vboxweb-service won´t start as unprivileged user

Posted: 29. Mar 2011, 20:33
by Sasquatch
Wouldn't it be easy to just use VBOXWEB_PIDFILE=/path/to/pidfile, where you specify a location that the user has write access to? You can always create a folder in /var/run and allow the vbox user write permissions there. So you end up with the following:

Code: Select all

VBOXWEB_PIDFILE=/var/run/vbox/vboxweb-service
Folder /var/run/vbox has vbox:root ownership or vbox:vboxusers if you prefer. File mask needs to be at least 755, but it can be 775 if you like.

Re: vboxweb-service won´t start as unprivileged user

Posted: 30. Mar 2011, 09:42
by larsen
Perryg wrote:I login as me (normal user)
[/code]
Well, IMHO it´s not "autostart" when you have to login. Though, I will play around with some settings in "/etc/default/virtualbox" when the server has moved to it´s final place. Co-workers were complaining that it was too loud =) Perhaps the original problem was the result of some other problem I at first had.
Sasquatch wrote:Wouldn't it be easy to just use VBOXWEB_PIDFILE=/path/to/pidfile, where you specify a location that the user has write access to?
That sounds very promising! I was already using the documentation from phpVirtualBox that Perry noted, but that webpage is missing the pidfile information. Will search for the original docs and ask Ian to update his page and additionally link to the original page.

Thanks again! I will continue to work on this in a few days and keep you updated.