This is an email I posted to the XTension list. Newer versions of XTension don't need this hack but I've kept it on here for historical purposes...

 

I think I've come up with a very dirty, roundabout way to recover from the common CM11a problem we've discussed here. It's not pretty, but I think it works.

The problem I'm describing is this: The CM11a decides to give up. XTension looks for the CM11a every five minutes, and when it's playing dead, XTension places a "periodic check with interface failed" message in the log. Sometimes the CM11a mysteriously wakes up, although on my system it eventually causes XTension to hang. A simple system restart always recovers the CM11a. I know others have reported the same problem.

This "solution" operates by periodically looking at the current "XTension Log" file. In the current incarnation, the script runs every twenty minutes, and if it finds two successive "periodic check with interface failed" errors at the end of the log file, it initiates a restart. I will shortly alter slightly to allow for other log entries between failures (ie, if two of the last four entries are failure notices, then restart).

This has successfully restarted my Mac on the one occasion this problem occurred since I wrote it. It has also worked fine through testing (by unplugging the CM11a and waiting for a failure).

Please only consider trying this if you're comfortable getting messy. XTension seems to halt other operations while scripts are running, but if XTension does try to write to the log while the log is being read, I don't know what could happen. I recommend having XTension cut the log file every day so the procedure doesn't take too long.

I'm very interested in comments on the scripts and this method of trapping the error.

Three scripts are involved:

CheckComm: This is an internal XTension script which I have scheduled to run every 17 minutes. I decided on 17 minutes because it should follow error states, but before the system would crash (usually after 45-60 minutes). This period should also interfere with other scheduled events infrequently. It parses through the entire log file. If it determines an error state exists, it calls another internal script called System Restart.

System Restart (internal script): Calls an external applet, also called System Restart. Also increments a counter so I can see how often this happens.

System Restart (external applet): Explicitly quits XTension and restarts the system.

The scripts:

(keep in mind the lines may wrap due to email)

 

--CheckComm

--Look in the current log to see if communications have failed
--this parses through a log file.  The last line is the entry for running
--this script.  If the two previous lines both contain the "pediodic check
--with interface failed" message, a script called "System Restart" will
--be executed, hopefully restarting the system and clearing the error.

global lastline, secondlastline, thirdlastline
copy "" to secondlastline
copy "" to thirdlastline
copy "" to lastline
copy "" to recentline

set pathToUse to "XTension Log"
try
	set x to open for access alias pathToUse
on error
	write log "Problem opening the log during communications check!"
end try
set done to false
repeat while not done
	try
		set recentline to lastline
		set lastline to {(read x before return)}
		set thirdlastline to secondlastline
		set secondlastline to recentline
	on error errString number errNum
		if errNum = -39 then --end of file
			if ("periodic check with interface failed" is in (secondlastline as string)) and ¬
				("periodic check with interface failed" is in (thirdlastline as string)) ¬
					then
				write log "Two successive 'interface failed' messages found.  Restarting system."
				set value of "Restart counter" to ((value of "Restart counter") + 1)
				execute script "System restart"
			else
				--End of file, no need to restart
			end if
			set done to true
		else
			write log "error #" & errNum & " " & errString & " while looking at the log for a comm error!"
			return errString
			set done to true
		end if
	end try
end repeat

--end of CheckComm

 

 

--System Restart (internal script):

ignoring application responses
	tell application "System Restart"
		run
	end tell
end ignoring

--end of System Restart (internal script)

 

 

--System Restart (external applet)

on run
	ignoring application responses
		tell application "XTension 1.7.1"
			quit
		end tell
		tell application "Finder"
			restart
		end tell
	end ignoring
end run

--end of System Restart (external applet)