Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 420991 - app-emulation/phpvirtualbox - install vboxinit autostart and autosave init script
Summary: app-emulation/phpvirtualbox - install vboxinit autostart and autosave init sc...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: New packages (show other bugs)
Hardware: All Linux
: Normal enhancement (vote)
Assignee: Markos Chandras (RETIRED)
URL: http://code.google.com/p/phpvirtualbox/
Whiteboard:
Keywords: PATCH, REVIEWED
Depends on:
Blocks:
 
Reported: 2012-06-13 14:05 UTC by Balint SZENTE
Modified: 2012-08-17 19:24 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
vboxinit-initd (vboxinit-initd,1.10 KB, text/plain)
2012-06-13 14:07 UTC, Balint SZENTE
Details
phpvirtualbox-4.1.7.ebuild.patch (phpvirtualbox-4.1.7.ebuild.patch,674 bytes, patch)
2012-06-13 14:10 UTC, Balint SZENTE
Details | Diff
startupmode.png (startupmode.png,88.80 KB, image/png)
2012-06-14 08:02 UTC, Balint SZENTE
Details
phpvirtualbox-4.1.7.ebuild.patch (phpvirtualbox-4.1.7.ebuild.patch,907 bytes, patch)
2012-06-15 11:36 UTC, Balint SZENTE
Details | Diff
vboxinit-initd (vboxinit-initd,1.11 KB, text/plain)
2012-06-15 11:44 UTC, Balint SZENTE
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Balint SZENTE 2012-06-13 14:05:40 UTC
Currently the virtualbox and phpvirtualbox combination does not provide any solution for automatic start and save of virtual machines, which is really necessary for unattended virtual machine servers.

I took the vboxinit script from the phpVirtualBox project which was made for Debian, and I rewrote it for Gentoo. Please include it to Portage.

Reproducible: Always
Comment 1 Balint SZENTE 2012-06-13 14:07:20 UTC
Created attachment 315193 [details]
vboxinit-initd
Comment 2 Balint SZENTE 2012-06-13 14:07:44 UTC
Comment on attachment 315193 [details]
vboxinit-initd

Virtual machine autostart and autosave init script
Comment 3 Balint SZENTE 2012-06-13 14:10:19 UTC
Created attachment 315195 [details, diff]
phpvirtualbox-4.1.7.ebuild.patch

Patch for app-emulation/phpvirtualbox-4.1.7.ebuild
Comment 4 Markos Chandras (RETIRED) gentoo-dev 2012-06-13 19:17:40 UTC
I don't understand what problem you are trying to solve here and why you want phpvirtualbox to autostart any virtual machine. This is a web application so it should not do such things behind your back. This init script should belong to virtualbox package but honestly I wouldn't be happy about this. If you really need to start vms during boot, then keep your own script in /usr/local/bin
Comment 5 Markos Chandras (RETIRED) gentoo-dev 2012-06-13 21:07:16 UTC
Now that I think about it, this package makes no sense at all. phpvirtualbox does NOT require virtual machines (and virtualbox) to be installed on the host so there may not be virtual machines to boot locally. I am closing this as invalid as it certainly does not fit in the phpvirtualbox package. You may want to open a new bug to inclusion in virtualbox but I suspect they will close it as invalid too. This init script only applies to very specific user configuration so I still think it should be scriptable by users and not distributed within a package
Comment 6 Balint SZENTE 2012-06-14 08:01:02 UTC
Before closing as invalid, please give a chance for a reply (wait 1 day for example). For me it does make sense, otherwise I would not open an issue. There is a *real* problem that must be handled and it needs to be discussed at least. Let us find a proper solution for Gentoo.

You have absolutely right in the fact that phpVirtualBox does not require VirtualBox on the same host. I know it, I'm using it for a very long time. But if you install this init script, it does not mean you also must to use it (like many other initscript in Gentoo). Whether this init script should be part of virtualbox package is debatable.

Let me explain why this initscrip is necessary:
 * phpVirtualBox is used mainly for controlling headless servers which runs several virtual machines. Of course, you can use for your desktop machine as well, but it is kinda exception.
 * on a virtual machine server you want the machines working all time time, even if there is a power failure
 * if there is a power failure, and the server restarts, some machines must be started automatically
 * VirtualBox does not offer any solution for this

phpVirtualBox has a feature, which is disabled by default in config.php file:

/* Enable startup / shutdown configuration.
 * This only works in linux and you must add the vboxinit file to
 * your startup scripts list.
 */
