#!/usr/bin/php &1', $output); if ( preg_match('/any/', implode($output)) ) { file_put_contents_verbose($file, 'GLSASDFOK'); } else { file_put_contents_verbose($file, implode($output)); } exec('chmod 755 ' . $file); } // RAID function cron_raid($active, $test_raid_args) { global $basepath; if ( ! $active ) { return; } foreach ( $test_raid_args as $raid ) { if ( ! is_array($raid) ) { echo 'Error in $test_raid_args, a member is not an array' . "\n"; return; } exec($basepath . '/sdf-raid-' . $raid[0] . '.pl ' . $raid[1], $output); file_put_contents_verbose('/var/run/sdf-raid-' . $raid[0], implode($output)); } } // SMART function cron_smart($active, $smartchk, $file) { if ( ! $active ) { return; } if ( ! is_array($smartchk) ) { file_put_contents_verbose($file, 'smartchk not array'); return; } foreach ($smartchk AS $smartdisk) { $success = TRUE; $r = exec('/usr/sbin/smartctl -A ' . $smartdisk, $output, $ret); if ( $ret != 0 ) { file_put_contents_verbose($file, 'smartctl failed for ' . $smartdisk); return; } foreach($output AS $line) { if ( preg_match('/^\s*(\d+)\s+.+\s+(\d+)\s*$/', $line, $matches) ) { // was not zero on 3 different disks, so unreliable // if ( $matches[1] == 1 && $matches[2] != 0 ) { file_put_contents_verbose($file, 'smartctl (' . $smartdisk . ') Raw_Read_Error_Rate is not zero (' . $matches[2] . ')'); return; } // idem // if ( $matches[1] == 7 && $matches[2] != 0 ) { file_put_contents_verbose($file, 'smartctl (' . $smartdisk . ') Seek_Error_Rate is not zero (' . $matches[2] . ')'); return; } if ( $matches[1] == 196 && $matches[2] != 0 ) { file_put_contents_verbose($file, 'smartctl (' . $smartdisk . ') Reallocated_Event_Count is not zero (' . $matches[2] . ')'); return; } } } } file_put_contents_verbose($file, 'OK'); } function cron_supervise($active, $test_supervise_args, $test_supervise_file) { if ( ! $active ) { return; } // create command by concatenating all the directories $cmd = 'svstat'; foreach ($test_supervise_args as $directory) { // if not directory, try prepending /services if ( (substr($directory,0,1)!='/') && is_dir('/service/' . $directory) ) { $directory = '/service/' . $directory; } // directory must exist if ( ! is_dir($directory) ) { file_put_contents_verbose($test_supervise_file, 'supervise failed for ' . $directory . ': not a valid directory' . "\n"); return; } $cmd .= ' \'' . $directory . '\''; } // exec command and parse results exec($cmd, $output); foreach ($test_supervise_args as $directory) { if ( (substr($directory,0,1)!='/') && is_dir('/service/' . $directory) ) { $directory = '/service/' . $directory; } $status = FALSE; foreach($output as $line) { if ( preg_match("|^$directory: up|", $line) ) { $status = TRUE; } } if ( ! $status ) { file_put_contents_verbose($test_supervise_file, 'supervise failed for ' . $directory . ': service is not up'); return; } } file_put_contents_verbose($test_supervise_file, 'OK'); } // verbose function function file_put_contents_verbose($file, $content) { file_put_contents($file, $content); echo $file . ': ' . $content . "\n"; } // fake function for legacy function checkmounts() {}