hostname of web server (default: same as ) // hostname of scheduling server (default: same as ) // pid file of scheduling server httpd.conf // (default: /etc/httpd/run/httpd.pid) // hostname of upload/download server (default: same as ) // pid file of upload/download server httpd.conf // (default: /etc/httpd/run/httpd.pid) // path to ssh (default: /usr/bin/ssh) // path to ps (which supports "w" flag) (default: /bin/ps) /////////////////////////////////////////////////////////////////////////////// require_once("../inc/util.inc"); require_once("../inc/db.inc"); require_once("../inc/xml.inc"); require_once("../inc/cache.inc"); $xml = get_int("xml", true); $cache_args = ""; if ($xml) $cache_args = "xml=1"; $cache_period = 600; start_cache($cache_period, $cache_args); $xmlout = ""; if ($argv[1] == "-f") { $xmlout = $argv[2]; $xmloutfile = fopen($xmlout,"w+"); if (!$xmloutfile) { die( "failed to open file: $xmlout"); } } // daemon status outputs: 1 (running) 0 (not running) or -1 (disabled) // function daemon_status($host, $pidname, $progname, $disabled) { global $ssh_exe, $ps_exe, $project_host; $path = "../../pid_$host/$pidname.pid"; $running = 0; if (is_file($path)) { $pid = file_get_contents($path); if ($pid) { $command = "$ps_exe ww $pid"; if ($host != $project_host) { $command = "$ssh_exe $host " . $command; } $foo = exec($command); if ($foo) { if (strstr($foo, $progname)) $running = 1; } } } if ($disabled == 1) $running = -1; return $running; } function show_status($host, $function, $running) { global $xml,$xmlout,$xmloutfile; $xmlstring = " \n $host\n $function\n"; $htmlstring = "$function$host"; if ($running == 1) { $xmlstring .= " running\n"; $htmlstring .= "Running\n"; } elseif ($running == 0) { $xmlstring .= " not running\n"; $htmlstring .= "Not Running\n"; } else { $xmlstring .= " disabled\n"; $htmlstring .= "Disabled\n"; } $xmlstring .= " \n"; $htmlstring .= "\n"; if ($xml) { echo $xmlstring; return 0; } if ($xmlout) { fwrite($xmloutfile,$xmlstring); } echo $htmlstring; return 0; } function show_daemon_status($host, $pidname, $progname, $disabled) { $running = daemon_status($host, $pidname, $progname, $disabled); show_status($host, $pidname, $running); } function show_counts($key, $xmlkey, $value) { global $xml,$xmlout,$xmloutfile; $formattedvalue = number_format($value); $xmlstring = " <$xmlkey>$value\n"; if ($xml) { echo $xmlstring; return 0; } if ($xmlout) { fwrite($xmloutfile,$xmlstring); } echo "$key$formattedvalue"; return 0; } function get_mysql_count ($query) { $result = mysql_query("select count(*) as count from " . $query); $count = mysql_fetch_object($result); mysql_free_result($result); return $count->count; } $config_xml = get_config(); $config_vars = parse_element($config_xml,""); $project_host = parse_element($config_vars,""); $www_host = parse_element($config_vars,""); if ($www_host == "") { $www_host = $project_host; } $sched_pid = parse_element($config_vars,""); if ($sched_pid == "") { $sched_pid = "/etc/httpd/run/httpd.pid"; } $sched_host = parse_element($config_vars,""); if ($sched_host == "") { $sched_host = $project_host; } $uldl_pid = parse_element($config_vars,""); if ($uldl_pid == "") { $uldl_pid = "/etc/httpd/run/httpd.pid"; } $uldl_host = parse_element($config_vars,""); if ($uldl_host == "") { $uldl_host = $project_host; } $ssh_exe = parse_element($config_vars,""); if ($ssh_exe == "") { $ssh_exe = "/usr/bin/ssh"; } $ps_exe = parse_element($config_vars,""); if ($ps_exe == "") { $ps_exe = "/bin/ps"; } $xmlstring = "\n " . time() . "\n \n"; if ($xml) { xml_header(); echo $xmlstring; } else { if ($xmlout) { fwrite($xmloutfile,$xmlstring); } page_head("Server status page"); echo "

