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

finisheshed daemon-control javascript

parent 620a1357
...@@ -4,13 +4,26 @@ ...@@ -4,13 +4,26 @@
<style></style> <style></style>
<script language="JavaScript"> <script language="JavaScript">
var initialized = false; var initialized = false;
var seq_counter = 0;
var duration = 100; var pre_delay;// = 5.0;
var pre_delay = 5.0; var duration;// = 100;
var ffc_period = 30; var duration_eo;// = 100;
var run = true; var ffc;// = false;
var want_run = true; var ffc_period;// = 30;
var next_ffc_sec = 0; // will be overdue var ffc_groups;// = 2;
var ffc_frames;// = 8;
var compressor_run;// = false;
var debug;// = 0;
var sequence_num;// = 0;
var last_ffc;// = 0;
var time_to_ffc;// = 0;
var capture_run;// = 0;
var want_run;
var request_num = 0;
var update_editable = true;
var apply_pending = false;
function parse_response(resp){ function parse_response(resp){
var result = ""; var result = "";
console.log(resp); console.log(resp);
...@@ -41,134 +54,235 @@ function send_request(rq,callback){ ...@@ -41,134 +54,235 @@ function send_request(rq,callback){
request.send(); request.send();
} }
function sendStatusRequest(){
var url = "http://192.168.0.41/lwir16/lwir16.php?daemon=status";
function init_lwir(){ if (apply_pending) {
send_request("http://192.168.0.41/lwir16/lwir16.php?cmd=init",init_response); var mod_pars = modParameters();
document.getElementById('idpre_delay').value= ""+pre_delay; // console.log('mod_pars members:');
document.getElementById('idduration').value= ""+duration; for(const p in mod_pars) {
document.getElementById('idffc_period').value= ""+ffc_period; url +="&"+p+"="+mod_pars[p];
}
update_editable = true; // will update edited fields
apply_pending = false;
}
send_request(url,parseStatusResponse);
} }
function init_response(resp){
initialized = true; function sendRestartRequest(){
// alert ("LWIR16 initialized"); var url = "http://192.168.0.41/lwir16/lwir16.php?daemon=restart&cmd=STATUS";
document.getElementById('idStartStop').innerHTML= run? 'STOP': 'START'; send_request(url,parseStatusResponse);
console.log("LWIR16 initialized");
want_run = run;
captureSet();
} }
function capture_response(resp){
document.getElementById('idcount').value=""+seq_counter;
// document.getElementById('idcount').innerHTML=""+seq_counter; function parseStatusResponse(resp){
//id="idcount" var result = "";
seq_counter++; // console.log(resp);
if (want_run) { if (update_editable) {
run = true; if (resp.getElementsByTagName("pre_delay").length!=0){
// send_request("http://192.168.0.41/lwir16/lwir16.php?cmd=capture&duration="+duration+"&pre_delay="+pre_delay,capture_response); pre_delay = parseFloat(resp.getElementsByTagName("pre_delay")[0].childNodes[0].nodeValue);
captureSet(); document.getElementById("idpre_delay").value = pre_delay;
} else { }
run = false;
document.getElementById('idStartStop').innerHTML='START'; if (resp.getElementsByTagName("duration").length!=0){
duration = parseInt(resp.getElementsByTagName("duration")[0].childNodes[0].nodeValue);
document.getElementById("idduration").value = duration;
}
if (resp.getElementsByTagName("duration_eo").length!=0){
duration_eo = parseInt(resp.getElementsByTagName("duration_eo")[0].childNodes[0].nodeValue);
document.getElementById("idduration_eo").value = duration_eo;
} }
}
function updatePreDelay(field_id){ if (resp.getElementsByTagName("ffc").length!=0){
var v=parseDouble(document.getElementById(field_id).value); ffc = parseInt(resp.getElementsByTagName("ffc")[0].childNodes[0].nodeValue);
if (isNaN(v)){ document.getElementById("idffc").checked = ffc > 0;
v = 5.0; }
}
pre_delay = v;
document.getElementById(field_id).value=""+v;
}
if (resp.getElementsByTagName("ffc_period").length!=0){
ffc_period = parseFloat(resp.getElementsByTagName("ffc_period")[0].childNodes[0].nodeValue);
document.getElementById("idffc_period").value = ffc_period;
}
if (resp.getElementsByTagName("ffc_groups").length!=0){
ffc_groups = parseInt(resp.getElementsByTagName("ffc_groups")[0].childNodes[0].nodeValue);
document.getElementById("idffc_groups").value = ffc_groups;
}
if (resp.getElementsByTagName("ffc_frames").length!=0){
ffc_frames = parseInt(resp.getElementsByTagName("ffc_frames")[0].childNodes[0].nodeValue);
document.getElementById("idffc_frames").value = ffc_frames;
}
function updateDuration(field_id){ if (resp.getElementsByTagName("compressor_run").length!=0){
var v=parseInt(document.getElementById(field_id).value); compressor_run = parseInt(resp.getElementsByTagName("compressor_run")[0].childNodes[0].nodeValue);
if (isNaN(v)){ document.getElementById("idcompressor_run").checked = compressor_run > 0;
v = 100; }
if (resp.getElementsByTagName("debug").length!=0){
debug = parseInt(resp.getElementsByTagName("debug")[0].childNodes[0].nodeValue);
document.getElementById("iddebug").value = debug;
}
}
if (resp.getElementsByTagName("sequence_num").length!=0){
sequence_num = parseInt(resp.getElementsByTagName("sequence_num")[0].childNodes[0].nodeValue);
document.getElementById("idsequence_num").value = sequence_num;
} }
duration = v;
document.getElementById(field_id).value=""+v;
}
function updateFFCPeriod(field_id){ if (resp.getElementsByTagName("last_ffc").length!=0){
var v=parseInt(document.getElementById(field_id).value); last_ffc = parseFloat(resp.getElementsByTagName("last_ffc")[0].childNodes[0].nodeValue);
if (isNaN(v)){ document.getElementById("idlast_ffc").value = last_ffc;
v = 100; }
if (resp.getElementsByTagName("time_to_ffc").length!=0){
time_to_ffc = parseFloat(resp.getElementsByTagName("time_to_ffc")[0].childNodes[0].nodeValue);
document.getElementById("idtime_to_ffc").value = time_to_ffc;
}
if (resp.getElementsByTagName("capture_run").length!=0){
capture_run = parseInt(resp.getElementsByTagName("capture_run")[0].childNodes[0].nodeValue);
document.getElementById("idcapture_run").checked = capture_run > 0;
if (update_editable) {
document.getElementById("idStartStop").innerHTML=capture_run?"Stop":"Start";
document.getElementById("idStartStop").disabled = false;
want_run = capture_run;
}
}
if (update_editable) {
document.getElementById('idApply').innerHTML='Apply';
document.getElementById('idApply').disabled= false;
document.getElementById('idRestart').innerHTML='Restart';
document.getElementById('idRestart').disabled= false;
} }
ffc_period = v; request_num++;
document.getElementById(field_id).value=""+v; document.getElementById("idrequest_num").value = request_num;
update_editable = false;
sendStatusRequest();
} }
function modParameters(){
function clickedRun(field_id){ var mod_pars={};
want_run = !run; if (document.getElementById("idpre_delay").value != (""+pre_delay)){
// alert("want_run="+want_run); mod_pars['pre_delay'] = document.getElementById("idpre_delay").value;
if (want_run){ }
run = true; if (document.getElementById("idduration").value != (""+duration)){
document.getElementById(field_id).innerHTML='STOP'; mod_pars['duration'] = document.getElementById("idduration").value;
captureSet(); }
// send_request("http://192.168.0.41/lwir16/lwir16.php?cmd=capture&duration="+duration+"&pre_delay="+pre_delay,init_response); if (document.getElementById("idduration_eo").value != (""+duration_eo)){
mod_pars['duration_eo'] = document.getElementById("idduration_eo").value;
}
if (document.getElementById("idffc").checked != ffc){
mod_pars['ffc'] = document.getElementById("idffc").checked?"1":"0";
}
if (document.getElementById("idffc_period").value != (""+ffc_period)){
mod_pars['ffc_period'] = document.getElementById("idffc_period").value;
}
if (document.getElementById("idffc_groups").value != (""+ffc_groups)){
mod_pars['ffc_groups'] = document.getElementById("idffc_groups").value;
}
if (document.getElementById("idffc_frames").value != (""+ffc_frames)){
mod_pars['ffc_frames'] = document.getElementById("idffc_frames").value;
}
if (document.getElementById("idcompressor_run").checked != compressor_run){
mod_pars['compressor_run'] = document.getElementById("idcompressor_run").checked?"1":"0";
}
if (want_run != capture_run) {
mod_pars['cmd'] = want_run? "START":"STOP";
} }
console.log('mod_pars members:');
for(const p in mod_pars) {
console.log (p, mod_pars[p]);
}
return mod_pars;
} }
function setPending(){
document.getElementById('idApply').innerHTML='Pending';
document.getElementById('idApply').disabled= true;
document.getElementById("idStartStop").innerHTML="Pending";
document.getElementById("idStartStop").disabled = true;
document.getElementById("idRestart").innerHTML="Pending";
document.getElementById("idRestart").disabled = true;
apply_pending = true;
}
function captureSet(){ function clickedRestart(){
var now_sec = 0.001 * ((new Date()).getTime()); setPending();
var ffc_cmd = ""; sendRestartRequest();
if (now_sec > next_ffc_sec) { }
ffc_cmd = "&ffc"; function clickedRun(){
next_ffc_sec = now_sec + ffc_period; want_run = !capture_run;
document.getElementById("idffc").value="NOW"; setPending();
} else { }
document.getElementById('idffc').value=""+ (0.01 * Math.round(100*(next_ffc_sec - now_sec)));
} function clickedApply(){
send_request("http://192.168.0.41/lwir16/lwir16.php?cmd=capture&duration="+duration+"&pre_delay="+pre_delay+ffc_cmd,capture_response); setPending();
} }
</script> </script>
</head> </head>
<body onload='init_lwir()'> <body onload='sendStatusRequest()'>
<table> <table>
<tr>
<td>Pre-capture delay</td><td> <tr><td>
<input id="idpre_delay" name="npre_delay" size="10" maxlength="10" value="?" onchange="updatePreDelay('idpre_delay')" type="text"> <button id="idStartStop" name = "nStartStop" onclick="clickedRun()" disabled="true">???</button>
</td> </td><td>
<td><button id="idStartStop" name = "nStartStop" onclick="clickedRun('idStartStop')">???</button></td> <button id="idApply" name = "nApply" onclick="clickedApply()" disabled = "true">???</button>
</tr> </td><td>&nbsp;</td> <td>&nbsp;</td><td>&nbsp;</td>
<tr> <td><button id="idRestart" name = "nRestart" onclick="clickedRestart()" >Restart</button></td></tr>
<td>Sequence length (@60Hz)</td><td>
<input id="idduration" name="nduration" size="10" maxlength="10" value="?" onchange="updateDuration('idduration')" type="text"> <tr><td>Pre-capture delay</td><td>
</td> <input id="idpre_delay" name="npre_delay" size="10" maxlength="10" value="?" type="text">
<td>frames</td> </td><td> sec</td><td>Sequence count</td><td>
</tr> <input id="idsequence_num" name="nsequence_num" size="10" maxlength="10" value="?" type="text" disabled >
</td><td>captured</td></tr>
<tr>
<td>FFC period</td><td> <tr><td>Sequence length (@60Hz)</td><td>
<input id="idffc_period" name="nffc_period" size="10" maxlength="10" value="?" onchange="updateFFCPeriod('idffc_period')" type="text"> <input id="idduration" name="nduration" size="10" maxlength="10" value="?" type="text">
</td> </td><td>frames</td><td>Request count</td><td>
<td>sec</td> <input id="idrequest_num" name="nrequest_num" size="10" maxlength="10" value="?" type="text" disabled >
</tr> </td><td>&nbsp;</td></tr>
<tr><td>Sequence length (@10Hz)</td><td>
<input id="idduration_eo" name="nduration_eo" size="10" maxlength="10" value="?" type="text">
</td><td>frames</td><td>Capture run</td><td>
<input id="idcapture_run" name="ncapture_run" type="checkbox" disabled>
</td><td>&nbsp;</td></tr>
<tr> <tr><td>FFC</td><td>
<td>Sequence count</td><td> <input id="idffc" name="nffc" type="checkbox">
<input id="idcount" name="ncount" size="10" maxlength="10" value="?" type="text" disabled > </td><td>&nbsp;</td><td>Last FFC</td><td>
</td> <input id="idlast_ffc" name="nlast_ffc" size="10" maxlength="10" value="?" type="text" disabled >
<td>captured</td> </td><td>sec</td></tr>
</tr>
<tr>
<td>Time to ffc</td><td>
<input id="idffc" name="ncount" size="10" maxlength="10" value="?" type="text" disabled >
</td>
<td>sec</td>
</tr>
<tr><td>FFC period</td><td>
<input id="idffc_period" name="nffc_period" size="10" maxlength="10" value="?" type="text">
</td><td>sec</td><td>Time to FFC</td><td>
<input id="idtime_to_ffc" name="ntime_to_ffc" size="10" maxlength="10" value="?" type="text" disabled >
</td><td>sec</td></tr>
<tr><td>FFC groups</td><td>
<select id="idffc_groups" name="nffc_groups" value="?">
<option value="1">1</option>
<option value="2">2</option>
<option value="4" selected="selected">4</option>
</select>
</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>FFC frames</td><td>
<input id="idffc_frames" name="nffc_frames" size="10" maxlength="10" value="?" type="text">
</td><td>frames</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>Compress after Init</td><td>
<input id="idcompressor_run" name="ncompressor_run" type="checkbox">
</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>Debug level</td><td>
<input id="iddebug" name="ndebug" size="10" maxlength="10" value="?" type="text">
</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td></tr>
</table> </table>
</body> </body>
</html> </html>
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