I’m running stand-alone web apps on OS X, and I have a logging scheme which logs App.Unhandled Exception, so I can tell why it died. But I’m curious if there’s an elegant way to relaunch the web app when this happens?
I currently have a bash shell script which launches my app (after killing any existing instances) which looks like this:
I suppose I could just have a command in UnhandledException which opens a Shell and executes this script again?
#!/bin/bash
##################################################
# Script to launch a Xojo webapp
##################################################
# note:
# uses command-line parameters for additions options
# see http://www.xojo.com/blog/en/2014/01/web-standalone-ssl.php
##################################################
# kill any running apps
echo '##################################################'
echo '# Killing running apps (if any)'
echo '##################################################'
killall MyApp
echo '# Launching apps'
echo '##################################################'
# launch uploader for class(es) being taught.
cd "/path/to/my/webapp"
./MyApp --logging --secureport=8402 & # launch in background using SSL on port 8402
If you launch your app with launchd (OS X init system) then you can specify a “keepalive” key in the config and then the system will relaunch your app automatically if it crashes/quits. Just an option to consider since it is already built-in.
I use launchd on OS X and it’s worked great for me. I can’t remember the last time I had to touch a stand alone web app that was running from launchd. Usually I setup haproxy under launchd as well and at least two instances of my web app behind that. Works like a charm and spins like a top.