Commit 3b0788d7 authored by Andrey Filippov's avatar Andrey Filippov

finisheshed daemon-control javascript

parent 620a1357
This diff is collapsed.
ips = "192.168.0.41,192.168.0.42,192.168.0.43,192.168.0.44,192.168.0.45" ips = "192.168.0.41,192.168.0.42,192.168.0.43,192.168.0.44,192.168.0.45"
duration = 100 duration = 100
pre_delay = 5.0 pre_delay = 3.0
ffc_period = 300.0 ffc_period = 30.0
ffc_groups = 2 ffc_groups = 2
ffc_frames = 8 ffc_frames = 8
ffc = 1 ffc = 1
......
...@@ -63,12 +63,14 @@ ...@@ -63,12 +63,14 @@
define('DAEMON_CTRL', 'daemon'); define('DAEMON_CTRL', 'daemon');
define('DAEMON_CTRL_CMDS', 'cmd'); //comma-separated commands to be sent to the daemon define('DAEMON_CTRL_CMDS', 'cmd'); //comma-separated commands to be sent to the daemon
// print_r($_GET); // magic
// exit(0); // magic
// initializations before reading lwir16.ini // initializations before reading lwir16.ini
$GLOBALS[COMPRESSOR_RUN] = 0; $GLOBALS[COMPRESSOR_RUN] = 0;
$GLOBALS[DURATION] = 100; $GLOBALS[DURATION] = 100;
$GLOBALS[PRE_DELAY] = 5.0; // seconds $GLOBALS[PRE_DELAY] = 5.0; // seconds
$GLOBALS[FFC] = false; // perform FFC before starting a sequence (and before delay? reduce delay ?) $GLOBALS[FFC] = 0; // perform FFC before starting a sequence (and before delay? reduce delay ?)
// $ffc = false; // $ffc = false;
$GLOBALS[FFC_GROUPS] = 2; // 1/2/4 - do not run FFC on all channels simultaneously (43 failed) $GLOBALS[FFC_GROUPS] = 2; // 1/2/4 - do not run FFC on all channels simultaneously (43 failed)
$GLOBALS[FFC_FRAMES] = 8; // read actual? $GLOBALS[FFC_FRAMES] = 8; // read actual?
...@@ -108,7 +110,7 @@ ...@@ -108,7 +110,7 @@
} else if ($key == 'run'){ } else if ($key == 'run'){
$GLOBALS[COMPRESSOR_RUN] = 2; $GLOBALS[COMPRESSOR_RUN] = 2;
} else if ($key == 'ffc'){ } else if ($key == 'ffc'){
$GLOBALS[FFC] = true; $GLOBALS[FFC] = 1;
if ($value) { // string "0" will also be false if ($value) { // string "0" will also be false
$v = (int) $value; $v = (int) $value;
if (($v == 1) || ($v == 2) || ($v == 4)){ if (($v == 1) || ($v == 2) || ($v == 4)){
...@@ -117,6 +119,10 @@ ...@@ -117,6 +119,10 @@
} }
} }
} }
// print_r($lswir16cmds);
// exit(0);
if (isset($duration) && !isset($duration_eo)){ if (isset($duration) && !isset($duration_eo)){
$duration_eo = (int) ($duration/EO_DECIMATE + 1); $duration_eo = (int) ($duration/EO_DECIMATE + 1);
} }
...@@ -124,7 +130,8 @@ ...@@ -124,7 +130,8 @@
if (isset($duration_eo)) $GLOBALS[DURATION_EO] = $duration_eo; if (isset($duration_eo)) $GLOBALS[DURATION_EO] = $duration_eo;
if ($GLOBALS[DURATION] < 1) $GLOBALS[DURATION] = 1; if ($GLOBALS[DURATION] < 1) $GLOBALS[DURATION] = 1;
if ($GLOBALS[DURATION_EO] < 1) $GLOBALS[DURATION_EO] = 1; if ($GLOBALS[DURATION_EO] < 1) $GLOBALS[DURATION_EO] = 1;
if (isset($lswir16cmds)){ if (isset($lswir16cmds)){
$lwir_trig_dly = 0; $lwir_trig_dly = 0;
$eo_quality = 97; $eo_quality = 97;
...@@ -180,7 +187,7 @@ ...@@ -180,7 +187,7 @@
} else if ($cmd == 'capture'){ } else if ($cmd == 'capture'){
$results = runCapture($GLOBALS[FFC], $nowait); // runCapture($run_ffc, $nowait = 0, $debug=0) $results = runCapture($GLOBALS[FFC], $nowait); // runCapture($run_ffc, $nowait = 0, $debug=0)
$xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><capture_range/>"); $xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><capture_range/>");
$xml->addChild ('ffc', $GLOBALS[FFC] ? 'true':'false'); $xml->addChild ('ffc', $GLOBALS[FFC]);
$xml->addChild (FFC_GROUPS,$GLOBALS[FFC_GROUPS]); $xml->addChild (FFC_GROUPS,$GLOBALS[FFC_GROUPS]);
$xml->addChild (FFC_FRAMES,$GLOBALS[FFC_FRAMES]); $xml->addChild (FFC_FRAMES,$GLOBALS[FFC_FRAMES]);
for ($i = 0; $i<count($GLOBALS[IPS]); $i++){ for ($i = 0; $i<count($GLOBALS[IPS]); $i++){
...@@ -591,11 +598,9 @@ EOT; ...@@ -591,11 +598,9 @@ EOT;
$xml_state->addChild (trim($kv[0]),trim($kv[1])); $xml_state->addChild (trim($kv[0]),trim($kv[1]));
} }
} }
$xml->addChild (SECUENCE_NUM, $GLOBALS[SECUENCE_NUM]); $GLOBALS[TIME_TO_FFC] = $GLOBALS[LAST_FFC] + $GLOBALS[FFC_PERIOD] - time();
if ($GLOBALS[FFC]) { $xml->addChild (SECUENCE_NUM, $GLOBALS[SECUENCE_NUM]);
$GLOBALS[TIME_TO_FFC] = $GLOBALS[LAST_FFC] + $GLOBALS[FFC_PERIOD] - time(); $xml->addChild (TIME_TO_FFC, $GLOBALS[TIME_TO_FFC]);
$xml->addChild (TIME_TO_FFC, $GLOBALS[TIME_TO_FFC]);
}
$xml->addChild (IPS, implode(',',$GLOBALS[IPS])); $xml->addChild (IPS, implode(',',$GLOBALS[IPS]));
$xml->addChild (DURATION, $GLOBALS[DURATION]); $xml->addChild (DURATION, $GLOBALS[DURATION]);
$xml->addChild (DURATION_EO, $GLOBALS[DURATION_EO]); $xml->addChild (DURATION_EO, $GLOBALS[DURATION_EO]);
...@@ -652,7 +657,9 @@ EOT; ...@@ -652,7 +657,9 @@ EOT;
if ($GLOBALS[DEBUG]){ if ($GLOBALS[DEBUG]){
print_r($ini); print_r($ini);
} }
unset ($GLOBALS[DAEMON_CMD]); unset ($GLOBALS[DAEMON_CMD]);
applyConf ($ini); // update $GLOBALS applyConf ($ini); // update $GLOBALS
$from_pipe = true; $from_pipe = true;
if ($GLOBALS[DEBUG] > 1){ if ($GLOBALS[DEBUG] > 1){
...@@ -726,7 +733,7 @@ EOT; ...@@ -726,7 +733,7 @@ EOT;
if (isset($arr[DAEMON_CMD])) $GLOBALS[DAEMON_CMD] = $arr[DAEMON_CMD]; if (isset($arr[DAEMON_CMD])) $GLOBALS[DAEMON_CMD] = $arr[DAEMON_CMD];
if (isset($arr[DEBUG])) $GLOBALS[DEBUG] = (int) $arr[DEBUG]; if (isset($arr[DEBUG])) $GLOBALS[DEBUG] = (int) $arr[DEBUG];
if (isset($arr[COMPRESSOR_RUN])) $GLOBALS[COMPRESSOR_RUN] = (int) $arr[COMPRESSOR_RUN]; // only after INIT if (isset($arr[COMPRESSOR_RUN])) $GLOBALS[COMPRESSOR_RUN] = (int) $arr[COMPRESSOR_RUN]; // only after INIT
if (isset($arr[FFC])) $GLOBALS[FFC] = $arr[FFC]?true:false; // only after INIT if (isset($arr[FFC])) $GLOBALS[FFC] = $arr[FFC]?1:0;
} }
/** /**
...@@ -736,41 +743,88 @@ EOT; ...@@ -736,41 +743,88 @@ EOT;
*/ */
function daemon_control($cmd) function daemon_control($cmd)
{ {
/* // echo "<pre>\n";
echo "<pre>\n"; // print_r($_SERVER);
print_r($_SERVER); // echo "</pre>\n";
echo "</pre>\n"; // exit(0);
exit(0);
*/
// see if it already running // see if it already running
$debug = 0;
$max_wait = 10; // seconds $max_wait = 10; // seconds
// $sript_name = substr($_SERVER['SCRIPT_NAME'], 1); // remove leading '/' // $sript_name = substr($_SERVER['SCRIPT_NAME'], 1); // remove leading '/'
$sript_path = $_SERVER['SCRIPT_FILENAME']; $sript_path = $_SERVER['SCRIPT_FILENAME'];
$sript_name = basename($sript_path); $sript_name = basename($sript_path);
$pids = getPIDByName($sript_name, 'php', $active_only = false); $pids = getPIDByName($sript_name, 'php', $active_only = false);
// echo "<pre>0:\n";
// print_r($pids);
// echo "</pre>\n";
// Stop if needed // Stop if needed
if ($pids && (($cmd == 'restart') || ($cmd == 'stop'))) { if ($pids && (($cmd == 'restart') || ($cmd == 'stop'))) {
$mode = 0600; // below - does not work with non-blocking "w+", will take care later
if (! file_exists(PIPE_CMD)) { /*
// create the pipe * $mode = 0600;
umask(0); * if (! file_exists(PIPE_CMD)) {
posix_mkfifo(PIPE_CMD, $mode); * // create the pipe
* umask(0);
* posix_mkfifo(PIPE_CMD, $mode);
* }
* $f = fopen(PIPE_CMD, "w+"); // make it non-blocking as the receiver may be hang
* fwrite($f, "CMD=EXIT");
* fclose($f);
* for ($i = 0; $pids && ($i < $max_wait); $i ++) {
* sleep (1);
* $pids = getPIDByName($sript_name, 'php', $active_only = false);
* }
*/
// if(file_exists(PIPE_CMD)) unlink(PIPE_CMD); //delete pipe
// if(file_exists(PIPE_RESPONSE)) unlink(PIPE_RESPONSE); //delete pipe
// print_r($pids);
if ($debug) {
echo "<pre>1:\n";
print_r($pids);
echo "</pre>\n";
}
if ($pids) { // did not exit, ask politely
foreach ($pids as $proc) {
exec('kill ' . $proc['pid'], $output, $retval);
}
} }
$f = fopen(PIPE_CMD, "w+"); // make it non-blocking as the receiver may be hang if ($debug) {
fwrite($f, "CMD=EXIT"); echo "<pre>2:\n";
fclose($f); print_r($pids);
for ($i = 0; $i < $max_wait; $i ++) { echo "</pre>\n";
}
for ($i = 0; $pids && ($i < $max_wait); $i ++) {
sleep (1);
$pids = getPIDByName($sript_name, 'php', $active_only = false); $pids = getPIDByName($sript_name, 'php', $active_only = false);
if (! $pid)
break;
} }
if ($pids) { // did not exit if ($debug) {
echo "<pre>3:\n";
print_r($pids);
echo "</pre>\n";
}
if ($pids) { // did not exit - just kill them
foreach ($pids as $proc) { foreach ($pids as $proc) {
exec('kill -9 ' . $proc['pid'], $output, $retval); exec('kill -9 ' . $proc['pid'], $output, $retval);
} }
} }
$pids = getPIDByName($sript_name, 'php', $active_only = false);
if ($debug) {
echo "<pre>4\n";
print_r($pids);
echo "</pre>\n";
}
} }
$pids = getPIDByName($sript_name, 'php', $active_only = false); $pids = getPIDByName($sript_name, 'php', $active_only = false);
// print_r($pids);
if (!$pids && ($cmd != 'stop')) { if (!$pids && ($cmd != 'stop')) {
exec($sript_path . ' > /dev/null 2>&1 &'); // "> /dev/null 2>&1 &" makes sure it is really really run as a background job that does not wait for input exec($sript_path . ' > /dev/null 2>&1 &'); // "> /dev/null 2>&1 &" makes sure it is really really run as a background job that does not wait for input
// wait it to run // wait it to run
...@@ -780,8 +834,16 @@ EOT; ...@@ -780,8 +834,16 @@ EOT;
} }
} }
/*
$exit_ps = ($cmd == 'stop') || !pids ; // nothing else to do if it is not running
if (($cmd == 'restart') || ($cmd == 'start')){
if (!isset ($_GET[DAEMON_CTRL_CMDS]) && !isset ($_GET[DAEMON_CMD])){ // no other commands (like "status")
$exit_ps = true;
}
}
*/
if (($cmd == 'restart') || ($cmd == 'start') || ($cmd == 'stop') || !pids) { // nothing else to do if it is not running if (($cmd == 'restart') || ($cmd == 'start') || ($cmd == 'stop') || !pids) { // nothing else to do if it is not running
// just respond with $pids xml // if ($exit_ps) { // nothing else to do if it is not running just respond with $pids xml
$xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><lwir16_daemon_status/>"); $xml = new SimpleXMLElement("<?xml version='1.0' standalone='yes'?><lwir16_daemon_status/>");
if ($pids) { if ($pids) {
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment