示例#1
0
function run_check($file_services, $file_configuration, &$data_autoconf, $binary, $binary_stats, $file_report, $var_dir, $nb_check, $time)
{
    if (file_put_contents($file_services, $data_autoconf) === FALSE) {
        exit('error: file_put_contents failed' . NL);
    }
    my_system('rm -rf ' . $var_dir);
    @mkdir($var_dir);
    @mkdir($var_dir . '/rw');
    @mkdir($var_dir . '/spool');
    system($binary . ' ' . $file_configuration . ' > /dev/null 2>&1 &');
    sleep(1);
    if (my_system('ps aux | grep ' . basename($binary) . ' | grep -v grep') == '') {
        exit('error: ' . basename($binary) . ' not running' . NL);
    }
    for ($i = 0; $i < $time; $i += 5 * 60) {
        $memory = get_memory($binary);
        $loadavg = get_loadavg();
        $latency = get_latency($binary_stats);
        $line = $nb_check . ' ' . $memory . ' ' . $loadavg['load5'] . ' ' . $loadavg['load15'] . ' ' . $latency . ' ' . time() . NL;
        if (file_put_contents($file_report, $line, FILE_APPEND) === FALSE) {
            exit('error: file_put_contents failed' . NL);
        }
        sleep(5 * 60);
    }
    my_kill($binary);
    return $latency;
}
require_once 'geograph/gridsquare.class.php';
require_once 'geograph/map.class.php';
require_once 'geograph/image.inc.php';
$db = NewADOConnection($GLOBALS['DSN']);
$start_time = time();
$end_time = $start_time + 60 * $param['timeout'];
#$map=new GeographMap;
while (1) {
    $invalid_maps = $db->GetOne("select count(*) from mapcache where age > 0 and type_or_user >= -1");
    if ($invalid_maps) {
        //done as many small select statements to allow new maps to be processed
        $recordSet =& $db->Execute("select * from mapcache where age > 0 and type_or_user >= -1\n\t\t\torder by pixels_per_km desc, age desc limit 50");
        while (!$recordSet->EOF) {
            //sleep until calm if we've specified a load average
            if ($param['load'] < 100) {
                while (get_loadavg() > $param['load']) {
                    sleep($param['sleep']);
                    if (time() > $end_time) {
                        exit;
                    }
                }
            }
            $map = new GeographMap();
            foreach ($recordSet->fields as $name => $value) {
                if (!is_numeric($name)) {
                    $map->{$name} = $value;
                }
            }
            $ok = $map->_renderMap();
            echo ($ok ? 're-rendered ' : 'FAILED: ') . $map->getImageFilename() . "\n";
            flush();