Check for Crashed CGI apps

We have several CGI apps running on our website. For the most part they have no interaction. Each one does a specific job, usually of form to gather information like a renewal form or an application form.

@Greg O’Lone Said in a post I was reading: Make sure you have implemented the two UnhandledException handlers so yo can see what’s failing. There’s one in app and one in Session. I have tried implementing an unhandled exception handler but I don’t think I’m doing it correctly. Does somebody have some examples that I could use to create the two handlers that Greg recommends.

What happens from the user’s point of view is they get the internal server error and I have to go terminate the application from memory, and then it’s all right.

The other thought I had was some kind of script running on the server like every minute that checks for the internal server error and if it sees it that terminates it from memory. This is way beyond my capabilities.

If anybody has any recommendations or ideas please let me know.

In terms of Unhandled Exceptions, the minimum you could do is to log it by appending to a file with textOutputStream. So you can come back and see what has happened. Then you can start addressing the issues.

The idea is to start from a diagnostic.

I don’t think you really need another app to look for issues. You should be able to manage that from the UnhandledException event.

Remember if you don’t have any session active and you get an error, you can quit a CGI app and it will simply restart the next time a visitor comes along.

Do you have any examples for the UnhandledException event? I’ve been playing with it but it’s not giving me the information I need.

I would start by that to get a log of all errors. I save the file to home because it is convenient and out of the web space, but it could be anywhere.

[code]Function UnhandledException(Error As RuntimeException) Handles UnhandledException as Boolean
dim log as string
dim d as new date
log = log + d.SQLDateTime + EndOfLine
log = log + Error.Message + EndOfLine + error.Reason + join(stack, EndOfLine)

Dim f As FolderItem = SpecialFolder.UserHome.child(“myErrorLog.txt”)
Dim t as TextOutputStream
If f <> Nil then
t = TextOutputStream.Append(f)
t.WriteLine(log)
t.Close
End If
Return true
End Function
[/code]

When you have a clearer idea of the issues that present, then you can address them with a select case based on Error.Number for instance. The log should tell you anyway through the stack where it happens, so you can eventually modify your code.

It is probably worth pointing out that one of the important lines in Michel’s code is the selection of where to write the log file. Make sure that the account under which the app is running has read/write permission. Otherwise you’ll get nada.

Great thanks.

Im getting a compiler error: Item Doesn’t exist on
log = log + Error.Message + EndOfLine + error.Reason + join(stack, EndOfLine)

stack is hi hilighted…

When it comes to monitoring, CURL (command line function) is your friend.

You can either write a script using CURL or you could also write a small Xojo app that uses either curl (through the shell) or an http socket to periodically poll your site, parse the response and then restart the webapp (again through the shell) when required

[quote=307799:@Richard Albrecht]Great thanks.

Im getting a compiler error: Item Doesn’t exist on
log = log + Error.Message + EndOfLine + error.Reason + join(stack, EndOfLine)

stack is hi hilighted…[/quote]

Error is provided in the UnhandledException event as a parameter. If you try elsewhere it won’t happen. Place the code in there and raise an exception from your code.

See http://developer.xojo.com/userguide/exception-handling

[quote=307788:@Michel Bujardet]I would start by that to get a log of all errors. I save the file to home because it is convenient and out of the web space, but it could be anywhere.

[code]Function UnhandledException(Error As RuntimeException) Handles UnhandledException as Boolean
dim log as string
dim d as new date
log = log + d.SQLDateTime + EndOfLine
log = log + Error.Message + EndOfLine + error.Reason + join(stack, EndOfLine)

Dim f As FolderItem = SpecialFolder.UserHome.child(“myErrorLog.txt”)
Dim t as TextOutputStream
If f <> Nil then
t = TextOutputStream.Append(f)
t.WriteLine(log)
t.Close
End If
Return true
End Function
[/code]

When you have a clearer idea of the issues that present, then you can address them with a select case based on Error.Number for instance. The log should tell you anyway through the stack where it happens, so you can eventually modify your code.[/quote]
If you do t this way, make sure you wrap it in a try catch, otherwise if you get an ioexception, you’ll get caught in an infinite loop of exceptions.