Autostart Virtual Machine VBoxHeadless at boot with Upstart - init and Graceful exit












2














I want to automatically start a VirtualBox Virtual Machine at boot on a Ubuntu 14 Linux Headless Server.



I have tried @reboot via crontab, but the VboxHeadless command does not seem to work in conjunction with @reboot. I think its a timing issue.



So I have researched more and was guided to make a Upstart Script. How can I go about this?










share|improve this question
























  • @reboot trail and error and failing post just for reference
    – FreeSoftwareServers
    Oct 24 '15 at 2:41
















2














I want to automatically start a VirtualBox Virtual Machine at boot on a Ubuntu 14 Linux Headless Server.



I have tried @reboot via crontab, but the VboxHeadless command does not seem to work in conjunction with @reboot. I think its a timing issue.



So I have researched more and was guided to make a Upstart Script. How can I go about this?










share|improve this question
























  • @reboot trail and error and failing post just for reference
    – FreeSoftwareServers
    Oct 24 '15 at 2:41














2












2








2


4





I want to automatically start a VirtualBox Virtual Machine at boot on a Ubuntu 14 Linux Headless Server.



I have tried @reboot via crontab, but the VboxHeadless command does not seem to work in conjunction with @reboot. I think its a timing issue.



So I have researched more and was guided to make a Upstart Script. How can I go about this?










share|improve this question















I want to automatically start a VirtualBox Virtual Machine at boot on a Ubuntu 14 Linux Headless Server.



I have tried @reboot via crontab, but the VboxHeadless command does not seem to work in conjunction with @reboot. I think its a timing issue.



So I have researched more and was guided to make a Upstart Script. How can I go about this?







virtualbox sysvinit upstart






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 51 secs ago

























asked Oct 24 '15 at 2:36









FreeSoftwareServers

98331836




98331836












  • @reboot trail and error and failing post just for reference
    – FreeSoftwareServers
    Oct 24 '15 at 2:41


















  • @reboot trail and error and failing post just for reference
    – FreeSoftwareServers
    Oct 24 '15 at 2:41
















@reboot trail and error and failing post just for reference
– FreeSoftwareServers
Oct 24 '15 at 2:41




@reboot trail and error and failing post just for reference
– FreeSoftwareServers
Oct 24 '15 at 2:41










1 Answer
1






active

oldest

votes


















5














Create Script >> Make it executable >> "Install" script via update-rc.d



cat << 'EOL' >/etc/init.d/StartVM
#!/bin/sh

#Edit these variables!
VMUSER=user
VMNAME=VM1
VMNAME2=Test

case "$1" in
start)
echo "Starting VirtualBox VM ..."
sudo -u $VMUSER VBoxHeadless --startvm $VMNAME &
sudo -u $VMUSER VBoxHeadless --startvm $VMNAME2 &
;;
stop)
echo "Saving state of Virtualbox VM ..."
sudo -u $VMUSER VBoxManage controlvm $VMNAME savestate
sudo -u $VMUSER VBoxManage controlvm $VMNAME2 acpipowerbutton
;;
*)
echo "Usage: /etc/init.d/StartVM {start|stop}"
exit 1
;;
esac

exit 0
EOL
sudo chmod +x /etc/init.d/StartVM
sudo update-rc.d StartVM defaults





share|improve this answer























  • Original Thread, slightly changed and picked best answer IMO, just giving credit here
    – FreeSoftwareServers
    Oct 24 '15 at 2:41










  • This is with Ubuntu Server 14.04 x64 and Vbox 5.*
    – FreeSoftwareServers
    Oct 24 '15 at 2:42











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f238287%2fautostart-virtual-machine-vboxheadless-at-boot-with-upstart-init-and-graceful%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














Create Script >> Make it executable >> "Install" script via update-rc.d



cat << 'EOL' >/etc/init.d/StartVM
#!/bin/sh

#Edit these variables!
VMUSER=user
VMNAME=VM1
VMNAME2=Test

case "$1" in
start)
echo "Starting VirtualBox VM ..."
sudo -u $VMUSER VBoxHeadless --startvm $VMNAME &
sudo -u $VMUSER VBoxHeadless --startvm $VMNAME2 &
;;
stop)
echo "Saving state of Virtualbox VM ..."
sudo -u $VMUSER VBoxManage controlvm $VMNAME savestate
sudo -u $VMUSER VBoxManage controlvm $VMNAME2 acpipowerbutton
;;
*)
echo "Usage: /etc/init.d/StartVM {start|stop}"
exit 1
;;
esac

exit 0
EOL
sudo chmod +x /etc/init.d/StartVM
sudo update-rc.d StartVM defaults





share|improve this answer























  • Original Thread, slightly changed and picked best answer IMO, just giving credit here
    – FreeSoftwareServers
    Oct 24 '15 at 2:41










  • This is with Ubuntu Server 14.04 x64 and Vbox 5.*
    – FreeSoftwareServers
    Oct 24 '15 at 2:42
















