function start($aspid = false) { $unix = new unix(); $sock = new sockets(); $nginx = $unix->find_program("nginx"); if (!is_file($nginx)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, 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]: Nginx Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $MEMORY = $unix->MEM_TOTAL_INSTALLEE(); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx {$MEMORY}K\n"; } $pid = PID_NUM(); if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx Service already started {$pid} since {$timepid}Mn...\n"; } return; } $php = $unix->LOCATE_PHP5_BIN(); $EnableNginx = intval($sock->GET_INFO("EnableNginx")); $SquidAllow80Port = intval($sock->GET_INFO("SquidAllow80Port")); if (is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, is Wordpress Appliance\n"; } $sock->SET_INFO("EnableNginx", 1); if (!is_dir("/usr/share/wordpress-src")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, Installing Wordpress\n"; } shell_exec("{$php} /usr/share/artica-postfix/exec.wordpress.download.php"); } $EnableNginx = 1; } if (!is_numeric($EnableNginx)) { $EnableNginx = 1; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service \"EnableNginx\" = {$EnableNginx}\n"; } if ($SquidAllow80Port == 1) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service disabled (SquidAllow80Port)\n"; } return; } if ($EnableNginx == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service disabled\n"; } return; } GHOSTS_PID(); @mkdir("/home/nginx/tmp", 0755, true); @mkdir("/var/log/nginx", 0755, true); $nohup = $unix->find_program("nohup"); $fuser = $unix->find_program("fuser"); $kill = $unix->find_program("kill"); $results = array(); $FUSERS = array(); $unix->KILL_PROCESSES_BY_PORT(80); $unix->KILL_PROCESSES_BY_PORT(443); $php5 = $unix->LOCATE_PHP5_BIN(); if ($unix->is_socket("/var/run/nginx-authenticator.sock")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Remove authenticator socket\n"; } @unlink("/var/run/nginx-authenticator.sock"); } if (is_file("/var/run/nginx-authenticator.sock")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Remove authenticator socket\n"; } @unlink("/var/run/nginx-authenticator.sock"); } nginx_mime_types(); @unlink("/etc/nginx/conf.d/default.conf"); $cmd = "{$nginx} -c /etc/nginx/nginx.conf"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); for ($i = 0; $i < 6; $i++) { $pid = PID_NUM(); if ($unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service waiting {$i}/6...\n"; } sleep(1); } $pid = PID_NUM(); if ($unix->process_exists($pid)) { nginx_admin_mysql(2, "Nginx Web service success to start [action=info]", null, __FILE__, __LINE__); @unlink($GLOBALS["pidStampReload"]); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service Success service started pid:{$pid}...\n"; } $php5 = $unix->LOCATE_PHP5_BIN(); shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.php-fpm.php --start >/dev/null 2>&1 &"); shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.nginx.wizard.php --avail-status --force >/dev/null 2>&1 &"); return; } nginx_admin_mysql(0, "Nginx Web service failed to start [action=info]", null, __FILE__, __LINE__); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service failed...\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n"; } $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1 &"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } }
function start($aspid = false) { $unix = new unix(); $sock = new sockets(); $nginx = $unix->find_program("nginx"); if (!is_file($nginx)) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, 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]: Nginx Already Artica task running PID {$pid} since {$time}mn\n"; } return; } @file_put_contents($pidfile, getmypid()); } $MEMORY = $unix->MEM_TOTAL_INSTALLEE(); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx {$MEMORY}K\n"; } $pid = PID_NUM(); if ($unix->process_exists($pid)) { $timepid = $unix->PROCCESS_TIME_MIN($pid); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx Service already started {$pid} since {$timepid}Mn...\n"; } return; } $php = $unix->LOCATE_PHP5_BIN(); $EnableNginx = $sock->GET_INFO("EnableNginx"); if (is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, is Wordpress Appliance\n"; } $sock->SET_INFO("EnableNginx", 1); if (!is_dir("/usr/share/wordpress-src")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx, Installing Wordpress\n"; } shell_exec("{$php} /usr/share/artica-postfix/exec.wordpress.download.php"); } $EnableNginx = 1; } if (!is_numeric($EnableNginx)) { $EnableNginx = 1; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service \"EnableNginx\" = {$EnableNginx}\n"; } if ($EnableNginx == 0) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service disabled\n"; } return; } GHOSTS_PID(); @mkdir("/var/log/nginx", 0755, true); $nohup = $unix->find_program("nohup"); $fuser = $unix->find_program("fuser"); $kill = $unix->find_program("kill"); $results = array(); $FUSERS = array(); exec("{$fuser} 80/tcp 2>&1", $results); while (list($key, $line) = each($results)) { if ($GLOBALS["VERBOSE"]) { echo "fuser: ->\"{$line}\"\n"; } if (preg_match("#tcp:\\s+(.+)#", $line, $re)) { $FUSERS = explode(" ", $re[1]); } } if (count($FUSERS) > 0) { while (list($key, $pid) = each($FUSERS)) { $pid = trim($pid); if (!is_numeric($pid)) { continue; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: killing {$pid} PID that listens 80\n"; } unix_system_kill_force($pid); } } exec("{$fuser} 443/tcp 2>&1", $results); while (list($key, $line) = each($results)) { if ($GLOBALS["VERBOSE"]) { echo "fuser: ->\"{$line}\"\n"; } if (preg_match("#tcp:\\s+(.+)#", $line, $re)) { $FUSERS = explode(" ", $re[1]); } } if (count($FUSERS) > 0) { while (list($key, $pid) = each($FUSERS)) { $pid = trim($pid); if (!is_numeric($pid)) { continue; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: killing {$pid} PID that listens 443\n"; } unix_system_kill_force($pid); } } $php5 = $unix->LOCATE_PHP5_BIN(); if ($unix->is_socket("/var/run/nginx-authenticator.sock")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Remove authenticator socket\n"; } @unlink("/var/run/nginx-authenticator.sock"); } if (is_file("/var/run/nginx-authenticator.sock")) { if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Remove authenticator socket\n"; } @unlink("/var/run/nginx-authenticator.sock"); } nginx_mime_types(); $EnableArticaInNGINX = $sock->GET_INFO("EnableArticaInNGINX"); if (!is_numeric($EnableArticaInNGINX)) { $EnableArticaInNGINX = 0; } @unlink("/etc/nginx/conf.d/default.conf"); if ($EnableArticaInNGINX == 1) { build_default_asArtica(); } $cmd = "{$nginx} -c /etc/nginx/nginx.conf"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } shell_exec($cmd); for ($i = 0; $i < 6; $i++) { $pid = PID_NUM(); if ($unix->process_exists($pid)) { break; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service waiting {$i}/6...\n"; } sleep(1); } $pid = PID_NUM(); if ($unix->process_exists($pid)) { nginx_admin_mysql(2, "Nginx Web service success to start [action=info]", null, __FILE__, __LINE__); @unlink($GLOBALS["pidStampReload"]); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service Success service started pid:{$pid}...\n"; } $php5 = $unix->LOCATE_PHP5_BIN(); shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.php-fpm.php --start >/dev/null 2>&1 &"); shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.nginx.wizard.php --avail-status --force >/dev/null 2>&1 &"); return; } nginx_admin_mysql(0, "Nginx Web service failed to start [action=info]", null, __FILE__, __LINE__); if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx service failed...\n"; } if ($GLOBALS["OUTPUT"]) { echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n"; } $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1 &"; if ($GLOBALS["VERBOSE"]) { echo "{$cmd}\n"; } }