Index: trunk/ippMonitor/raw/czartool_labels.php
===================================================================
--- trunk/ippMonitor/raw/czartool_labels.php	(revision 29260)
+++ trunk/ippMonitor/raw/czartool_labels.php	(revision 29268)
@@ -25,49 +25,4 @@
 
 menu($myMenu, 'Czartool on '.$lastUpdateTime, 'ipp.css', $ID['link'], $ID['proj']);
-
-$pass = $ID['pass'];
-$proj = $ID['proj'];
-$menu = $ID['menu'];
-
-$selectedStage = $_GET[stage];
-$selectedLabel = $_GET[label];
-$selectedServer = $_GET[server];
-$selectedRevertStage = $_GET[revertstage];
-$selectedRevertMode = $_GET[revertmode];
-$plotType = $_GET[plottype];
-
-if ($selectedLabel == "") { $selectedLabel = "all_stdscience_labels"; }
-if ($selectedStage == "") { $selectedStage = "all_stages"; }
-if ($plotType == "") { $plotType = "linear"; }
-
-$nsStatus = getNightlyScienceStatus($czardb);
-$plotTypeLink = ($plotType == "linear") ? "log" : "linear";
-$link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&label=" . $selectedLabel . "&stage=" . $selectedStage . "&revertstage=" . $stage . "&plottype=$plotTypeLink";
-echo "<p  align=\"center\"> Current status of the IPP as of $lastUpdateTime (faults are shown in parentheses). <br>Documentation can be found <a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Processing\">here</a> and cluster load monitored <a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?r=hour&s=descending&c=IPP%2520Production\">here</a><br>Current nightly science status: $nsStatus<br>Use <a href=\"$link\"> $plotTypeLink</a> plots </p>";
-
-
-// deal with reverts: turn on or off if requested and pass current revert state for this stage onto labels table later
-if ($selectedRevertStage != "" && $selectedRevertMode != "") {
-
-    exec("czartool_revert.pl -t $selectedRevertStage -o $selectedRevertMode", $response, $status);
-    $currentRevertMode;
-    if ($response[0] == "off") $currentRevertMode = 0;
-    else if ($response[0] == "on") $currentRevertMode = 1;
-
-    setRevertStatus($czardb, $selectedRevertStage, $currentRevertMode);
-}
-$debug = 0;
-
-$stdsLabels = getLabels($czardb, "stdscience");
-$distLabels = getLabels($czardb, "distribution");
-$pubLabels = getLabels($czardb, "publishing");
-$updateLabels = getLabels($czardb, "update");
-
-if ($debug) {
-    echo "prog returned $status, and output:<br>";
-    for ($i = 0; $i < count($distLabels); $i++) {
-        echo "$distLabels[$i]<br>";
-    }
-}
 
 $states=array("full","new","drop","wait");
@@ -86,4 +41,55 @@
         "summitcopy");
 
+$pass = $ID['pass'];
+$proj = $ID['proj'];
+$menu = $ID['menu'];
+
+$selectedStage = $_GET[stage];
+$selectedLabel = $_GET[label];
+$selectedServer = $_GET[server];
+$selectedRevertStage = $_GET[revertstage];
+$selectedRevertMode = $_GET[revertmode];
+$plotType = $_GET[plottype];
+$serverCmd = $_GET[servercmd];
+$allServerCmd = $_GET[allservercmd];
+
+if ($selectedLabel == "") { $selectedLabel = "all_stdscience_labels"; }
+if ($selectedStage == "") { $selectedStage = "all_stages"; }
+if ($plotType == "") { $plotType = "linear"; }
+
+$nsStatus = getNightlyScienceStatus($czardb);
+$plotTypeLink = ($plotType == "linear") ? "log" : "linear";
+$link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&label=" . $selectedLabel . "&stage=" . $selectedStage . "&revertstage=" . $stage . "&plottype=$plotTypeLink";
+echo "<p  align=\"center\"> Current status of the IPP as of $lastUpdateTime (faults are shown in parentheses). <br>Documentation can be found <a href=\"http://svn.pan-starrs.ifa.hawaii.edu/trac/ipp/wiki/Processing\">here</a> and cluster load monitored <a href=\"http://ganglia.pan-starrs.ifa.hawaii.edu/?r=hour&s=descending&c=IPP%2520Production\">here</a><br>Current nightly science status: $nsStatus<br>Use <a href=\"$link\"> $plotTypeLink</a> plots </p>";
+
+
+// deal with reverts: turn on or off if requested and pass current revert state for this stage onto labels table later
+if ($selectedRevertStage && $selectedRevertMode) turnRevertsOnOff($czardb, $selectedRevertStage, $selectedRevertMode);
+
+// tell selected server to stop or run
+if ($selectedServer && $serverCmd) serverStopRun($czardb, $selectedServer,  $serverCmd);
+
+// tell all servers to stop or run
+if ($allServerCmd) {
+
+    foreach ($servers as &$server) serverStopRun($czardb, $server,  $allServerCmd);
+}
+
+
+$debug = 0;
+
+$stdsLabels = getLabels($czardb, "stdscience");
+$distLabels = getLabels($czardb, "distribution");
+$pubLabels = getLabels($czardb, "publishing");
+$updateLabels = getLabels($czardb, "update");
+
+if ($debug) {
+    echo "prog returned $status, and output:<br>";
+    for ($i = 0; $i < count($distLabels); $i++) {
+        echo "$distLabels[$i]<br>";
+    }
+}
+
+
 // set up the form
 echo "<form action=\"czartool_labels.php\" method=\"POST\">\n";
