You are not logged in.

#1 2011-09-04 00:54:32

thiago
Member
Registered: 2010-09-10
Posts: 8

[SOLVED] I need a simple way to start/stop a virtualbox vm

Hi,

  I need a very simple way to start a headless virtualbox vm on login, and cleanly save its state on system shutdown/reboot. I can't use solutions like vboxtool because my home directory is encrypted and only available after I login.

  I have written a simple script to do what I need:

#!/bin/bash

if VBoxManage startvm --type headless archdev > /dev/null 2>&1; then
	trap "VBoxManage controlvm archdev savestate > /dev/null 2>&1; exit" SIGINT SIGTERM
	while true;  
	do 
		sleep 10h
	done
fi

  When I run this script in a interactive shell, all works as expected: It will successfully start the vm(archdev), and when I send SIGINT (using CTRL+C)  it will cleanly save the vm state. The problem I'm facing is that when I start this script as a background process(sufix it with a '&') it will successfully start, but it will fail to cleanly save state on shutdown, since it seems to  ignore signals send using 'kill' command(unless it is a SIGKILL). I highly appreciate an solution to this problem, by either explaining to me what is happening, or by providing an alternate one(as long it doesn't involve starting the vm with the system).

  Thanks in advance.

Last edited by thiago (2011-09-04 14:54:44)

Offline

#2 2011-09-04 01:01:12

cybertorture
Member
Registered: 2010-05-05
Posts: 339

Re: [SOLVED] I need a simple way to start/stop a virtualbox vm

vboxmanage startvm --type headless VMNAME

put this to start at login

su -c 'vboxmanage controlvm VMNAME savestate' USERNAME

put this to /etc/rc.local.shutdown


O' rly ? Ya rly Oo

Offline

#3 2011-09-04 01:13:03

thiago
Member
Registered: 2010-09-10
Posts: 8

Re: [SOLVED] I need a simple way to start/stop a virtualbox vm

cybertorture wrote:
vboxmanage startvm --type headless VMNAME

put this to start at login

su -c 'vboxmanage controlvm VMNAME savestate' USERNAME

put this to /etc/rc.local.shutdown

Worked like a charm, thanks.

Offline

#4 2011-09-04 03:41:56

cybertorture
Member
Registered: 2010-05-05
Posts: 339

Re: [SOLVED] I need a simple way to start/stop a virtualbox vm

No problem, i m plesed to hear it suits you. Just a reminder to put [solved], before moderators do it big_smile


O' rly ? Ya rly Oo

Offline

#5 2011-09-04 03:50:13

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,926

Re: [SOLVED] I need a simple way to start/stop a virtualbox vm

cybertorture wrote:

No problem, i m plesed to hear it suits you. Just a reminder to put [solved], before moderators do it big_smile

Hey!


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

Board footer

Powered by FluxBB