VMware Communities
dav0101
Contributor
Contributor

Howto make vmrun blocking (for use with KeepAlive in launchd)

Hi,

1)

Any ideas how to force vmrun to not return and keep running in the background.

Problem is when using launchd and keepalive (for detecting and restarting if vmware crashes), it needs the executable not to daemonize itself.

2)

Also wonder if there is a trick to suspend/quit vmware and the running instance nicely when shutting down a Mac OS X system.

I want to make sure the equivalent to vmrun suspend is executed when the system signal for shutdown

    i.e..

    signal.suspendOnHUP = "TRUE"
    signal.powerOffOnTERM = "TRUE"
Tags (1)
Reply
0 Kudos
11 Replies
WoodyZ
Immortal
Immortal

Archive an attach a copy of the .plist file.

Reply
0 Kudos
dav0101
Contributor
Contributor

<plist version="1.0">

<dict>

<key>Label</key>
<string>launchd_vmware</string>
<key>ProgramArguments</key>
<array>
<string>/Library/Application Support/VMware Fusion/vmrun</string>
<string>-T</string>
<string>fusion</string>
<string>start</string>
<string>/Users/foo/Documents/Virtual Machines/Win7.vmwarevm/Win7.vmx</string>
<string>nogui</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>KeepAlive</key>
<false/> <!-- note have this false for now... ->
</dict>
</plist>


Reply
0 Kudos
WoodyZ
Immortal
Immortal

What did you not understand about "Archive an attach a copy of the .plist file."?  I DID NOT ask you to copy and paste the contents of the file into the body of a reply!

Reply
0 Kudos
dav0101
Contributor
Contributor

Sorry about that, attached is the file itself.

Reply
0 Kudos
WoodyZ
Immortal
Immortal

Give the one I've attached a try and you'll need to edit it in two places to remove the value foo and put the correct ${USER} value in its place.

Reply
0 Kudos
dav0101
Contributor
Contributor

I checked your version, if I'm not wrong, it's function is identical to the one I sent.

QueueDirectories and WatchPaths is added but both have empty lists.

UserName is already "my user" since I run it from ~/Library/LaunchAgents
What I'm after is how to utilize launchd's nifty KeepAlive flag (which I've by purpose set to false currently).
Problem by using vmrun is that it needs to block until the vmware application is closed, otherwise launchd can't be used together with KeepAlive.
Reply
0 Kudos
WoodyZ
Immortal
Immortal

UserName is already "my user" since I run it from ~/Library/LaunchAgents
What I'm after is how to utilize launchd's nifty KeepAlive flag (which I've by purpose set to false currently).
Problem by using vmrun is that it needs to block until the vmware application is closed, otherwise launchd can't be used together with KeepAlive.

You can remove QueueDirectories and WatchPaths keys if you want however keep the UserName key and the .plist file needs to be placed in the /Library/LaunchDaemons/ folder owned by root if you want to keep it alive!

rw-r--r--  root  wheel

Also I have the answer for your number two question and will post it a bit later when I get the time.

Reply
0 Kudos
dav0101
Contributor
Contributor

awesome, I will try that. so basically when running vmrun as root, it wont return immediately?

looking forward to input on question 2. seems to be a hot topic around the web, but no real answers.

Reply
0 Kudos
WoodyZ
Immortal
Immortal

awesome, I will try that. so basically when running vmrun as root, it wont return immediately?

If the KeepAlive key is set to false and run as I mentioned then it will not return immediately.

looking forward to input on question 2. seems to be a hot topic around the web, but no real answers.

I working on it now and should be to much longer.

Reply
0 Kudos
WoodyZ
Immortal
Immortal

2) Also wonder if there is a trick to suspend/quit vmware and the running instance nicely when shutting down a Mac OS X system.

Have a look at: Running a VM Headless (no GUI) and Controlling Shutdown/Suspend with Mac OS X Reboot/Shutdown

Reply
0 Kudos
dav0101
Contributor
Contributor

Thanks alot Woody!

I agree that it's so strange launchd doesn't have the feature of the old StartupItem to enable an easy way to gracefully quit apps during system shutdown/reboot...

Reply
0 Kudos