@@ -95,51 +101,51 @@
 
 echo "<table>\n";
-  echo "<tr>\n";
-    echo "<td>\n";
-      echo "<img src=\"czartool_getplot.php?type=t&label=$selectedLabel&stage=$selectedStage&plottype=$plotType\"><br>";
-    echo "</td>\n";
-
-    echo "<td> \n";
-      createLabelsTable($pass, $proj, $czardb, "stdscience", $stdsLabels, $distLabels, $pubLabels, $stages, $states, "new", $selectedLabel, $selectedStage, $plotType);
-    echo "</td>\n";
-  echo "</tr>\n";
-
-  echo "<tr>\n";
-    echo "<td>\n";
-      echo "<img src=\"czartool_getplot.php?type=h&label=$selectedLabel&stage=$selectedStage&plottype=linear\"><br>";
-    echo "</td>\n";
-
-    echo "<td> \n";
-      createLabelsTable($pass, $proj, $czardb, "update", $updateLabels, $distLabels, $pubLabels, $stages, $states, "new", $selectedLabel, $selectedStage, $plotType);
-    echo "</td>\n";
-  echo "</tr>\n";
-
-  echo "<tr>\n";
-    echo "<table>\n";
-      echo "<tr valign=top>\n";
-        echo "<td> \n";
-          echo "<img src=\"czartool_getplot.php?type=s\"><br>";
-        echo "</td>\n";
-        echo "<td>\n";
-          createServersTable($pass, $proj,$czardb, $servers, $selectedLabel, $selectedStage, $plotType);
-        echo "</td>\n";
-
-        echo "<td> \n";
-          $today = date("Y-m-d");
-          showSummitData($gpc1db, $today);
-        echo "</td>\n";
-      echo "</tr>\n";
-    echo "</table>\n";
-
-    echo "<table>\n";
-      echo "<tr valign=top>\n";
-        echo "<td> \n";
-        echo "</td>\n";
-        echo "<td>\n";
-      if ($selectedServer) showServerStatus($selectedServer);
-        echo "</td>\n";
-      echo "</tr>\n";
-    echo "</table>\n";
-  echo "</tr>\n";
+echo "<tr>\n";
+echo "<td>\n";
+echo "<img src=\"czartool_getplot.php?type=t&label=$selectedLabel&stage=$selectedStage&plottype=$plotType\"><br>";
+echo "</td>\n";
+
+echo "<td> \n";
+createLabelsTable($pass, $proj, $czardb, "stdscience", $stdsLabels, $distLabels, $pubLabels, $stages, $states, "new", $selectedLabel, $selectedStage, $plotType);
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<td>\n";
+echo "<img src=\"czartool_getplot.php?type=h&label=$selectedLabel&stage=$selectedStage&plottype=linear\"><br>";
+echo "</td>\n";
+
+echo "<td> \n";
+createLabelsTable($pass, $proj, $czardb, "update", $updateLabels, $distLabels, $pubLabels, $stages, $states, "new", $selectedLabel, $selectedStage, $plotType);
+echo "</td>\n";
+echo "</tr>\n";
+
+echo "<tr>\n";
+echo "<table>\n";
+echo "<tr valign=top>\n";
+echo "<td> \n";
+echo "<img src=\"czartool_getplot.php?type=s\"><br>";
+echo "</td>\n";
+echo "<td>\n";
+createServersTable($pass, $proj,$czardb, $servers, $selectedLabel, $selectedStage, $plotType);
+echo "</td>\n";
+
+echo "<td> \n";
+$today = date("Y-m-d");
+showSummitData($gpc1db, $today);
+echo "</td>\n";
+echo "</tr>\n";
+echo "</table>\n";
+
+echo "<table>\n";
+echo "<tr valign=top>\n";
+echo "<td> \n";
+echo "</td>\n";
+echo "<td>\n";
+if ($selectedServer && !$serverCmd) showServerStatus($selectedServer);
+echo "</td>\n";
+echo "</tr>\n";
+echo "</table>\n";
+echo "</tr>\n";
 echo "</table>\n";
 
