Downtime Detection /w Automated Restart
In order to prevent a future downtime, the next server release will contain code to monitor itself. A separate thread will poll the server every 30 seconds. If the server does not respond for 7 consequitive times, the server will be considered down and automatically restarted.
Possible reasons for a downtime include: running out of memory, database going down, loosing the connection to the database, file handles exhausted, other crashes and errors.
Although the code will not catch all server problems and will not be able to restart the server in all cases, it will still be able to take care of at least some of the cases listed above. The server monitor will be better than having nothing in place at all.
Java code to restart a computer:
String os = System.getProperty("os.name").toLowerCase();
boolean windows = os.indexOf( "win" ) >= 0;
Runtime runtime = Runtime.getRuntime();
if (windows) {
// for windows
runtime.exec("cmd /c shutdown -r -t 0");
}
else {
// for Linux and Mac OS X
runtime.exec("/sbin/shutdown -r now");
}