The script is in /etc/init.d:


CURRDATE=(`date +"%m-%d-%Y"` + `date +"%H:%M:%S"`)
CURRTIME=(`date +"%X"`)


   echo "Starting VM Guest"
   echo "Starting VM Services on $CURRDATE at $CURRTIME" >> $FILE
   sudo -u $VMUSER $VBPATH/VBoxManage startvm sherbet --type headless


   echo "Stopping VM Guest"
   echo "Stopping VM Services on $CURRDATE at $CURRTIME" >> $FILE
   sudo -u $VMUSER $VBPATH/VBoxManage controlvm sherbet savestate

   echo "Restart"
   echo "Restarted on $CURRDATE at $CURRTIME" >> $FILE

case "$1" in
   echo "In Start" >> $FILE
    echo "Usage: vm-service {start|stop}"
    exit 1

When I reboot the script stop is called. But Ubuntu restarts the start is never called. The script seems to have the correct execute settings:

enter image description here

The echo for shutdown is working cause I see the entry.
I installed the script as follows:

=> sudo update-rc.d vm-services defaults 99 01

I can manually start/stop with no problems: =>/etc/init.d/vm-services start =>/etc/init.d/vm-services stop

Any advise would be appreciated

Update 8/19/2014 - 1:24PMI modified the script above now includes VBPATH that points to the VBoxManage path. But it doesnt work. The stop is always called when it reboots but the start never gets hit. Just sending the string to the file doesnt get hit. On reboot it does it everytime.

  • I suggest playing around with the line sudo update-rc.d vm-services defaults 99 01 a bit and changing the 99 to a lower value. Try 01, and see if that works. If it still doesn't, then try just setting your script to start and stop at certain run-levels rather than all of them. E.g. update-rc.d vm-services start 99 3 . stop 01 0 1 6 .
    – Warwick
    Aug 20, 2014 at 7:04

2 Answers 2


OK the problem was because i checked off when i installed to have my home directory encrypted. So when I put the debug option in my script:

~/bin/bash -x

I noticed that when the script tried to run it was saying that the home folder could not be decrypted. So I went ahead and removed the encryption for home folders and restarted the computer and everything works now. The process for removing encryption is several steps that can be found here


I'd be looking at putting a specific assignment to PATH environment variable so that you are assured that the startup script is getting the binaries from the right location. In this case, it could be that the startup environment may not contain the appropriate path the a program you need to execute.

  • I modified my code above to include the path but the start is just not being called. The stop always gets called cause I can see the log from the echo. But the start never logs the echo. And that is called before running the VBoxManage
    – adviner
    Aug 19, 2014 at 20:28

You must log in to answer this question.

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