5














Create Script >> Make it executable >> "Install" script via update-rc.d



cat << 'EOL' >/etc/init.d/StartVM
#!/bin/sh

#Edit these variables!
VMUSER=user
VMNAME=VM1
VMNAME2=Test

case "$1" in
start)
echo "Starting VirtualBox VM ..."
sudo -u $VMUSER VBoxHeadless --startvm $VMNAME &
sudo -u $VMUSER VBoxHeadless --startvm $VMNAME2 &
;;
stop)
echo "Saving state of Virtualbox VM ..."
sudo -u $VMUSER VBoxManage controlvm $VMNAME savestate
sudo -u $VMUSER VBoxManage controlvm $VMNAME2 acpipowerbutton
;;
*)
echo "Usage: /etc/init.d/StartVM {start|stop}"
exit 1
;;
esac

exit 0
EOL
sudo chmod +x /etc/init.d/StartVM
sudo update-rc.d StartVM defaults





share|improve this answer























  • Original Thread, slightly changed and picked best answer IMO, just giving credit here
    – FreeSoftwareServers
    Oct 24 '15 at 2:41










  • This is with Ubuntu Server 14.04 x64 and Vbox 5.*
    – FreeSoftwareServers
    Oct 24 '15 at 2:42














5












5








5






Create Script >> Make it executable >> "Install" script via update-rc.d



cat << 'EOL' >/etc/init.d/StartVM
#!/bin/sh

#Edit these variables!
VMUSER=user
VMNAME=VM1
VMNAME2=Test

case "$1" in
start)
echo "Starting VirtualBox VM ..."
sudo -u $VMUSER VBoxHeadless --startvm $VMNAME &
sudo -u $VMUSER VBoxHeadless --startvm $VMNAME2 &
;;
stop)
echo "Saving state of Virtualbox VM ..."
sudo -u $VMUSER VBoxManage controlvm $VMNAME savestate
sudo -u $VMUSER VBoxManage controlvm $VMNAME2 acpipowerbutton
;;
*)
echo "Usage: /etc/init.d/StartVM {start|stop}"
exit 1
;;
esac

exit 0
EOL
sudo chmod +x /etc/init.d/StartVM
sudo update-rc.d StartVM defaults





share|improve this answer














Create Script >> Make it executable >> "Install" script via update-rc.d



cat << 'EOL' >/etc/init.d/StartVM
#!/bin/sh

#Edit these variables!
VMUSER=user
VMNAME=VM1
VMNAME2=Test

case "$1" in
start)
echo "Starting VirtualBox VM ..."
sudo -u $VMUSER VBoxHeadless --startvm $VMNAME &
sudo -u $VMUSER VBoxHeadless --startvm $VMNAME2 &
;;
stop)
echo "Saving state of Virtualbox VM ..."
sudo -u $VMUSER VBoxManage controlvm $VMNAME savestate
sudo -u $VMUSER VBoxManage controlvm $VMNAME2 acpipowerbutton
;;
*)
echo "Usage: /etc/init.d/StartVM {start|stop}"
exit 1
;;
esac

exit 0
EOL
sudo chmod +x /etc/init.d/StartVM
sudo update-rc.d StartVM defaults






share|improve this answer














share|improve this answer



share|improve this answer








edited 2 mins ago

























answered Oct 24 '15 at 2:37









FreeSoftwareServers

98331836




98331836












  • Original Thread, slightly changed and picked best answer IMO, just giving credit here
    – FreeSoftwareServers
    Oct 24 '15 at 2:41










  • This is with Ubuntu Server 14.04 x64 and Vbox 5.*
    – FreeSoftwareServers
    Oct 24 '15 at 2:42


















  • Original Thread, slightly changed and picked best answer IMO, just giving credit here
    – FreeSoftwareServers
    Oct 24 '15 at 2:41










  • This is with Ubuntu Server 14.04 x64 and Vbox 5.*
    – FreeSoftwareServers
    Oct 24 '15 at 2:42
















Original Thread, slightly changed and picked best answer IMO, just giving credit here
– FreeSoftwareServers
Oct 24 '15 at 2:41




Original Thread, slightly changed and picked best answer IMO, just giving credit here
– FreeSoftwareServers
Oct 24 '15 at 2:41












This is with Ubuntu Server 14.04 x64 and Vbox 5.*
– FreeSoftwareServers
Oct 24 '15 at 2:42




This is with Ubuntu Server 14.04 x64 and Vbox 5.*
– FreeSoftwareServers
Oct 24 '15 at 2:42


















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f238287%2fautostart-virtual-machine-vboxheadless-at-boot-with-upstart-init-and-graceful%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Accessing regular linux commands in Huawei's Dopra Linux

Can't connect RFCOMM socket: Host is down

Kernel panic - not syncing: Fatal Exception in Interrupt