function status() { $cache_file = "/usr/share/artica-postfix/ressources/logs/web/monit.status.all"; $unix = new unix(); $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n"; } return; } $time = $unix->file_time_min($cache_file); if ($time < 2) { return; } $monit = new monit_unix(); $array = $monit->all_status(); if (count($array) < 2) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} array returned less than 2 items\n"; } return; } @unlink($cache_file); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Saving {$cache_file}\n"; } @file_put_contents($cache_file, serialize($array)); @chmod($cache_file, 0755); }
function monit() { if (!$GLOBALS["CLASS_USERS"]->MONIT_INSTALLED) { if ($GLOBALS["VERBOSE"]) { echo __FUNCTION__ . " MEMCACHED_INSTALLED = FALSE\n"; } $l[] = "[APP_MONIT]"; $l[] = "service_name=APP_MONIT"; $l[] = "installed=0"; $l[] = "service_disabled=0"; return implode("\n", $l); } $bin = $GLOBALS["CLASS_UNIX"]->find_program("monit"); $EnableDaemon = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableMonit"); $SquidPerformance = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("SquidPerformance")); if ($SquidPerformance > 2) { $EnableDaemon = 0; } if (!is_numeric($EnableDaemon)) { $EnableDaemon = 1; } $unix = new unix(); $master_pid = $unix->get_pid_from_file("/var/run/monit/monit.pid"); $cache_file = "/usr/share/artica-postfix/ressources/logs/web/monit.status.all"; if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { $master_pid = $GLOBALS["CLASS_UNIX"]->PIDOF($bin, true); } if ($EnableDaemon == 0) { if ($GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { shell_exec2("/etc/init.d/monit stop"); } } $l[] = "[APP_MONIT]"; $l[] = "service_name=APP_MONIT"; $l[] = "master_version=" . monit_daemon_version(); $l[] = "service_disabled={$EnableDaemon}"; $l[] = "watchdog_features=1"; $l[] = "service_cmd=/etc/init.d/monit"; $l[] = "family=system"; $l[] = "installed=1"; if ($EnableDaemon == 0) { $l[] = ""; return implode("\n", $l); return; } if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) { if ($GLOBALS["VERBOSE"]) { echo " **** NO RUNNING ****\n"; } if (!$GLOBALS["DISABLE_WATCHDOG"]) { shell_exec2("/etc/init.d/monit start"); } $l[] = "running=0"; $l[] = ""; return implode("\n", $l); } $AS_CGROUP = false; if ($GLOBALS["CLASS_SOCKETS"]->EnableIntelCeleron == 1) { $AS_CGROUP = true; } if ($AS_CGROUP) { events("mysqld cgroup must be enabled ....", __FUNCTION__, __LINE__); $cgroups = new status_cgroups(); $limit = $cgroups->GetLimit($master_pid); if ($cgroups->GetLimit($master_pid) == "unlimited") { $cgroups->set_limit("php", $master_pid); } } $l[] = GetMemoriesOf($master_pid); $l[] = "running=1"; $monit = new monit_unix(); $monit->WAKEUP(); $time = $GLOBALS["CLASS_UNIX"]->file_time_min($cache_file); if ($GLOBALS["VERBOSE"]) { echo "{$cache_file} = {$time}mn DISABLE_WATCHDOG = {$GLOBALS["DISABLE_WATCHDOG"]}\n"; } if ($time > 2) { if (!$GLOBALS["DISABLE_WATCHDOG"]) { shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} /usr/share/artica-postfix/exec.monit.php --status >/dev/null 2>&1 &"); } } return implode("\n", $l); }
function monit() { $monit = new monit_unix(); $monit->WAKEUP(); $unix = new unix(); $unix->chmod_func(0755, "/etc/artica-postfix/settings/Daemons/*"); }
function start($aspid = false) { $scriptlog = null; if ($GLOBALS["BYSCRIPT"]) { $scriptlog = " by init.d script"; } $sock = new sockets(); $unix = new unix(); if (is_file("/etc/artica-postfix/FROM_ISO")) { if ($unix->file_time_min("/etc/artica-postfix/FROM_ISO") < 1) { return; } } $daemon_path = $unix->APACHE_LOCATE_PHP_FPM(); if (!is_file($daemon_path)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: not installed\n"; } return; } if (!$aspid) { $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid"; $pid = $unix->get_pid_from_file($pidfile); if ($unix->process_exists($pid, basename(__FILE__))) { $time = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $pid = FPM_PID(); $EnablePHPFPM = $sock->GET_INFO("EnablePHPFPM"); if (!is_numeric($EnablePHPFPM)) { $EnablePHPFPM = 0; } $ZarafaApachePHPFPMEnable = $sock->GET_INFO("ZarafaApachePHPFPMEnable"); if (!is_numeric($ZarafaApachePHPFPMEnable)) { $ZarafaApachePHPFPMEnable = 0; } $EnableArticaApachePHPFPM = $sock->GET_INFO("EnableArticaApachePHPFPM"); if (!is_numeric($EnableArticaApachePHPFPM)) { $EnableArticaApachePHPFPM = 0; } $EnablePHPFPMFreeWeb = $sock->GET_INFO("EnablePHPFPMFreeWeb"); if (!is_numeric($EnablePHPFPMFreeWeb)) { $EnablePHPFPMFreeWeb = 0; } $EnablePHPFPMFrameWork = $sock->GET_INFO("EnablePHPFPMFrameWork"); if (!is_numeric($EnablePHPFPMFrameWork)) { $EnablePHPFPMFrameWork = 0; } if ($EnableArticaApachePHPFPM == 1) { $EnablePHPFPM = 1; } if ($ZarafaApachePHPFPMEnable == 1) { $EnablePHPFPM = 1; } if ($EnablePHPFPMFreeWeb == 1) { $EnablePHPFPM = 1; } if ($EnablePHPFPMFrameWork == 1) { $EnablePHPFPM = 1; } if (is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) { $EnablePHPFPMFreeWeb = 1; $EnablePHPFPM = 1; } if ($unix->process_exists($pid)) { if ($EnablePHPFPM == 0) { stop(true); } $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Already started {$pid} since {$timepid}Mn...\n"; } return; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: EnablePHPFPMFrameWork = {$EnablePHPFPMFrameWork}\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: EnablePHPFPMFreeWeb = {$EnablePHPFPMFreeWeb}\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: ZarafaApachePHPFPMEnable = {$ZarafaApachePHPFPMEnable}\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: EnableArticaApachePHPFPM = {$EnableArticaApachePHPFPM}\n"; } if ($EnablePHPFPM == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Disabled ( see EnablePHPFPM )\n"; } @unlink("/etc/monit/conf.d/phpfpm.monitrc"); return; } $end = null; $nohup = $unix->find_program("nohup"); $ParseParams = ParseParams(); $parms[] = "{$daemon_path}"; if (isset($ParseParams["pid"])) { $parms[] = "--pid /var/run/php5-fpm.pid"; } $parms[] = "--fpm-config /etc/php5/fpm/php-fpm.conf"; if (isset($ParseParams["daemonize"])) { $parms[] = "--daemonize"; $end = "&"; } //PHP 5.3.10-1ubuntu3.6 //PHP 5.3.24-1~dotdeb.0 if (isset($ParseParams["allow-to-run-as-root"])) { $parms[] = "--allow-to-run-as-root"; } if ($end != null) { $parms[] = $end; } $cmd = @implode(" ", $parms); if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: version:" . GetVersion() . "\n"; } FrmToSyslog("Starting PHP-FPM daemon{$scriptlog}"); shell_exec($cmd); for ($i = 0; $i < 6; $i++) { $pid = FPM_PID(); if ($unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: waiting {$i}/6...\n"; } sleep(1); } $pid = FPM_PID(); if ($unix->process_exists($pid)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Success service started pid:{$pid}...\n"; } $monit = new monit_unix(); $monit->MONITOR("PHPFPM"); } else { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: PHP-FPM: Service failed...\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n"; } } }