The script is in /etc/init.d:
#!/bin/bash
VMUSER=myname
CURRDATE=(`date +"%m-%d-%Y"` + `date +"%H:%M:%S"`)
CURRTIME=(`date +"%X"`)
FILE=/home/myname/log/vm-services.log
VBPATH=/usr/bin
start(){
echo "Starting VM Guest"
echo "Starting VM Services on $CURRDATE at $CURRTIME" >> $FILE
sudo -u $VMUSER $VBPATH/VBoxManage startvm sherbet --type headless
}
stop(){
echo "Stopping VM Guest"
echo "Stopping VM Services on $CURRDATE at $CURRTIME" >> $FILE
sudo -u $VMUSER $VBPATH/VBoxManage controlvm sherbet savestate
}
restart(){
echo "Restart"
echo "Restarted on $CURRDATE at $CURRTIME" >> $FILE
}
case "$1" in
start)
echo "In Start" >> $FILE
start
;;
stop)
stop
;;
restart)
restart
;;
*)
echo "Usage: vm-service {start|stop}"
exit 1
esac
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:
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.
sudo update-rc.d vm-services defaults 99 01
a bit and changing the99
to a lower value. Try01
, 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 .