@@ -258,5 +264,5 @@
     write_header_cell($class, "Label (in order of priority)");
     foreach ($stages as &$stage) {
-        
+
         if ($stage == $selectedStage) $link = "";
         else $link = "czartool_labels.php?pass=" . $pass . "&proj=" . $proj . "&label=" . $selectedLabel . "&stage=".$stage."&plottype=".$plotType;
@@ -385,4 +391,19 @@
 
     return $row[0];
+}
+
+###########################################################################
+#
+#  Turns reverts on or off for a given task
+#
+###########################################################################
+function turnRevertsOnOff($db, $stage, $mode) {
+
+    exec("czartool_revert.pl -t $stage -o $mode", $response, $status);
+    $currentRevertMode;
+    if ($response[0] == "off") $currentRevertMode = 0;
+    else if ($response[0] == "on") $currentRevertMode = 1;
+
+    setRevertStatus($db, $stage, $currentRevertMode);
 }
 
@@ -449,18 +470,40 @@
     write_header_cell($class, "Server");
     write_header_cell($class, "Alive?");
-    write_header_cell($class, "Scheduler running?");
+    $link = "czartool_labels.php?pass=".$pass."&proj=".$proj."&label=".$selectedLabel."&stage=".$selectedStage."&plottype=".$plotType."&allservercmd=stop";
+    write_table_cell($class, '%s', $link, "Stop all");
+    $link = "czartool_labels.php?pass=".$pass."&proj=".$proj."&label=".$selectedLabel."&stage=".$selectedStage."&plottype=".$plotType."&allservercmd=run";
+    write_table_cell($class, '%s', $link, "Run all");
     echo "</tr>\n";
 
     foreach ($servers as &$server) {
 
+        getServerStatus($db, $server, $alive, $running);
+
+        echo "<tr><td></td>\n";
         $link = "czartool_labels.php?pass=".$pass."&proj=".$proj."&server=".$server."&label=".$selectedLabel."&stage=".$selectedStage."&plottype=".$plotType;
-        //      $link = "";
-
-        getServerStatus($db, $server, $alive, $running);
-
-        echo "<tr><td></td>\n";
         write_table_cell($class, '%s', $link, $server);
         write_table_cell($class, '%s', "", $alive ? "yes" : "NO");
-        write_table_cell($class, '%s', "", $running ? "yes" : "NO");
+
+        if ($alive) {
+
+            $link = "czartool_labels.php?pass=".$pass."&proj=".$proj."&label=".$selectedLabel."&stage=".$selectedStage."&plottype=".$plotType."&server=".$server."&servercmd=";
+            if ($running)  {
+
+                $link = $link . "stop";
+                write_table_cell($class, '%s', $link, "stop");
+                write_table_cell($class, '%s', "", "running");
+            }
+            else {
+
+                $link = $link . "run";
+                write_table_cell($class, '%s', "", "stopped");
+                write_table_cell($class, '%s', $link, "run");
+            }
+        }
+        else {
+        
+            write_table_cell($class, '%s', "", "");
+            write_table_cell($class, '%s', "", "");
+        }
         echo "</tr>\n";
     }
@@ -468,4 +511,37 @@
     echo "</table>\n";
 }
+
+###########################################################################
+#
+#  Commands a server to stop or run 
+#
+###########################################################################
+function serverStopRun($db, $server, $cmd) {
+
+    exec("czartool_serverstoprun.pl -s $server -c $cmd", $response, $status);
+    $alive = 0;
+    $running = 0;
+    if ($response[0] == "running") {$alive = 1; $running = 1;}
+    else if ($response[0] == "stopped") {$alive = 1; $running = 0;} 
+    else if ($response[0] == "dead") {$alive = 0; $running = 0;}
+    setServerStatus($db, $server, $alive, $running);
+    print "$cmd $server $alive, $running<br>";
+}
+
+###########################################################################
+#
+# Sets server status 
+#
+###########################################################################
+function setServerStatus($db, $server, $alive, $running) {
+
+    $sql = "INSERT INTO servers (server, alive, running) VALUES ('$server', $alive, $running)";
+
+    if ($debug) {echo "$sql<br>";}
+
+    $qry = $db->query($sql);
+    if (dberror($qry)) {echo "<b>error with $sql </b><br>\n";}
+}
+
 
 ###########################################################################
