clockwerk-tools – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 eva 1 #!/usr/bin/php
2 <?php
3  
4 /////////////////////////////////////////////////////////////
5 // Wizardry and Steamworks (c) was.fm - 2014, License: MIT //
6 // //
7 // Permission is hereby granted, free of charge, to any //
8 // person obtaining a copy of this software and associated //
9 // documentation files (the "Software"), to deal in the //
10 // Software without restriction, //including without //
11 // limitation the rights to use, copy, modify, merge, //
12 // publish, distribute, sublicense, and/or sell copies of //
13 // the Software, and to permit persons to whom the //
14 // Software is furnished to do so, subject to the //
15 // following conditions: //
16 // //
17 // The above copyright notice and this permission notice //
18 // shall be included in all copies or substantial portions //
19 // of the Software. //
20 // //
21 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF //
22 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT //
23 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS //
24 // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO //
25 // EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE //
26 // FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER //
27 // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING //
28 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR //
29 // THE USE OR OTHER DEALINGS IN THE SOFTWARE. //
30 /////////////////////////////////////////////////////////////
31  
32 /////////////////////////////////////////////////////////////
33 // CONFIGfURATION //
34 /////////////////////////////////////////////////////////////
35  
36 // Hostname or IP of your OpenSim MySQL server.
37 define("MYSQL_HOSTNAME", "localhost");
38 // Username of the OpenSim MySQL user.
39 define("MYSQL_USERNAME", "opensim");
40 // Password of the OpenSim MySQL user.
41 define("MYSQL_PASSWORD", "***");
42 // Name of the OpenSim database on the MySQL server.
43 define("MYSQL_DATABASE", "opensim");
44  
45 /////////////////////////////////////////////////////////////
46 // INTERNALS //
47 /////////////////////////////////////////////////////////////
48  
49 if(!defined('STDIN')) {
50 print 'This script is meant to be run on the command line.'."\n";
51 return 1;
52 }
53  
54 $pid = `pidof mono`;
55 // process does not exist, so abort
56 if(strlen($pid) == 0) {
57 return 0;
58 }
59  
60 $countdown = file_get_contents(
61 '/sys/class/xt_idletimer/timers/clockwerk'
62 );
63 // the file could not be found, bail
64 if($countdown === FALSE) {
65 return 0;
66 }
67  
68 switch($countdown) {
69 case 0:
70 //suspend
71 $stat = `ps --no-headers -o stat -C mono | grep T`;
72 // process already suspended, so abort
73 if(strlen($stat) != 0) {
74 return 0;
75 }
76 `kill -s STOP $pid`;
77 break;
78 default:
79 //resume
80 `kill -s CONT $pid`;
81 break;
82 }