Ubuntu – Ubuntu 15.10 vboxautostart-service stop does not work

systemdvirtualbox

I have replaced my 14.04 system by a fresh install of 15.10. With 14.04 I used the vboxautostart init script to start a vbox guest at boot time and stop it during system shutdown. This used to work very well.

Now I'm trying to achieve a similar setup with Ubuntu 15.10. The main difference is that I have to use systemd which I'm not very familiar with, yet.
I was able to do the vbox specific setup, so I can call
/usr/lib/virtualbox/vboxautostart-service.sh start/stop from the shell and it works perfectly.
I can also use systemctl start vboxautostart-service.service to start the vbox guest. It is even started automatically at system startup after I enabled the service.
However if I try to stop the service with

systemctl stop vboxautostart-service.service

it does nothing, so the guest is still running afterwards.
systemctl status shows the following:

root@linux:~# systemctl -l status vboxautostart-service.service
● vboxautostart-service.service
   Loaded: loaded (/usr/lib/virtualbox/vboxautostart-service.sh; enabled; vendor preset: enabled)
   Active: inactive (dead) since Sa 2015-10-31 16:39:10 CET; 4min 57s ago
  Process: 5645 ExecStop=/usr/lib/virtualbox/vboxautostart-service.sh stop (code=exited, status=0/SUCCESS)
  Process: 5586 ExecStart=/usr/lib/virtualbox/vboxautostart-service.sh start (code=exited, status=0/SUCCESS)
   CGroup: /system.slice/vboxautostart-service.service
           ├─ 875 /usr/lib/virtualbox/VBoxXPCOMIPCD
           ├─ 880 /usr/lib/virtualbox/VBoxSVC --auto-shutdown
           └─5602 /usr/lib/virtualbox/VBoxHeadless --comment server --startvm b3376916-8562-442e-a25e-cfe26fa800db --vrde config

Okt 31 16:37:52 linux systemd[1]: Starting vboxautostart-service.service...
Okt 31 16:37:52 linux vboxautostart-service.sh[5586]: Starting VirtualBox VMs configured for autostart
Okt 31 16:37:52 linux systemd[1]: Started vboxautostart-service.service.
Okt 31 16:39:10 linux systemd[1]: Stopping vboxautostart-service.service...
Okt 31 16:39:10 linux systemd[1]: Stopped vboxautostart-service.service.

The ExecStop command in the service looks quite right, however, for some reason it is not working, when called from systemd. Any idea what I can do here?

Best Answer

Looks like I'm having the same problem on debian jessie with systemd and virtualbox 5.0.10 packaged from Oracle.

After lot of debugging there seams to be something related to the way the start-stop-daemon is called in the stop() function in /usr/lib/virtualbox/vboxautostart-service.sh (around line 236) which does not triggers for the start() function in the same way

What I came up with is an horrible hack but really would like someone more systemd friendly to dig into this issue.

I replaced in /usr/lib/virtualbox/vboxautostart-service.sh :

for user in `ls $VBOXAUTOSTART_DB/*.stop` 
do
    start_daemon `basename $user | sed -ne "s/\(.*\).stop/\1/p"` $binary $PARAMS > /dev/null 2>&1
done

with :

for user in `ls $VBOXAUTOSTART_DB/*.stop`
do
    su - `basename $user | sed -ne "s/\(.*\).stop/\1/p"` -c "$binary $PARAMS" > /dev/null 2>&1
done
Related Question