Loading...
Logo
Processing Forum
Hello 

I was just gathering some code snippets for a script that will watch if a certain application is running and will automatically restart it in case of a crash or if the user is quitting it.
This might me useful if you show a processing app in an exhibition.
Of course there should be no bugs and it shouldn't crash, but you never know for sure ;-)

All you need is a launcher.plist...
Copy code
  1. <dict>
  2.        <string>com.restart.launcher</string>
  3.       <key>Program</key>
  4.       <string> /Applications/Opera.app/Contents/MacOS/Opera</string>
  5.       <key>KeepAlive</key>
  6.       <true/>
  7.       <key>RunAtLoad</key>
  8.       <false/>
  9. </dict/>

and a terminal command to start it.
Copy code
  1. launchctl load "${0%/*}/com.restart.launcher.plist"
This works well. There is only one problem.
The file of the application to be watched is in the package contents: Contents > MacOS
Processing Applications don't have that file in the package content or rather an file called "JavaApplicationStub".
Unfortunately it doesn't work with this file.

Any suggestions? 

I know that there is a App called  Lingon that may do the job but my script also does a bunch of other stuff that Lingon won't.

Replies(3)

Hey Broenni,
I am in need of such a smart cron-job as well.
Something that restarts an app, once it crashes.

I found the location of JavaApplicationStub via this blog post

Copy code
  1. <dict>
  2.       <key>Label</key>
  3.       <string>com.restart.launcher</string>
  4.       <key>Program</key>
  5.       <string>/Users/USERNAME/Documents/Processing/APPLICATIONFOLDER/application.macosx/APPLICATIONNAME.app/Contents/MacOS/JavaApplicationStub</string>
  6.       <key>KeepAlive</key>
  7.       <true/>
  8.       <key>RunAtLoad</key>
  9.       <false/>
  10. </dict>

When i launch the plist through the terminal, it starts my application. 


Launch via Terminal (in location of  com.restart.launcher.plist file)
Copy code
  1. launchctl load com.restart.launcher.plist
Unlaunch via Terminal
Copy code
  1. launchctl unload com.restart.launcher.plist

When i kill my application on purpose (hit escape), it automatically restarts. So far so good. Yet, if my application crashes and freezes, nothing happens. I've put in a test-crash into my application, that leads to an IndexOutOfBounds Exception crash. When i trigger this, the application freezes and remains frozen. 

Any idea how launchctl would recognize that the application is frozen instead of just not-running?

Eva


Hi Eva

Thanks for that JavaApplicationStub hint. Nice that this works.
I don't yet have a solution for the freeze issue. But I'm interested in that too and constantly looking for solutions.



You can have a look at SIKULI  http://sikuli.org/ and write a script that watch if your app is running/freezing/crashing and restart it

http://makio.free.fr/