var $startStopConfig = true;

If you enable this, a new option will appear in the Settings->General->Basic tab (see the attached screenshot). There you can select whether you want automatic or manual startup. phpVirtualBox saves this option in the .vbox file of the machine in the <ExtraData/> element. VirtualBox has API for getting and setting extra data for a machine (VBoxManage [getextradata|setextradata] ). This is what the provided init script checks and launches the machines if the "pvbx/startupMode" extra data was set to auto by phpVirtualBox.

This init script is *mandatory* if you want autostart feature of phpVirtualBox. And you definitely want this for a headless server.
The author of the phpVirtualBox provides this script only for Debian, and that's why I rewrote it as an openrc init script for Gentoo.

So if the package installs this init script, it will definitely help the user. And it's up to the user whether it adds to the default runlevel or not. I does not make sense for every user to reimplement the same script. You cannot expect every Gentoo user who want to make a virtual machine server to know the internals of phpVirtualBox and vboxwebsvc and VBoxManage.

On the other hand this init script cannot be added to app-emulation/virtualbox because it *depends on a phpvirtualbox* functionality: the setting of "pvbx/startupMode" extra data. They are connected logically.

Taking your arguments probably the best would be to create a new ebuild just for this initscript, and make an einfo message in app-emulation/phpvirtualbox: "you may consider to install app-emulation/phpvirtualbox-vboxinit on the host where VirtualBox is running". Something like that. It's up to the user whether it will or not install it.

But I repeat, this is not a very specific scenario, it is the *common* scenario for a phpVirtualBox user, because it is a very useful feature. The script should be written *once* and put in Portage, and should not be reimplemented by each user.

What is your proposal?
Comment 7 Balint SZENTE 2012-06-14 08:02:11 UTC
Created attachment 315251 [details]
startupmode.png

Screenshot of the Settings->General->Basic tab with the Startup Mode option.
Comment 8 Markos Chandras (RETIRED) gentoo-dev 2012-06-14 08:45:40 UTC
Ok I must apologize as I haven't understood the issue properly. Thanks for the init script. I will review it and post comments soon
Comment 9 Markos Chandras (RETIRED) gentoo-dev 2012-06-14 16:40:57 UTC
There is a typo in the ebuild patch. 

"saveing" -> "saving"

Other than that, the patches look ok
Comment 10 Balint SZENTE 2012-06-15 07:46:13 UTC
Thanks for your patience. Yes, that typo needs to be fixed.

After giving a second thought, I think the proper solution for this initscript is to create a simple package for it (with the doinit line and RDEPEND virtualbox), because as you said, it is very possible that somebody has a web server, where phpVirtualBox is installed and the vboxwebsrv to be on another host. This script must be installed on the host where virtualbox is installed.

Should I open a new ticket for this? What do you recommend?
Comment 11 Markos Chandras (RETIRED) gentoo-dev 2012-06-15 08:47:36 UTC
Nah that would be an overkill. Having one ebuild for just one file is pointless. The phpvirtualbox ebuild will install the file and users are free to use it or not
Comment 12 Balint SZENTE 2012-06-15 11:36:23 UTC
Created attachment 315411 [details, diff]
phpvirtualbox-4.1.7.ebuild.patch

New ebuild patch with more explanations. This should be better to include in Portage.
Comment 13 Balint SZENTE 2012-06-15 11:44:02 UTC
Created attachment 315413 [details]
vboxinit-initd

New version of the vboxinit script with '/var/log/vboxinit.log' log file. I think it's better to have the script name instead just 'vb.log'.
Comment 14 Markos Chandras (RETIRED) gentoo-dev 2012-06-16 09:54:36 UTC
Maybe it worth replacing 

VBoxManage startvm $UUID --type headless

with

VBoxHeadless -s $UUID ?

