Dear AppleScript Experts,
I’ve built a nice web site but when my 4DWebSTAR 5.2.3 on my MacOS 10.2.3 stops working (for any reason), the visitors can’t get access to my site until I restart the computer. When this “web server crash” happens in the middle of the night, it makes the whole situation even worse so this is where I’m thinking about an AppleScript that would do the following:
Every xx seconds, check to see if the http://www.my-local-site.com is returning a value of, let’s say, which appears on every functional web page (from a web server that hasn’t crashed).
After xx number of unsuccessful attempts, it’s pretty clear the web server has crashed so the next logical step is to automatically RESTART the computer.
When the server reboots, this precious little AppleScript reloads automatically to continue checking the web server and make sure, once again, everything runs smoothly.
I need the help of one of you to build this AppleScript since I have very limited knowledge of the language. Hopefully, I’m at the right place to ask such a favor. In return for this very important piece of software (for me an anyone running a web server), I’ll be glad to offer an employer listing (if relevant) for a full year (on my site, SuperJobs.net) to anyone who resolves this issue and posts the script (or a downloadable version, ready to work).
Thank you all for you kind intervention,
I think you need kick-off or powerkey from http://www.sophisticated.com/
I haven’t used them but other reviews I’ve seen have been positive.
This code may be a base to build this tricky app. The only problems I see is: where you say “web server crash”, what does it means? Web server functions do not work? WebStar crashed?
If “application WebStar” crashed, then Finder should post a notification such as “this app crashed but nothing bad happened”; then we should find a way to dismiss this notification before restarting.
If this app not crashed, but simply it doesn’t work, we should add a line of code to quit WebStar before restarting… Does WebStar display a dialog such as “really quit”? Then we should dismiss this dialog, too…
Sorry, I have not webstar installed to check this. But this piece of code, saved as “stay-open” and within your login items, may do the job if there is not dialogs to dismiss…
property url_to_check : "http://192.168.200.1/"
property temp_file : (path to temporary items as text) & "tempfile.txt"
tell app "4DWebSTAR 5.2.3" to activate --> only first time I'm launched, after restarting
set errors to 0 --> initialize errors
if errors > 5 then tell application "Finder" to restart -- self explaining
--> download url_to_check
tell application "URL Access Scripting"
download url_to_check to file temp_file replacing yes
on error --> there is not such url? there was not response?
set errors to errors + 1
--> read web page returned of url_to_check
set x to (open for access result)
set z to (read x)
close access x
if z's length < 50 then set errors to errors + 1 -- hypothetical condition
return 5 -- run this code every 5 seconds
The tools I find most effective in assuring server reliability are:
- Custom Applescripts
- Sophisticated hardware - I have one of each and they are all great (Kick-Off, Rebound, Powerkey)
- Whistleblower (awesome!)
- A good APC UPS