• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Remote Restart via AS
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Remote Restart via AS


  • Subject: Re: Remote Restart via AS
  • From: Graff <email@hidden>
  • Date: Thu, 15 Apr 2004 03:52:55 -0400

Ugh, I wrote all this and then I re-read the e-mail and realized that the server you are talking about is running Mac OS 8.6. Obviously none of this will work for 8.6, it's all pretty much based on at least Mac OS X 10.0 and the System Events stuff needs Mac OS X 10.3.

I'm posting it anyways because why let it go to waste, maybe it will help someone else out there...

----------------------------

Well the quick and dirty way is to enable ssh and then just ssh into the machine and enter this command:

shutdown -r now

This will reboot the server immediately. It can be ugly for any GUI app because they could possibly need user interaction to save documents. For example if a user has a Word document open and hasn't saved this command will just quit the program and lose the document. This may not be a problem if there is no application that needs a user at the helm to shut it down manually.

You could also do it through an AppleScript:

tell application "System Events" to restart

This is a little kinder on the GUI portion of Mac OS X because it will better inform GUI applications that they should quit gracefully. The trouble with this is that if any GUI application needs attention before it will quit then the entire reboot will halt.

However you may be best served by just finding out if you can simply restart some part of the server application that is operating weirdly. For example, does the application open up any daemons which run in the background? Maybe one of them is hung. If so then you can do something similar to this:

kill `ps -acx | awk '/daemon name/ { print $1 }'`

This will quit the hung daemon. Then you can have the GUI scripted to shut down and restart the application. Here's a spitball script that will give you an idea of how you might do this:
----------
set daemonName to "daemon name"
set theApp to "application name"

set theResult to do shell script "ps -acx | awk '/" & daemonName & "/ { print $1 }'"
set processNumber to theResult as number
if (processNumber > 0) then
do shell script "kill " & processNumber
end if

set theResult to do shell script "ps -acx | awk '/" & daemonName & "/ { print $1 }'"
set processNumber to theResult as number
if (processNumber > 0) then
do shell script "kill -KILL" & processNumber
end if

tell application "System Events"
if exists process theApp then
set itExists to true
else
set itExists to false
end if
end tell

if itExists then tell application theApp to quit

tell application theApp to activate
----------

I do the check for the daemon twice because some hung processes won't be quit by a normal kill. So we first try a normal kill and if the process is still around we go for the jugular by issuing an almost-unstoppable kill signal. Then we quit the server application if it is running and we then start it up. I don't know exactly how the Filemaker Server runs so I'm just giving you a rough example.

- Ken

On Apr 14, 2004, at 10:31 AM, Mark Record wrote:

Hello Applescripters,

At my office, we have a server running Filemaker. For some reason the Filemaker Server application is prone to crashing (actually it doesn't crash, but it will stay open and stop sharing databases - is "hang" the proper word?). When this happens, we have to restart the machine to get the FM Server to work again.

Quite often the server will crash/hang/stop working when there is nobody at the office to physically restart the machine and remote workers need access to the FM databases.

My thinking is that a remote restart should be something that I could accomplish via applescript (as opposed to shelling out money for Remote Desktop or Timbuktu).

The real question is how to trigger it remotely. I was thinking of making a Folder Action (when file is dropped into the folder, the computer restarts), but that just seems like an ugly way to do it.

Any suggestions?


Oh yeah, and here's the kicker: the server is running OS 8.6...
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.


References: 
 >Remote Restart via AS (From: Mark Record <email@hidden>)

  • Prev by Date: Re: Remote Restart via AS
  • Next by Date: Re: Fwd: Brain Function
  • Previous by thread: Re: Remote Restart via AS
  • Next by thread: Re: Remote Restart via AS
  • Index(es):
    • Date
    • Thread