I will test the patch locally today and commit it within 48 hours
Comment 15 Balint SZENTE 2012-06-16 20:18:24 UTC
(In reply to comment #14)
> VBoxManage startvm $UUID --type headless
> 
> with
> 
> VBoxHeadless -s $UUID ?

You're right, actually this is the recommended way: <http://www.virtualbox.org/manual/ch07.html#vboxheadless>

But I think the --vrde=config option is also necessary to enable VRDP server depending on the VM settings, like this:

VBoxHeadless --startvm $UUID --vrde=config
Comment 16 Markos Chandras (RETIRED) gentoo-dev 2012-06-17 09:17:43 UTC
Committed. Thanks
Comment 17 Balint SZENTE 2012-06-18 11:21:32 UTC
Sorry Markos for opening this issue again. Today I made an update on the server, that I manage and:

VBoxHeadless --startvm $UUID --vrde=config

hangs up the init process. It does not exit after starting the machine like VBoxManage does. I did not expect that VBoxHeadless to behave different from VBoxManage in this way.

Please change back to:

VBoxManage startvm $UUID --type headless

It seems that VBoxHeadless is good mainly for manual starting the machines, to see the error logs.

Sorry for the inconvenience, I should have test it.
Comment 18 Markos Chandras (RETIRED) gentoo-dev 2012-06-18 17:28:43 UTC
Ok I just pushed a new revision and removed the old one
Comment 19 Markos Chandras (RETIRED) gentoo-dev 2012-08-11 12:16:36 UTC
I just noticed the patch is incomplete. /etc/conf.d/vboxwebsrv should also be supplied with the ebuild as well
Comment 20 Balint SZENTE 2012-08-13 07:24:28 UTC
It is supplied for a long time by the virtualbox package/ebuild built with USE="vboxwebsrv":

# equery b vboxwebsrv 
 * Searching for vboxwebsrv ... 
app-emulation/virtualbox-4.1.12 (/etc/conf.d/vboxwebsrv)
app-emulation/virtualbox-4.1.12 (/usr/lib64/virtualbox/vboxwebsrv)
app-emulation/virtualbox-4.1.12 (/usr/bin/vboxwebsrv -> /usr/lib64/virtualbox/VBox)
app-emulation/virtualbox-4.1.12 (/etc/init.d/vboxwebsrv)

So the patch is complete. Just leave as it is.

On the other hand, this patch soon will become obsolete starting with VirtualBox 4.2.0:
<https://forums.virtualbox.org/viewtopic.php?p=232358&sid=42932a4ef10a403ecef2e998f48ccc7d&f=15#p232358>

"Added possibility to start VMs during system boot on Linux, OS X and Solaris; see the manual for more information (bug #950)"

For the moment just leave as it is. When VirtualBox 4.2.0 will be released, I assume phpVirtualbox-4.2.x will be updated accordingly by upstream and this patch will not be necessary anymore for >=phpvirtualbox-4.2.x.
Comment 21 Markos Chandras (RETIRED) gentoo-dev 2012-08-13 08:20:07 UTC
(In reply to comment #20)
> It is supplied for a long time by the virtualbox package/ebuild built with
> USE="vboxwebsrv":
> 
> # equery b vboxwebsrv 
>  * Searching for vboxwebsrv ... 
> app-emulation/virtualbox-4.1.12 (/etc/conf.d/vboxwebsrv)
> app-emulation/virtualbox-4.1.12 (/usr/lib64/virtualbox/vboxwebsrv)
> app-emulation/virtualbox-4.1.12 (/usr/bin/vboxwebsrv ->
> /usr/lib64/virtualbox/VBox)
> app-emulation/virtualbox-4.1.12 (/etc/init.d/vboxwebsrv)
> 
> So the patch is complete. Just leave as it is.
> 
> On the other hand, this patch soon will become obsolete starting with
> VirtualBox 4.2.0:
> <https://forums.virtualbox.org/viewtopic.
> php?p=232358&sid=42932a4ef10a403ecef2e998f48ccc7d&f=15#p232358>
> 
> "Added possibility to start VMs during system boot on Linux, OS X and
> Solaris; see the manual for more information (bug #950)"
> 
> For the moment just leave as it is. When VirtualBox 4.2.0 will be released,
> I assume phpVirtualbox-4.2.x will be updated accordingly by upstream and
> this patch will not be necessary anymore for >=phpvirtualbox-4.2.x.

Like I explained multiple times, you don't have to have virtualbox+phpvirtualbox installed on the same box. I have just phpvirtualbox installed so I don't have a vboxwebsrv file under /etc/conf.d. Hence the phpvirtualbox package must supply a vboxwebsrv file if there is not one installed already
Comment 22 Balint SZENTE 2012-08-13 08:42:30 UTC
vboxwebsrv must run on the host where the VirtualBox machine is running. I don't understand what can you do with a single vboxwebsrv script on your computer without having VirtualBox installed. vboxwebsrv belongs to VirtualBox. You cannot use it stand alone.

Example setup with separate host for web server and virtualbox server:

 Host1                    Host2
+---------------+        +-------------+
| PHP Server    | TCP/IP | VBoxSVC     | 
|     &         +<------>+     &       |
| phpVirtualBox |        | vboxwebsrv* |
|               |        | vboxinit    |
+---------------+        +-------------+

* means both init script and ELF binary.

You cannot run vboxwebsrv (neither the init script nor the ELF binary) on Host1 on the above example. vboxwebsrv ELF is communicating with VBoxSVC by XPCOM.
Comment 23 Markos Chandras (RETIRED) gentoo-dev 2012-08-13 16:53:45 UTC
(In reply to comment #22)
> vboxwebsrv must run on the host where the VirtualBox machine is running. I
> don't understand what can you do with a single vboxwebsrv script on your
> computer without having VirtualBox installed. vboxwebsrv belongs to
> VirtualBox. You cannot use it stand alone.
> 
> Example setup with separate host for web server and virtualbox server:
> 
>  Host1                    Host2
> +---------------+        +-------------+
> | PHP Server    | TCP/IP | VBoxSVC     | 
> |     &         +<------>+     &       |
> | phpVirtualBox |        | vboxwebsrv* |
> |               |        | vboxinit    |
> +---------------+        +-------------+
> 
> * means both init script and ELF binary.
> 
> You cannot run vboxwebsrv (neither the init script nor the ELF binary) on
> Host1 on the above example. vboxwebsrv ELF is communicating with VBoxSVC by
> XPCOM.

Then the file must be installed conditionally based on whether virtualbox installed on that host or not
Comment 24 Balint SZENTE 2012-08-14 07:23:41 UTC
(In reply to comment #23)
> Then the file must be installed conditionally based on whether virtualbox
> installed on that host or not

I would kindly ask you to be more specific. With "the file" are you referring to vboxinit file, right? If yes, than please check comment #10 and comment #11.
Comment 25 Markos Chandras (RETIRED) gentoo-dev 2012-08-14 08:09:08 UTC
(In reply to comment #24)
> (In reply to comment #23)
> > Then the file must be installed conditionally based on whether virtualbox
> > installed on that host or not
> 
> I would kindly ask you to be more specific. With "the file" are you
> referring to vboxinit file, right? If yes, than please check comment #10 and
> comment #11.

Yeah I was wrong because the init script that is being installed by phpvirtualbox required the /etc/conf.d/vboxwebsrv to be present. So either both need to be present or none of them

I am inlcined to use something like that in the ebuild

if has_version app-emulation/virtualbox[vboxwebsrv]; then
  <install_init_file>
fi
Comment 26 Balint SZENTE 2012-08-14 11:42:31 UTC
(In reply to comment #25)
> Yeah I was wrong because the init script that is being installed by
> phpvirtualbox required the /etc/conf.d/vboxwebsrv to be present.

Yes. The idea was to not duplicate the configuration data and to reuse the already existing virtualbox web server config.

> So either
> both need to be present or none of them

Exactly: the vboxinit must be run on the same host where virtualbox (and implicitly vboxwebsrv) is installed. That's why the ebuild has the following elog message:

  "You should also add the /etc/init.d/vboxinit script to the"
  "default runlevel on the virtualbox host:"
  "\`rc-update add vboxinit default\`"
  "If the server is on a remote host, than the script must be"
  "copied manually."

> I am inlcined to use something like that in the ebuild
> 
> if has_version app-emulation/virtualbox[vboxwebsrv]; then
>   <install_init_file>
> fi

I don't know if it does worth to make this change. Adding vboxinit to default runlevel is voluntary only, and the ebuild says clearly what should be done with it. On the other hand it is very unlikely to have both phpvirtualbox and virtualbox without vboxwebsrv installed on the same computer.

Anyway if you do make the change, than please change also the elog messages, and inform the user about the necessity of coping the vboxinit script from ${FILESDIR} to the virtualbox host and adding it to the default runlevel there.

Thanks for your work.
Comment 27 Markos Chandras (RETIRED) gentoo-dev 2012-08-14 16:46:40 UTC
(In reply to comment #26)
> (In reply to comment #25)
> > Yeah I was wrong because the init script that is being installed by
> > phpvirtualbox required the /etc/conf.d/vboxwebsrv to be present.
> 
> Yes. The idea was to not duplicate the configuration data and to reuse the
> already existing virtualbox web server config.
> 
> > So either
> > both need to be present or none of them
> 
> Exactly: the vboxinit must be run on the same host where virtualbox (and
> implicitly vboxwebsrv) is installed. That's why the ebuild has the following
> elog message:
> 
>   "You should also add the /etc/init.d/vboxinit script to the"
>   "default runlevel on the virtualbox host:"
>   "\`rc-update add vboxinit default\`"
>   "If the server is on a remote host, than the script must be"
>   "copied manually."
> 
> > I am inlcined to use something like that in the ebuild
> > 
> > if has_version app-emulation/virtualbox[vboxwebsrv]; then
> >   <install_init_file>
> > fi
> 
> I don't know if it does worth to make this change. Adding vboxinit to
> default runlevel is voluntary only, and the ebuild says clearly what should
> be done with it. On the other hand it is very unlikely to have both
> phpvirtualbox and virtualbox without vboxwebsrv installed on the same
> computer.
> 
> Anyway if you do make the change, than please change also the elog messages,
> and inform the user about the necessity of coping the vboxinit script from
> ${FILESDIR} to the virtualbox host and adding it to the default runlevel
> there.
> 
> Thanks for your work.

For me, restarting the apache server (where phpvirtualbox is a vhost) also brings up the vboxinit script which complains about the missing vboxwebsrv in /etc/conf.d. So the init script is not as optional as you may think.

Is there a reason for change the elog message? The init file will only be installed (automatically by portage) if the user has virtualbox installed with the "vboxwebsrv" use flag enabled. Why does the user need to copy the file manually?
Comment 28 Balint SZENTE 2012-08-15 11:23:25 UTC
(In reply to comment #27)
> For me, restarting the apache server (where phpvirtualbox is a vhost) also
> brings up the vboxinit script which complains about the missing vboxwebsrv
> in /etc/conf.d. So the init script is not as optional as you may think.

That's really weird and should not be this way, especially if vboxinit is not added to any runlevel. vboxinit has absolutely nothing to do with apache or any other web server. I use nginx and restarting it or php-fpm does not bring up vboxinit.

If this is your case, than it is a bug somewhere (maybe in vboxinit depend() function?) that causes openrc to start vboxinit, and this must be investigated and fixed. Actually, I think that is the real issue here.

vboxinit is a totally independent init script from apache or any other web server.

> Is there a reason for change the elog message? The init file will only be
> installed (automatically by portage) if the user has virtualbox installed
> with the "vboxwebsrv" use flag enabled.

Yes, because /etc/init.d/vboxinit will not exist, and the user will not be aware of its existence. It will be only in $PORTDIR/app-emulation/phpvirtualbox/files directory.

> Why does the user need to copy the file manually?

The user needs to copy manually the vboxinit script to virtualbox host (Host2 in the above example) in order to have the autostart feature integrated with phpvirtualbox. Check my comment #6.

Summary in short:
 1. There is the original app-emulation/phpvirtualbox package that can be installed on a let's call Host A.
 2. There is the app-emulation/virtualbox[vboxwebsrv] package that can be installed on a let's call Host B. vboxwebsrv MUST run on Host B, i.e. the same host where VBoxSVC is running, because it is communicating with it locally by XPCOM. That's the reason that vboxwebsrv is an inseparable part of virtualbox.
 3. There is this phpVirtualBox's autostart feature, that needs a helper vboxinit script, that MUST be run on Host B, to work. This yields to the problem, that vboxinit uses something phpVirtualBox specific thing (so it may be not part of virtualbox package), but should be run on Host B. So this way vboxinit becames a "stepchild": phpvirtualbox package is not a proper place, because should be run on the computer where virtualbox is installed,  virtualbox package is not a proper place, because basically phpvirtualbox is who can set those <ExtraData/> elements (as descried in comment #6).

So if you put vboxinit in phpvirtualbox package as it is now, people should copy it manually to Host B.
If you install vboxinit if and only if virtualbox[vboxwebsrv] is installed (trivial case when Host A is the same as Host B), than what happens with those people that has virtualbox on a separate host? They will not know about this feature. That's why I said that the elog message should be changed to inform the user of the existence of vboxinit script.

I can put this howto on the gentoo wiki, when we finish with the ebuild.
Comment 29 Markos Chandras (RETIRED) gentoo-dev 2012-08-17 18:24:27 UTC
Thanks fixed again
Comment 30 Balint SZENTE 2012-08-17 19:24:08 UTC
(In reply to comment #29)
> Thanks fixed again

There is a minor typo in the phpvirtualbox-4.1.7-r2.ebuild, Revision 1.2:

"${FILESDIR}/vboxinit to /etc/init.d/vboxinit"

should be changed to:

"${FILESDIR}/vboxinit-initd to /etc/init.d/vboxinit"

The rest is ok. Thank you.