[As of ", time_str(time()), "]

Server status

"; } // Are the data-driven web sites running? Check for existence // of stop_web. If it is there, set $web_running to -1 for // "disabled," otherwise it will be already set to 1 for "enabled." // Set $www_host to the name of server hosting WWW site. // $web_running = !file_exists("../../stop_web"); if ($web_running == 0) $web_running = -1; show_status($www_host, "data-driven web pages", $web_running); // Check for httpd.pid file of upload/download server. // $uldl_running = file_exists($uldl_pid); if ($uldl_running == 0) $uldl_running = -1; show_status($uldl_host, "upload/download server", $uldl_running); // $sched_running = !file_exists("../../stop_sched"); // $sched_running = file_exists($sched_pid); if ($sched_running == 0) $sched_running = -1; show_status($sched_host, "scheduler", $sched_running); // parse through config.xml to get all daemons running // $cursor = 0; while ($thisxml = trim(parse_next_element($config_xml,"",&$cursor))) { $host = parse_element($thisxml,""); if ($host == "") { $host = $project_host; } $cmd = parse_element($thisxml,""); list($ncmd) = explode(" ",$cmd); $log = parse_element($thisxml,""); if (!$log) { $log = $ncmd . ".log"; } list($nlog) = explode(".log",$log); $pid = parse_element($thisxml,""); if (!$pid) { $pid = $ncmd . ".pid"; } $disabled = parse_element($thisxml,""); show_daemon_status($host,$nlog,$ncmd,$disabled); } $xmlstring = " \n \n"; if ($xml) { echo $xmlstring; } else { if ($xmlout) { fwrite($xmloutfile,$xmlstring); } echo "
ProgramHostStatus
Running: Program is operating normally
Not Running: Program failed or ran out of work
(or the project is down)
Disabled: Program has been disabled by staff
(for debugging/maintenance)

Database/file status

"; } $retval = db_init_aux(); if ($retval) { echo "The database server is not accessible"; } else { if (!$xml) { echo " "; } // If you are reading these values from a file rather than // making live queries to the database, do something like this: // // $sendfile = "/home/boincadm/server_status_data/count_results_unsent.out"; // $n = `/bin/tail -1 $sendfile`; // show_counts("Results ready to send","results_ready_to_send",$n); show_counts( "Results ready to send", "results_ready_to_send", get_mysql_count("result where server_state = 2") ); show_counts( "Results in progress", "results_in_progress", get_mysql_count("result where server_state = 4") ); show_counts( "Workunits waiting for validation", "workunits_waiting_for_validation", get_mysql_count("workunit where need_validate=1") ); show_counts( "Workunits waiting for assimilation", "workunits_waiting_for_assimilation", get_mysql_count("workunit where assimilate_state=1") ); show_counts( "Workunits waiting for deletion", "workunits_waiting_for_deletion", get_mysql_count("workunit where file_delete_state=1") ); show_counts( "Results waiting for deletion", "results_waiting_for_deletion", get_mysql_count("result where file_delete_state=1") ); $result = mysql_query("select MIN(transition_time) as min from workunit"); $min = mysql_fetch_object($result); mysql_free_result($result); $gap = (time() - $min->min)/3600; if ($gap < 0) { $gap = 0; } show_counts( "Transitioner backlog (hours)", "transitioner_backlog_hours", $gap ); if (!$xml) { echo "
State#
"; } } $xmlstring = " \n\n"; if ($xml) { echo $xmlstring; } else { if ($xmlout) { fwrite($xmloutfile,$xmlstring); } echo "
 
"; page_tail(); } end_cache($cache_period, $cache_args); ?>