We’ve been transitioning from FileMaker to Xojo and getting close to having our first converted Web App in the hands of our client. While I have been running a demo for the client on one of our Mac Mini’s I haven’t seen the Xojo Web Apps crash. With FileMaker Server, we have to reboot it to get it working again when it silently stalls.
Does anyone see their Xojo Web Apps crash?
I was thinking of running Keyboard Maestro to monitor the Xojo Web App to let me know if the Web App crashes:
This is a job for a shell script, saved as a .command file. Here’s an example, which shows some handy features, such as killing off the existing webApp (if any) and also options for better logging and TLS support:
#!/bin/bash
##################################################
# Script to launch one or more Xojo webapps
##################################################
# 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 NameOfMyXojoWebApp
echo '# Launching apps'
echo '##################################################'
# launch it
cd "/Volumes/Server/MyApps"
./MyAppFolder/NameOfMyXojoWebApp --logging --secureport=8403 & # launch in background with a weird port number
echo '# Processes'
ps | grep NameOfMyXojoWebApp | grep -v grep
echo '##################################################'
echo "App is running. To terminate it, run the command 'killall NameOfMyXojoWebApp'"
You could also add some fancy stuff to loop forever, count the number of running processes by that name, and re-launch the app if it ever dies:
### watch for a webApp dying and re-launch it if needed
while true
do
echo `date`
echo '# Sleeping for 1 minutes'
sleep 60
numprocesses =`ps | grep NameOfMyXojoWebApp | grep -v grep | wc -l`
if [[ $numprocesses -gt 0 ]] ; then
echo "found $numprocesses apps running"
else
echo "App crashed, relaunching"
./MyAppFolder/NameOfMyXojoWebApp --logging --secureport=8403 & # launch in background with a weird port number
fi
done
this is a job for a launchd script and precisely what that is meant for
way simpler to write
about the only thing you need is the identifier & the keep alive key and launchd will restart your app when / if it crashes
I have web apps that occasionally throw an internal server error.
These are stand alone cgi. Most are various forms for our Membership App, Renewal, and a host of other things. When the user gets that error, the app is still in memory and can’t be launched until it is killed.
I don’t suppose there is any way a script can detect when an app throws the Internal Server error is there?
[quote=244483:@Richard Albrecht]
These are stand alone cgi. [/quote]
This doesn’t make sense
Their EITHER standalone with an embedded web server
OR CGI
But not both
In that case you need a slightly higher level script. Something that periodically connects to the app and checks for the internal server error page. If it sees that page then it would kill the app. You could also do this with a shell script of some sort or maybe a 3rd party tool. The options will vary depending on the platform.
A web app can get non-responsive even if it is still running.
For instance, an evil attacker can consume all available sockets and leave your web app just sitting there.
I execute a simple shell script with crontab every x minutes that checks the response from my web app by requesting a page that is generated by the web app and checking that a string matches a word on the page.
If my web app has not responded correctly within 10 seconds I presume it has either crashed or is stuck in a non-responsive state. The script then kills and re-launches my web app.
My script is as follows.
You can easily enhance it with email notifications etc.
#!/bin/bash
#This script will check the responsive state of a WebApp by requesting a web page and matching a string on the page.
#You can preferably run this script on a regular interval with crontab.
#Allow at least 1 full minute for the script to complete (depending on curl timeout).
mysite='127.0.0.1:8080' #<--Site:port to check, Edit here.
mystring='<html' #<--String to match on web page (no spaces), Edit here.
myresult=$(curl -m10 -s $mysite | grep -c -m1 $mystring) #Check state, timeout after 10 secs.
if [ $myresult -eq 0 ] #If myWebApp is not responding.
then #Shell commands to run if the site is not responding.
#First we kill all instances of myWebApp in case it has locked up and is still running.
killall myWebApp > /dev/null 2>&1 #<--Edit web app name here.
#Then we re-start the WebApp.
/path/to/my/myWebApp #<--Edit path, params to web app here.
fi
Yes, I see no reason why not, maybe you need to do some modifications in the script to make it do what you want.
The scripts simply detects if the web server, CGI or standalone web app (a web page) does not respond as expected, and let you take actions if it does not.
You can restart the whole web server if you like, or just kill all the instances of the web app, or kill all active web sessions.
I have sometimes used it to monitor the apache web server and auto-restart it if it does not respond correctly.