clockwerk-tools – Rev 1
?pathlinks?
#!/usr/bin/php
<?php
/////////////////////////////////////////////////////////////
// Wizardry and Steamworks (c) was.fm - 2014, License: MIT //
// //
// Permission is hereby granted, free of charge, to any //
// person obtaining a copy of this software and associated //
// documentation files (the "Software"), to deal in the //
// Software without restriction, //including without //
// limitation the rights to use, copy, modify, merge, //
// publish, distribute, sublicense, and/or sell copies of //
// the Software, and to permit persons to whom the //
// Software is furnished to do so, subject to the //
// following conditions: //
// //
// The above copyright notice and this permission notice //
// shall be included in all copies or substantial portions //
// of the Software. //
// //
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF //
// ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT //
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS //
// FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO //
// EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE //
// FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER //
// IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR //
// THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
// CONFIGfURATION //
/////////////////////////////////////////////////////////////
// Hostname or IP of your OpenSim MySQL server.
define("MYSQL_HOSTNAME", "localhost");
// Username of the OpenSim MySQL user.
define("MYSQL_USERNAME", "opensim");
// Password of the OpenSim MySQL user.
define("MYSQL_PASSWORD", "***");
// Name of the OpenSim database on the MySQL server.
define("MYSQL_DATABASE", "opensim");
/////////////////////////////////////////////////////////////
// INTERNALS //
/////////////////////////////////////////////////////////////
if(!defined('STDIN')) {
print 'This script is meant to be run on the command line.'."\n";
return 1;
}
$pid = `pidof mono`;
// process does not exist, so abort
if(strlen($pid) == 0) {
return 0;
}
$countdown = file_get_contents(
'/sys/class/xt_idletimer/timers/clockwerk'
);
// the file could not be found, bail
if($countdown === FALSE) {
return 0;
}
switch($countdown) {
case 0:
//suspend
$stat = `ps --no-headers -o stat -C mono | grep T`;
// process already suspended, so abort
if(strlen($stat) != 0) {
return 0;
}
`kill -s STOP $pid`;
break;
default:
//resume
`kill -s CONT $pid`;
break;
}