A long time ago I wrote a bash shell script to monitor ColdFusion 7 and issue a restart if the CF server hung itself or was about to run out of memory.  I posted info on this script at House of Fusion back then. Today I am still getting requests for this script so I am finally posting the script files to my blog (which I didn't have back then).  


Repost from HOF:

My bash script does two things.  It checks a specified URL for a certain string to see if CF is still responsive and it also calls a cf script which reports back an integer that is the amount of free JVM memory left.

If a hang situation is detected the script will pause for a specified amount of time and

try again.  If the second attempt fails then it issues a restart command.  I've also scripted a way to perform automatic stack dumps (it can even find the proper PID on it's own) when when a hang situation is detected.  This way you can go into your logs and try to figure out what went wrong.

If your JVM memory usage creeps up and is causing unresponsive behavior this script will also record the memory usage when memory reaches a threshold that you set.  It can also restart CF if the low memory reaches a second threshold that you set.

The script also logs everything into it's own log file in /var/logs/ so you can track actions taken by the script.

The reason I wrote this was that when we migrated from CF5 to CFMX 7 the code base was so bad this was the only way to keep the server running.   It took me months to track down all the bugs and bad queries to get the code stable.  This is what can happen when there is no version control, ten years of development, hacking and re-hacking by so many different programmers that the owner can't name them all.  Now we have SVN, good programmers and a bug hound (me).


That was a over 2 years ago when I wrote that script, but it seems like it's a lot longer than that since now we are running five ColdFusion 8 64Bit Enterprise servers.  We had far fewer back then and when we first migrated to CF7 we ran on a single server. 

So here are the files from back then.  I found the zip file I had made and posted it here. Just click the Download Icon.

*Note: When I write little tools like this I'm usually writing it because there is something I absolutely need to see in order to complete another project. These little tools are not written as projects themselves and therefore may not be very pretty or as full featured as something that I was writing as a complete project. I just needed to get some code running that gave me back the data I needed to see. There are no warranties or promises. If you find is useful then great. If not, oh well. I know the code works on CF8 at the moment. It used to work on CF7, but I do not have a CF7 server anymore so I can not be certain.