/** * Handles DaemonCore requests. * * @param string $Input * @return boolean */ public static function Start($Input) { System_Daemon::debug('Starting "DaemonCore::Start" subprocess.'); $retVal = null; $Input = explode(" ", $Input, 2); switch ($Input[0]) { case 'checkAll': $retVal = self::checkAllData(); break; case 'Restart': System_Daemon::info('Running Restart subprocess.'); SocketHandler::Close(); System_Daemon::restart(); break; case 'SaveConfig': System_Daemon::debug('Running SaveConfig subprocess.'); if (isset($Input[1]) && is_array($Input[1])) { foreach (json_decode(trim($Input[1])) as $name => $wert) { if (isset(DaemonConfig::$cfg->{$name})) { DaemonConfig::$cfg->{$name} = $wert; } } } DaemonConfig::Save(); DaemonConfig::SaveOldConfig(); System_Daemon::debug('Finished SaveConfig subprocess.'); $retVal = true; break; case 'Setup': if (file_exists(dirname(__FILE__) . '/DaemonCoreSetup.php')) { require_once dirname(__FILE__) . '/DaemonCoreSetup.php'; if (isset($Input[1]) && $Input[1] != '') { $retVal = Setup($Input[1]); } } else { $retVal = false; } break; default: System_Daemon::warning("Don't know what to do with " . $Input[0]); $retVal = false; break; } System_Daemon::debug('Finished "DaemonCore::Start" subprocess.'); return $retVal; }
public function execute() { ob_start(); if ($this->runmodes['help'] == true) { echo 'Usage: ' . $argv[0] . ' [runmodes]' . "\n"; echo 'Available runmodes:' . "\n"; foreach ($this->runmodes as $runmode) { echo ' --' . $runmode . "\n"; } die; } System_Daemon::setOptions($this->options); if (!$this->runmodes['no-daemon']) { System_Daemon::start(); } if (!$this->runmodes['write-initd']) { System_Daemon::info('not writing an init.d script this time'); } else { if (($initd_location = System_Daemon::writeAutoRun()) === false) { System_Daemon::notice('unable to write init.d script'); } else { System_Daemon::info('sucessfully written startup script: %s', $initd_location); } } $this->application->dataLink->disconnect(); $this->application->dataLink->connect(); while (!System_Daemon::isDying() && $this->status == self::RUN) { $this->process(); System_Daemon::iterate($this->ownOptions['sleep']); $output = ob_get_contents(); if ($output != '') { System_Daemon::info($output); } ob_clean(); } }
#!/usr/bin/php -q <?php include '_includes/knx-function-daemon.php'; include '_includes/knx-config.php'; include '_includes/knx-function.php'; include '_includes/eib-functions.php'; System_Daemon::info("###### KNX Tracking -> Insert in db knxtrace.json each minute #####"); /* $sniffed[ $data['group_addr'] ] = array( "id" => data['id'], "name" => $data['name'], "dpt" => $data['dpt'], "value" => "", "unite" => getDptUnite($data['dpt']) ); */ while (true) { sleep(60); $json = file_get_contents(PATH_JSON); $trace = json_decode($json, true); $jour = date('Y-m-d'); $heure = date('H:i:s'); foreach ($trace as $groupaddr => $info) { $req_eq_inser = "INSERT INTO knx_tracking (knx_equipement_id,jour,heure,value) VALUES ('" . $info['id'] . "','" . $jour . "','" . $heure . "','" . $info['value'] . "')"; //System_Daemon::notice("Requete SQL -> ".$req_eq_inser); // Et on update la BDD mysql_query($req_eq_inser); } }
$heure = date("H:i:s", $time); $req_eq_inser = "INSERT INTO knx_tracking (knx_equipement_id,jour,heure,value) VALUES ('" . $sniffed[$grpaddr]['id'] . "','" . $jour . "','" . $heure . "','" . $sniffed[$grpaddr]['value'] . "')"; //System_Daemon::notice("Requete SQL -> ".$req_eq_inser); // Et on update la BDD $db->query($req_eq_inser); //System_Daemon::notice("OK"); } //System_Daemon::info("GroupAddr : ".$grpaddr." | hexa : ".$hexa." - value :".$sniffed[$grpaddr]['value'] ); } //on ecrit les données dans le fichier json trace System_Daemon::info("Initialisation du fichier knxtrace.json"); makeJsonTrace($sniffed); /* Mise a jour du ficheir knxtrace.json a chaque modification d'un equipement suivi */ System_Daemon::info("Mise a jour du fichier knxtrace.json a chaque modification d'un equipement suivi et sauvegarde en base s'il doit etre historisé"); //$lastpos = 0; while (true) { // On tail le fichier de log $knxlisten = tail(PATH_LOG, $lastpos); // On r�agit d�s qu'on a un Write // Pour chaque ligne, on r�cup�re le Groupe d'Addresse et de la valeur qu'on converti $groupaddr = get_string_between($knxlisten, 'group addr: ', ' -'); $hexa = get_string_between($knxlisten, 'Hexa: ', ' -'); //on met a jour le valeur dans le tableau et on regenere le fichier json //recursive_array_search if (array_key_exists($groupaddr, $sniffed)) { $decimal = hexdec($hexa); $value = dptSelectDecode($sniffed[$groupaddr]['dpt'], $decimal); //ecriture en base si changement d'etat et bas simplement l'equipement qui redis la meme chose sur le bus //System_Daemon::notice("Old Value -> ".$groupaddr.":: ".$oldSniffedValue[$groupaddr]);
// 'daemon" mode'; // System_Daemon::info('{appName} in %s %s/300', $a, $b); try { require_once 'lib/php/beanstalkd/ColaMensajes.php'; $colaMensajes = new ColaMensajes("transformarvideos"); $job = $colaMensajes->pop(); if ($job == "") { //Time out //System_Daemon::info("Time out!"); } else { $json = $job->getData(); require_once 'modulos/videos/controladores/videoControlador.php'; if (transformar($json)) { System_Daemon::notice('Video transformado correctamente'); } else { System_Daemon::info("ERROR! el resultado de la transformación no es cero"); } $colaMensajes->deleteJob($job); } } catch (Exception $e) { System_Daemon::info('ERROR! %s', $e->getMessage()); } if (!$runningOkay) { System_Daemon::err('parseLog() produced an error, ' . 'so this will be my last run'); } // Relax the system by sleeping for a little bit iterate also clears statcache System_Daemon::iterate(2); } // Shut down the daemon nicely // This is ignored if the class is actually running in the foreground System_Daemon::stop();
$runningOkay = true; // This variable keeps track of how many 'runs' or 'loops' your daemon has // done so far. For example purposes, we're quitting on 3. $cnt = 1; // While checks on 3 things in this case: // - That the Daemon Class hasn't reported it's dying // - That your own code has been running Okay // - That we're not executing more than 3 runs while (!System_Daemon::isDying() && $runningOkay && $cnt <= 3) { // What mode are we in? $mode = '"' . (System_Daemon::isInBackground() ? '' : 'non-') . 'daemon" mode'; // Log something using the Daemon class's logging facility // Depending on runmode it will either end up: // - In the /var/log/logparser.log // - On screen (in case we're not a daemon yet) System_Daemon::info('{appName} running in %s %s/3', $mode, $cnt); // In the actuall logparser program, You could replace 'true' // With e.g. a parseLog('vsftpd') function, and have it return // either true on success, or false on failure. $runningOkay = true; //$runningOkay = parseLog('vsftpd'); // Should your parseLog('vsftpd') return false, then // the daemon is automatically shut down. // An extra log entry would be nice, we're using level 3, // which is critical. // Level 4 would be fatal and shuts down the daemon immediately, // which in this case is handled by the while condition. if (!$runningOkay) { System_Daemon::err('parseLog() produced an error, ' . 'so this will be my last run'); } // Relax the system by sleeping for a little bit
function Setup_Finishing() { //exec(DaemonConfig::$cmd->{'SRV_HTTPD'} . ' restart'); $ControlConnect = DaemonCommon::ControlConnect('ApacheRestart'); if ($ControlConnect !== true) { return $ControlConnect . ' System is unable to reload Apache config.<br />'; } System_Daemon::info('Restart Daemon.'); $ControlConnect = DaemonCommon::ControlConnect('DaemonRestart'); if ($ControlConnect !== true) { return $ControlConnect . ' System is unable to restart EasySCP Daemon.<br />'; } unlink(DaemonConfig::$cfg->{'ROOT_DIR'} . '/daemon/DaemonCoreSetup.php'); exec(DaemonConfig::$cmd->{'CMD_RM'} . ' -rf ' . DaemonConfig::$cfg->{'ROOT_DIR'} . '/../setup >> /dev/null 2>&1'); // SocketHandler::Close(); // System_Daemon::restart(); }
} // Spawn Daemon System_Daemon::start(); // Here comes your own actual code // This variable keeps track of how many 'runs' or 'loops' your daemon has // done so far. For example purposes, we're quitting on 3. $cnt = 1; // While checks on 2 things in this case: // - That the Daemon Class hasn't reported it's dying // - That we're not executing more than 3 runs while (!System_Daemon::isDying() && $cnt <= 3) { // Log something using the Daemon class's logging facility // Depending on runmode it will either end up: // - In the /var/log/logparser.log // - On screen (in case we're not a daemon yet) System_Daemon::info('{appName} running %s/3', $cnt); // Relax the system by sleeping for a little bit // iterate() also clears statcache System_Daemon::iterate(2); // Just here to showcase how sighandlers can work // to catch a // /etc/init.d/signals stop // The SIGTERM signal tells the daemon to quit. // Normally it's catched by the ::defaultSigHandler() // but now we catch it with myHandler() posix_kill(posix_getpid(), SIGTERM); $cnt++; } // Shut down the daemon nicely // This is ignored if the class is actually running in the foreground System_Daemon::stop();
<?php require_once "../System/Daemon.php"; System_Daemon::setOption("appName", "leakplugger"); System_Daemon::start(); $last = 0; while (!System_Daemon::isDying()) { $mem = memory_get_peak_usage(); $use = $mem - $last; if ($use >= 0) { $use = '+' . $use; } System_Daemon::info("test"); echo "debug: memory_get_peak_usage: " . $use . "\n"; $last = $mem; System_Daemon::iterate(1); }
private static function DaemonMailDelete($row) { System_Daemon::debug('Starting "DaemonMailDelete" subprocess.'); $mail_ok = true; if ($row['mail_type'] == 'normal_mail' || $row['mail_type'] == 'alias_mail' || $row['mail_type'] == 'subdom_mail') { self::DaemonMailDelete_normal_mail($row); } if ($row['mail_type'] == 'normal_forward' || $row['mail_type'] == 'alias_forward' || $row['mail_type'] == 'subdom_forward') { self::DaemonMailDelete_normal_forward($row); } if ($row['mail_type'] == 'normal_catchall' || $row['mail_type'] == 'alias_catchall' || $row['mail_type'] == 'subdom_catchall') { self::DaemonMailDelete_catchall($row); } if ($mail_ok) { $mail_dir = substr($row['mail_addr'], strpos($row['mail_addr'], '@') + 1); System_Daemon::info('Delete Mail User Directory ' . DaemonConfig::$distro->{'MTA_VIRTUAL_MAIL_DIR'} . '/' . $mail_dir . '/' . $row['mail_acc']); if (file_exists(DaemonConfig::$distro->{'MTA_VIRTUAL_MAIL_DIR'} . '/' . $mail_dir . '/' . $row['mail_acc'])) { exec('rm -R ' . DaemonConfig::$distro->{'MTA_VIRTUAL_MAIL_DIR'} . '/' . $mail_dir . '/' . $row['mail_acc']); } $sql_param = array(':mail_id' => $row['mail_id']); $sql_query = "\n\t\t\t\tDELETE FROM\n\t\t\t\t\tmail_users\n\t\t\t\tWHERE\n\t\t\t\t\tmail_id = :mail_id\n\t\t\t"; DB::prepare($sql_query); DB::execute($sql_param)->closeCursor(); } System_Daemon::debug('Finished "DaemonMailDelete" subprocess.'); }
foreach ($values as $bytes) { array_push($recData, PhpType::bytes2signedInt($bytes)); } } // Get signed integer from INT interpretation $t = time(); $wert1 = array_merge((array) $t, (array) $recData); // zeit und daten zusammenfügen $wert2 = implode(":", $wert1); // ausgabe für rrd vorbereiten $wert3 = array($wert2); $ret = rrd_update($filename, $wert3); // rrd updaten if (!$ret) { $rrd_error = rrd_error(); System_Daemon::info('{appName} Graph error %s', $rrd_error); //echo "<b>Graph error, </b>".rrd_error()."\n"; } } else { // wenn das rrd file noch nicht vorhanden ist neues anlagen $options = array("--step", "5", "--start", "-30 days"); $zaehler = $start + $anzahl; //echo("Start: ".$start."Ende: ".$zaehler.""); for ($i = $start; $i < $zaehler; $i++) { // anzahl der trends Name ist aus Datenbanck IWx array_push($options, "DS:" . $art . $i . ":GAUGE:5:U:U"); } array_push($options, "RRA:AVERAGE:0.5:1:17280"); array_push($options, "RRA:AVERAGE:0.5:12:86400"); array_push($options, "RRA:AVERAGE:0.5:720:8760"); //print_r($options);
echo ' --' . $runmod . "\n"; } die; } // Make it possible to test in source directory // This is for PEAR developers only ini_set('include_path', ini_get('include_path') . ':..'); // Include Class error_reporting(E_STRICT); require_once 'System/Daemon.php'; $nom = basename($_SERVER['PHP_SELF']); // Setup $options = array('appName' => $nom, 'appDir' => dirname(__FILE__), 'appDescription' => 'Parses KNX logfiles and stores them in MySQL for INIT', 'authorName' => 'Stan', 'authorEmail' => '', 'sysMaxExecutionTime' => '0', 'sysMaxInputTime' => '0', 'sysMemoryLimit' => '128M', 'appRunAsGID' => 0, 'appRunAsUID' => 0); System_Daemon::setOptions($options); // This program can also be run in the forground with runmode --no-daemon if (!$runmode['no-daemon']) { // Spawn Daemon System_Daemon::start(); } // With the runmode --write-initd, this program can automatically write a // system startup file called: 'init.d' // This will make sure your daemon will be started on reboot if (!$runmode['write-initd']) { System_Daemon::info('not writing an init.d script this time'); } else { if (($initd_location = System_Daemon::writeAutoRun()) === false) { System_Daemon::notice('unable to write init.d script'); } else { System_Daemon::info('sucessfully written startup script: %s', $initd_location); } }