running VBox on OS X Server

Discussions related to using VirtualBox on Mac OS X hosts.
wyrdR
Posts: 36
Joined: 9. Aug 2009, 15:15
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Windows 7,Xubuntu,Mac OS X server

Re: running VBox on OS X Server

Post by wyrdR »

SlaunchaMan wrote:
borgo1971 wrote:there's no way to start a script on Mac OS X shutdown.
Re-read the portion of the launchd.plist man page that talks about this. Launchd sends the SIGTERM signal to processes on shutdown. To run something on shutdown, catch that signal.
I got this working on Mac OS X Snow Leopard server running on an Xserve.

For more info see VBox Daemon for Mac OS X:
http://forums.virtualbox.org/viewtopic.php?f=8&t=32332
borgo1971
Posts: 24
Joined: 11. Feb 2009, 18:32
Primary OS: Mac OS X Leopard
VBox Version: PUEL
Guest OSses: Windows Server 2003
Location: Italy

Re: running VBox on OS X Server

Post by borgo1971 »

wyrdR wrote:I got this working on Mac OS X Snow Leopard server running on an Xserve.

For more info see VBox Daemon for Mac OS X:
http://forums.virtualbox.org/viewtopic.php?f=8&t=32332
Thanks, I'll try later if your suggestion can be useful for my VM's (running on MacPro with Mac OS X 10.5 Server). Shutting down the server is our biggest problem at this time (none if not I, will shutdown VM's properly if needed).
I'll ask some other thing:
have you found a way automatically to shutdown VM at host shutdown?
did you never experience VM freezes or accidental network problems?
wyrdR
Posts: 36
Joined: 9. Aug 2009, 15:15
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Windows 7,Xubuntu,Mac OS X server

Re: running VBox on OS X Server

Post by wyrdR »

I'll ask some other thing:
have you found a way automatically to shutdown VM at host shutdown?
yes.
did you never experience VM freezes or accidental network problems?
no. not yet anyway.

Running Mac OS X Server 10.6.4 & 3.2.6 Beta 1 on an xServe - Guest: Mac OS X Server 10.6.4

I can use poweroff (like pulling out the plug) and savestate (saves current state). Still working on acpipowerbutton (Not sure if this is supported on Mac OS X guests or guests without guest additions)
borgo1971
Posts: 24
Joined: 11. Feb 2009, 18:32
Primary OS: Mac OS X Leopard
VBox Version: PUEL
Guest OSses: Windows Server 2003
Location: Italy

Re: running VBox on OS X Server

Post by borgo1971 »

wyrdR wrote:I can use poweroff (like pulling out the plug)
this isn't really usefull... i think it's not much different as shutdown the server with running VM's
wyrdR wrote:and savestate (saves current state). Still working on acpipowerbutton (Not sure if this is supported on Mac OS X guests or guests without guest additions)
OK, but how do you think to launch commands on Mac OS shutdown? I've made an applescript to shutdown the server (that usese savestate), but mostly, If I'm not in office and server need to be shutted down, my collegue shut it down without using the script (it's on desktop, called "launch this to shutdown") :(
And yes, acpipowerbutton should be better, but I haven't found how make it work with Windows Server 2003 guest
wyrdR
Posts: 36
Joined: 9. Aug 2009, 15:15
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Windows 7,Xubuntu,Mac OS X server

Re: running VBox on OS X Server

Post by wyrdR »

borgo1971 wrote:
wyrdR wrote:I can use poweroff (like pulling out the plug)
this isn't really usefull... i think it's not much different as shutdown the server with running VM's
wyrdR wrote:and savestate (saves current state). Still working on acpipowerbutton (Not sure if this is supported on Mac OS X guests or guests without guest additions)
acpishutdown might never work for a server: Read is there a command line ACPI shutdown for more info.
OK, but how do you think to launch commands on Mac OS shutdown? I've made an applescript to shutdown the server (that usese savestate), but mostly, If I'm not in office and server need to be shutted down, my collegue shut it down without using the script (it's on desktop, called "launch this to shutdown") :(
And yes, acpipowerbutton should be better, but I haven't found how make it work with Windows Server 2003 guest
As in this topic, you need to to run VBox as a Headless process as a LaunchDaemon. Everything you need is here: VBox Daemon for Mac OS X. The only thing you'll need to do is edit vbox.sh so it calls savestate. This is good enough for me.

The only issue is that, while it neatly stops the VM running, it's not really shut down but in a state of suspended animation. The next time you turn it back on, the VM is like, "where did the time go?" but then updates its clock and picks up where it left off.

If you literally want it to shutdown you'll need to use shutdown or pshutdown – perhaps leveraging Wine on MacOSX or by getting SSH listening on the Windows VM. I'm not running a Windows servers VM just now, so I won't be testing this right away.

Give it a shot and let us know :)
wyrdR
Posts: 36
Joined: 9. Aug 2009, 15:15
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Windows 7,Xubuntu,Mac OS X server

Re: running VBox on OS X Server

Post by wyrdR »

OK, but how do you think to launch commands on Mac OS shutdown? I've made an applescript to shutdown the server (that usese savestate), but mostly, If I'm not in office and server need to be shutted down, my collegue shut it down without using the script (it's on desktop, called "launch this to shutdown") :(
And yes, acpipowerbutton should be better, but I haven't found how make it work with Windows Server 2003 guest
PS – Found this. The same commands work in Mac OS X terminal:
How To Remotely Shut Down Windows XP Computers From A Linux Server

Code: Select all

net rpc shutdown -t 10 -f -C "Message..." -W domainname -U "name"%password -I xxx.xxx.xxx.xxx

Code: Select all

net rpc shutdown -t 10 -f -C "Message..." -W domainname -U "name"%password -S hostname
OR - for 3.2.x onwards: VBoxManage guestcontrol*

Code: Select all

VBoxManage guestcontrol execute "vmname" "c:\\windows\\system32\\shutdown.exe" --arguments "-f -p" --username name --password password --wait-for stdout --timeout 3000 
* guestcontrol is currently supported only by Windows Guests running Guest Additions.

Notes:
xxx.xxx.xxx.xxx = IP address
domainname = either the AD Domain Name OR the computername if authentication with a local account.

Modifying the vbox.sh script:

Code: Select all

    
#!/bin/bash

#Shutdown a Windows Guest

#   Expects VM name to be passed as parameter

    trap shutdown SIGTERM

   windowsuser=winadmin
   windowspass=anunencryptedpassword

    function displayhelp()
    {   
   echo
   echo Usage:
   echo
   echo -e $0 vmname\|'\x22'vmname \(long name\)'\x22'   
   echo -e   '\t'Starts VM named '\x22'vmname'\x22' \(use quotes to enclose names with spaces\)
   echo
   echo -e $0 -o\|--off vmname\|'\x22'vmname \(long name\)'\x22'
   echo -e '\t'Powers off VM named '\x22'vmname'\x22' \(use quotes to enclose names with spaces\)
   echo  
    }

    function shutdown()
    {
      echo `date` "Received SIGTERM, powering off VBox: $VM"
     
      ## UNCOMMENT WHERE APPROPRIATE ##

      #For any Guest:
      #/usr/bin/VBoxManage controlvm $VM savestate 

     #For Windows Guests with RPC service contactable from Host:
      #net rpc shutdown -t 10 -f -C "VBoxDaemon is shutting down" -W $VM -U "$windowsuser"%$windowspass -S $VM
     
     #In Virtual Box 3.2.x or greater for Windows guests running Guest Additions:
     VBoxManage guestcontrol execute "$VM" "c:\\windows\\system32\\shutdown.exe" --arguments "-f -p" --username $windowsuser --password $windowspass --wait-for stdout --timeout 3000 

      echo `date` "Shutting Down VBox: $VM"
      echo
      exit 0
    }



    function startup()
    {
   echo `date`'' "Starting VBox: $VM" 
   /usr/bin/VBoxHeadless --startvm $VM &
   echo `date`   Running VBox: $VM
   echo
   wait $!
   echo `date` Daemon exited: $0 $1 $2
    }
echo 
echo `date` Daemon launched: $0 $1 $2

   case $2 in
   -o|--off) VM=$2; shutdown $VM;;
   esac

   case $1 in
   -o|--off) VM=$2; shutdown $VM;;
   -h|--help) displayhelp;;
        *) VM=$1; echo VM: $VM; startup $VM;;   
   esac
Note: In the above, I assume that the hostname is the same as the VM's name. If not, you'll have to re-write the script to suit.

PS: 2011-04-07 - SSH is a good all round option. You can install SSH on Windows, and any OSX Server guest will be listening too. I have a trick to avoid hardcoding SSH passwords but I did it a while ago and have to retrace my steps. Will post back when I have time.
Post Reply