How can I...Restart on Error?

Hello all,
I have been working on a script to restart my server if a specific application fails.

Does anyone know a script that would restart the machine upon any error message?

Kick the whole box for a single process?

Elaborate. What exactly is going on?

And is the system on the server OS 9?

Mikey/Adam,
I just got an Xserve running OS 10.4.8 and also the New Filemaker Pro. It will be used primarily as a Host for FMP Databases. Filemaker would sometimes freeze and lock up our old machine. So I wanted an Applescript that would repeatedly open a DB to insure its still working and if it could not open the DB, restart the machine.

Well…i’ve got it recognizing whether it’s working or not, but I can’t get it to restart on error.
I’ve tried some different scripts that I found on forums and also read some guides, but none worked properly.

Can you help?

You need to find a better solution to your FileMaker problem than restarting your server. You’re putting a Band-Aid over a knife wound.

If it’s Filemaker that’s giving grief, why restart the machine? Just quit and restart FM.

set myApp to "appName"
tell application "System Events" to if exists process myApp then
	try
		tell myApp to quit
	on error -- it didn't listen
		do shell script "killall 'appName'" -- equivalent to Force Quit
	end try
end if
delay 3
tell application myApp to activate

I don’t have a problem with Filemaker or any gaping knife wounds.
I’m simply trying to write a precautionary script for when/if I get an application freeze, the server will reboot. This way, if i’m 5 hours away, I don’t have to come back just to do a server/app restart.

My Filemaker DB’s are being hosted with FM Server 8. There is no visible application but rather a daemon which is not scriptable.
If this daemon were to freeze, you would not be able to access the DB’s.

I want it to reboot the machine since the daemon would be the culprit. On any Server restart, all DB’s are opened and hosted automatically.

This led me to create a script which opens Filemaker Client, attempts to open a DB, and upon the result, either wait 5 minutes and repeat or reboot the machine.

I know this is long winded…does it make sense?

EDIT: My script is working in regards to opening FMP Client, then opening and closing a DB. The way i’m testing it is closing the one DB that is being used as the gopher. When it’s closed, It gets hung up on error messages and dialog windows. I was trying to find a line of commands that would basically cancel any errors/windows and proceed to the Restart command.

What is preventing you from killing and restarting the daemon, and then starting whatever other services you need, in the correct order?

but it is restartable. i don’t have FMP and don’t know the name of the daemon. however, this is an example i’d handle this kind of problem:


property adminPassword : "myPass"

try
	--check for FMP freeze here
on error
	do shell script "/usr/bin/killall nameOfFMPDaemon" password adminPassword with administrator privileges
	delay 1
	--start FMP
end try

save this as an application so that your password is not visible to the world. you may want to run this as a cron job or something so it checks periodically through the day.

cheers.

EDITED to add: I just realized that Adam’s script does basically the same thing. too late again!

Pardon if this is a stupid question.

Isn’t this script going to attempt to Quit the daemon? If it’s running properly, I don’t want the test to be an attempt to quit.

EDIT: Ok. Did what you said here. It ran as an app. However, this did not do anything. It did not even recognize that there were no DB’s available once I closed them. Was I supposed to add it to my original?

LS, why don’t you post your tester so someone can add the means of accomplishing what you want to do to it? Also, some of us don’t have a FM server to play with, so tell us the name of the daemon and how you normally start it.

Ok, Let me show you what I have.
What I restart whether it be the Daemon, Application, or the Server is not my problem.

I can’t get by the error dialogs.

set myApp to "Filemaker Pro"
tell application "FileMaker Pro"
	try
		open file "Filemaker:¢FMP System TEST:TEST.fp7"
	on error -- it didn't listen
		tell application "Finder" to restart -- equivalent to Force Quit
	end try
end tell

The script is working even to the point of recognizing there is a problem. But, when it does not recognize the database is working, it sits there on error windows. One says “nameofdatabase” could not open (not found)"; another is the window asking to find “nameofdatabase”.

It will not get past these error windows.
EDIT: Once I get these windows to close or cancel or whatever…I think it would work fine. Then it would just be making it repetitive.

Sorry, I’m lost. If this is on the Server, how will restarting the Server’s Finder help? What was the point of setting myApp - you don’t use it. If this is on a client of several then the messages are from your Finder telling you that the server didn’t respond. Which is the case?

It’s on the server. Finder is the application that restarts the computer, isn’t it?
The first script was part of another script that was suggested. I have not removed it even though the commands that it refered to are no longer there.

No, restarting the Finder will not restart the computer. The Finder is just another application that provides the file system GUI. Neither will restarting the Finder restart any other process, like your daemon that’s not responding. The Xtool.osax contains a restart instruction that will. This isn’t really bombproof either, because a safe restart will ask if you want to save any files that might be open and you don’t know what else is running on the server - so you’ll get another dialog you can’t see from a client.

You might try something like this:

try
	tell application "FileMaker Pro" to open file "Filemaker:¢FMP System TEST:TEST.fp7"
on error -- it didn't listen
	-- use one of the methods suggested earlier to force quit FMP and restart it
end try

Telling the Finder to “restart” will reboot the computer. It’s part of the Finder’s legacy suite.

Note, however, that this has been moved to System Events. The Finder command may (and likely will be) removed at some point in the future.

Regardless, this is not the best solution to the problem at hand. Kick the daemon and related processes, not the server.

But that’s followed Mike by: “Legacy suite Operations formerly handled by the Finder, but now automatically delegated to other applications”. I’m not willing to try it (because I don’t want to wait for a restart) but does it still work in Tiger?

It’s deprecated. It works, for now, but may be removed at any time. (See my note about System Events.)

LSP,

do shell script “sudo shutdown -r now” password “your_admin_password” with administrator privileges

This will reboot your machine as inelegantly as possible, and it won’t wait for any user input or throw any errors. It is probably a bad idea, but will that accomplish your original request?

Andy

Browser: Safari 412
Operating System: Mac OS X (10.4)

It is a bad idea, because it doesn’t account for anything else the server is doing, and it’s still not the right way to solve the problem.

Edit: Also, it’s horribly wrong. Do not use sudo when invoking “with administrator privileges”. It is both unnecessary and a security hole. Additionally, you should be using /full/paths/to/executables, because you’re invoking administrator rights. (Another security hole.)