source: system/freeze_restart.php@ 351

Last change on this file since 351 was 351, checked in by george, 17 years ago

Skript pro automatické restartování při zamrznutí.

File size: 1.2 KB
Line 
1<?php
2$MangosUptimeInterval = 60; // Matches UpdateUptimeInterval in mangosd.conf [seconds]
3$RestartDeadTime = 120; // Maximum dead time [seconds]
4$LoopSleepTime = 10; // Checking period [seconds]
5$MangosProcessName = '/a/mangos/bin/mangos-worldd';
6
7include('../global.php');
8
9echo('MaNGOS freeze restarter. Checking DB every '.$LoopSleepTime." seconds\n");
10$Restarted = 0;
11$Database->select_db('mangos');
12while(1)
13{
14 $DbResult = $Database->query('SELECT `starttime`, `uptime` FROM `uptime` ORDER BY `starttime` DESC LIMIT 1');
15 $DbRow = $DbResult->fetch_array();
16 $DbUptime = $DbRow['uptime'];
17 $RealUptime = time() - $DbRow['starttime'];
18 $TimeDifference = $RealUptime - $DbUptime;
19 echo('Uptime DB: '.$DbUptime.' vs. Real: '.$RealUptime." [s], Restart condition ".$TimeDifference." > ".$RestartDeadTime.
20 " (".round($TimeDifference / $RestartDeadTime * 100)."%)\n");
21 if(($TimeDifference > $RestartDeadTime) and ($Restarted == 0))
22 {
23 echo("Restarting MaNGOS...\n");
24 exec("ps -ef | grep '".$MangosProcessName."' | grep -v grep | awk '{print $2}' | xargs -i kill {}");
25 $Restarted = 1; // Restart only once and wait for new good uptime
26 } else $Restarted = 0;
27 Sleep($LoopSleepTime);
28}
29
30?>
Note: See TracBrowser for help on using the repository browser.