#!/usr/bin/env php . // Find the status of remote server processes // and write it to a serialized file. // Run this as a periodic task; in general it can't run as a web script // since the apache user can't ssh. require_once("../inc/util.inc"); // see if a web server is running on the host // function check_web_server($host) { $url = "http://$host"; $x = file_get_contents($url); if ($x) return true; return false; } // see if the given program is running on the host // function check_program($host, $program) { $cmd = "ssh $host 'ps -C $program'"; $out = exec($cmd); if (strstr($out, $program)) return true; return false; } function main() { echo "--- Starting at ".time_str(time())." ---\n"; $x = array(); $c = simplexml_load_file("../../config.xml"); if (!$c) { die("can't parse config file\n"); } $config = $c->config; if ($config->uldl_host) { $y = new StdClass; $y->cmd = 'upload/download server'; $y->host = (string)$config->uldl_host; if (check_web_server($config->uldl_host)) { //echo "uldl server running\n"; $y->status = 1; } else { //echo "uldl server not running\n"; $y->status = 0; } $x[] = $y; } $daemons = $c->daemons; foreach ($daemons->daemon as $d) { if ($d->host) { $cmd = explode(" ", $d->cmd); $prog = $cmd[0]; $y = new StdClass; $y->cmd = (string)$d->cmd; $y->host = (string)$d->host; if (check_program($d->host, $prog)) { //echo "$d->host $d->cmd is running\n"; $y->status = 1; } else { //echo "$d->host $d->cmd is not running\n"; $y->status = 0; } $x[] = $y; } } $x = serialize($x); file_put_contents("../cache/remote_server_status", $x); echo "--- Finished at ".time_str(time())." ---\n"; } main(); ?>