Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.5: Automatically restart a crashed program' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.5: Automatically restart a crashed program
Authored by: mark hunte on Dec 19, '07 05:33:17PM

Now I am not going to even suggest I am an expert,
SuccessfulExit sound like what we are looking for, but Does it work.
I have tried the SuccessfulExit key true and false, with and without KeepAlive true. It does not work
So please show us how you would do it, ( keeping the app running when it crashes but letting it stay quit when you quit it.)

---
mh



[ Reply to This | # ]
10.5: Automatically restart a crashed program
Authored by: macavenger on Dec 20, '07 09:38:54AM
I have tried the SuccessfulExit key true and false, with and without KeepAlive true. It does not work So please show us how you would do it, ( keeping the app running when it crashes but letting it stay quit when you quit it.)
The key here is that KeepAlive can be either a bool OR a dict- in this case we need it to be a dict, with the SuccessfulExit key as a child bool set to false. So, using my company's flight management software as an example, you would end up with the following LaunchAgent .plist file (I put it in my home library/LaunchAgents folder):
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>KeepAlive</key>
	<dict>
		<key>SuccessfulExit</key>
		<false/>
	</dict>
	<key>Label</key>
	<string>com.frontierflying.flightmaster</string>
	<key>ProgramArguments</key>
	<array>
		<string>/Users/Shared/FlightMasterStandalone/FlightMaster2004.app/Contents/MacOS/EXE</string>
	</array>
</dict>
</plist>
I made the inital file using Lingon, and then simply edited it to add the KeepAlive dict/key set. The program arguments string needs to be the path to the actual executable inside the app bundle, not just to the .app (assuming it is a bundle app) as shown.

Of course, this loads immediately at login. If this is the desired behavior, then you are done. If you don't want this, then put the .plist file in your documents directory or something, and use something like the following two line script to load it as desired:

launchctl unload /path/to/launchagent.plist
launchctl load /path/to/launchagent.plst
The unload command is needed only if you want to launch the application multiple times in a session. From what I can tell, once loaded the LaunchAgent remains loaded, and simply stops monitoring the app after it quits cleanly- but doesn't unload. In order to relaunch the app, you first have to unload the LaunchAgent, the load it again, thus the first line of the script. That script should be able to be put into an apple script using the "do shell script" apple script command if you want (although I didn't test this), or just leave it as a terminal script. Then just run that script, and launchd will launch your application, monitor it, and restart it if it crashes, but not if it exits cleanly. Perhaps in the end this isn't all that much simpler than your method, but it feels cleaner to me.

---
Aluminum iMac 20" 2.4 GHz/3GB/300GB HD

[ Reply to This | # ]

10.5: Automatically restart a crashed program
Authored by: mark hunte on Dec 20, '07 12:50:54PM

Thanks for explaining all that macavenger, I will check it out.

---
mh



[ Reply to This | # ]