コード例 #1
0
ファイル: exec.nginx.php プロジェクト: BillTheBest/1.6.x
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";
    }
}
コード例 #2
0
function check_all_websites_http()
{
    $q = new mysql_squid_builder();
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    $files = $unix->DirFiles("/etc/nginx/sites-enabled");
    while (list($file, $line) = each($files)) {
        $main = preg_match_site($file);
        if (!$main) {
            echo "Skip Site `{$file}`\n";
            continue;
        }
        $sitename = $main[0];
        if ($GLOBALS["VERBOSE"]) {
            echo "Found: {$sitename}\n";
        }
        $MAIN_ARRAY[$sitename] = true;
    }
    $results = $q->QUERY_SQL("SELECT servername FROM reverse_www WHERE enabled=0 ORDER BY zOrder");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $sitename = trim($ligne["servername"]);
        if ($sitename == null) {
            continue;
        }
        if (isset($MAIN_ARRAY[$sitename])) {
            nginx_admin_mysql(1, "Ask to remove {$sitename} from configuration (site disabled)", null, __FILE__, __LINE__);
            system("{$php} /usr/share/artica-postfix/exec.nginx.single.php --remove \"{$sitename}\" --no-buildmain --no-reload");
        }
    }
    $results = $q->QUERY_SQL("SELECT servername,zOrder FROM reverse_www ORDER BY zOrder");
    $c = 0;
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $c++;
        $q->QUERY_SQL("UPDATE reverse_www SET `zOrder`={$c} WHERE `servername`='{$ligne["servername"]}'");
    }
    $files = $unix->DirFiles("/etc/nginx/sites-enabled");
    while (list($file, $line) = each($files)) {
        $fullpath = "/etc/nginx/sites-enabled/{$file}";
        $main = preg_match_site($file);
        if ($file == "KILL") {
            @unlink($fullpath);
            continue;
        }
        if (!$main) {
            echo "Skip Site `{$file}`\n";
            continue;
        }
        $servername = null;
        $sitename = $main[0];
        $sitename_port = intval($main[1]);
        $sitename_ssl = intval($main[2]);
        echo "Found {$file} Site `{$sitename}` port {$sitename_port} SSL={$sitename_ssl}\n";
        if ($sitename_ssl > 0) {
            $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT servername FROM reverse_www WHERE servername='{$sitename}' AND `port`='{$sitename_ssl}' AND `enabled`=1"));
            if (!$q->ok) {
                nginx_admin_mysql(0, "MySQL Error", $q->mysql_error, __FILE__, __LINE__);
                echo $q->mysql_error . "\n";
                build_progress("{failed} MySQL error", 110);
                die;
            }
            $servername = $ligne["servername"];
            if ($servername == null) {
                $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT servername FROM reverse_www WHERE servername='{$sitename}' AND `ssl`=1 AND `enabled`=1"));
                if (!$q->ok) {
                    nginx_admin_mysql(0, "MySQL Error", $q->mysql_error, __FILE__, __LINE__);
                    echo $q->mysql_error . "\n";
                    build_progress("{failed} MySQL error", 110);
                    die;
                }
                $servername = $ligne["servername"];
            }
        } else {
            if ($sitename_port > 0) {
                $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT servername FROM reverse_www WHERE servername='{$sitename}' AND `port`='{$sitename_port}' AND `enabled`=1"));
                if (!$q->ok) {
                    nginx_admin_mysql(0, "MySQL Error", $q->mysql_error, __FILE__, __LINE__);
                    echo $q->mysql_error . "\n";
                    build_progress("{failed} MySQL error", 110);
                    die;
                }
                $servername = $ligne["servername"];
            }
            if ($servername == null) {
                $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT servername FROM reverse_www WHERE servername='{$sitename}' AND `enabled`=1"));
                if (!$q->ok) {
                    nginx_admin_mysql(0, "MySQL Error", $q->mysql_error, __FILE__, __LINE__);
                    echo $q->mysql_error . "\n";
                    build_progress("{failed} MySQL error", 110);
                    die;
                }
                $servername = $ligne["servername"];
            }
        }
        if ($servername == null) {
            nginx_admin_mysql(1, "Removing Site `{$sitename}`", "Removed:{$fullpath}\nFound {$file} Site `{$sitename}` port {$sitename_port} SSL={$sitename_ssl}", __FILE__, __LINE__);
            echo "Removing Site `{$sitename}` {$fullpath}\n";
            @unlink($fullpath);
        }
    }
    $dirs = $unix->dirdir("/var/log/apache2");
    $rm = $unix->find_program("rm");
    $q2 = new mysql();
    while (list($dirpath, $line) = each($dirs)) {
        $sitename = basename($dirpath);
        if ($sitename == "unix-varrunnginx-authenticator.sock") {
            continue;
        }
        $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT servername FROM reverse_www WHERE servername='{$sitename}'"));
        if (!$q->ok) {
            nginx_admin_mysql(0, "MySQL Error", $q->mysql_error, __FILE__, __LINE__);
            echo $q->mysql_error . "\n";
            continue;
        }
        if ($ligne["servername"] != null) {
            continue;
        }
        $ligne = mysql_fetch_array($q2->QUERY_SQL("SELECT servername FROM freeweb WHERE servername='{$sitename}'", "artica_backup"));
        if (!$q2->ok) {
            nginx_admin_mysql(0, "MySQL Error", $q2->mysql_error, __FILE__, __LINE__);
            echo $q2->mysql_error . "\n";
            continue;
        }
        if ($ligne["servername"] != null) {
            continue;
        }
        nginx_admin_mysql(1, "Removing logs Directory {$dirpath} for {$sitename}", __FILE__, __LINE__);
        echo "Directory: `{$sitename}` is not managed, remove it\n";
        system("{$rm} -rf {$dirpath}");
    }
}
コード例 #3
0
function BuildReverse($ligne, $backupBefore = false)
{
    $T1 = time();
    $q = new mysql_squid_builder();
    $unix = new unix();
    $ligne["servername"] = trim($ligne["servername"]);
    $GLOBALS["IPADDRS"] = $unix->NETWORK_ALL_INTERFACES(true);
    $IPADDRS = $GLOBALS["IPADDRS"];
    $DenyConf = $ligne["DenyConf"];
    $ligne["servername"] = trim($ligne["servername"]);
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Nginx\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "]  ************* {$ligne["servername"]}:{$ligne["port"]} / {$DenyConf} ************* \n";
    }
    if ($ligne["port"] == 82) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "] 82 port is an apache port, SKIP\n";
        build_progress("Bad port {$ligne["servername"]}:82", 110);
        return;
    }
    if ($GLOBALS["REMOVE_LOCAL_ADDR"]) {
        if (isset($IPADDRS[$ligne["servername"]])) {
            build_progress("{$IPADDRS[$ligne["servername"]]} *** SKIPPED ***", 110);
            echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "]  {$ligne["servername"]} *** SKIPPED ***\n";
            return;
        }
    }
    if ($DenyConf == 1) {
        build_progress("Denied config *** SKIPPED ***", 110);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "]  Local web site `{$ligne["servername"]}`, DenyConf = 1,skipped\n";
        }
        return;
    }
    if (isset($ALREADYSET[$ligne["servername"]])) {
        build_progress("Already setup", 110);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: [" . __LINE__ . "]  `{$ligne["servername"]}` Already defined, abort\n";
        }
        return;
    }
    $ListenPort = $ligne["port"];
    $SSL = $ligne["ssl"];
    $certificate = $ligne["certificate"];
    echo "Starting......: " . date("H:i:s") . " [INIT]:  ListenPort..............:{$ListenPort}\n";
    echo "Starting......: " . date("H:i:s") . " [INIT]:  SSL.....................:{$SSL}\n";
    echo "Starting......: " . date("H:i:s") . " [INIT]:  Certificate.............:{$certificate}\n";
    echo "Starting......: " . date("H:i:s") . " [INIT]:  OWA.....................:{$ligne["owa"]}\n";
    if ($ligne["owa"] == 1) {
        $GLOBALS["OUTPUT"] = true;
        $nginx_exchange = new nginx_exchange($ligne["servername"]);
        build_progress("{$ligne["servername"]}: {building} Microsoft Exchange Configuration", 50);
        $nginx_exchange->buildConfig();
        build_progress("{$ligne["servername"]}: {building} Microsoft Exchange Configuration {done}", 70);
        $Took = distanceOfTimeInWords($T1, time(), true);
        nginx_admin_mysql(2, "Success build Microsoft Exchange Configuration configuration for {$ligne["servername"]} took: {$Took}", "Took: {$Took}", __FILE__, __LINE__);
        build_progress("{$ligne["servername"]}: Microsoft Exchange Configuration {done}", 80);
        return true;
    }
    build_progress("{$ligne["servername"]}:{$ListenPort} [SSL:{$SSL}]", 20);
    echo "Starting......: " . date("H:i:s") . " [INIT]: Protect remote web site `{$ligne["servername"]}:{$ListenPort} [SSL:{$SSL}]`\n";
    if ($ligne["servername"] == null) {
        echo "Starting......: " . date("H:i:s") . " [INIT]:  skip it...\n";
        return;
    }
    $cache_peer_id = $ligne["cache_peer_id"];
    if ($cache_peer_id > 0) {
        $ligne2 = mysql_fetch_array($q->QUERY_SQL("SELECT * FROM `reverse_sources` WHERE `ID`='{$cache_peer_id}'"));
    }
    $host = new nginx($ligne["servername"]);
    if ($ListenPort == 80 && $SSL == 1) {
        build_progress("{$ligne["servername"]}: Building HTTP", 40);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]:  HTTP/HTTPS Enabled [" . __LINE__ . "]...\n";
        }
        $host->set_RedirectQueries($ligne["RedirectQueries"]);
        $host->set_forceddomain($ligne2["forceddomain"]);
        $host->set_ssl(0);
        $host->set_mixed_ssl(1);
        $host->set_proxy_port($ligne2["port"]);
        $host->set_listen_port(80);
        $host->set_poolid($ligne["poolid"]);
        $host->set_owa($ligne["owa"]);
        $host->set_storeid($ligne["cacheid"]);
        $host->set_cache_peer_id($cache_peer_id);
        $host->BackupBefore = $backupBefore;
        build_progress("{$ligne["servername"]}: HTTP/HTTPS Enabled", 50);
        $GLOBALS["NGINX_FATAL_ERRORS"] = array();
        if (!$host->build_proxy()) {
            if ($GLOBALS["NGINX_FATAL_ERROR"] != null) {
                nginx_admin_mysql(0, "Fatal error on {$ligne["servername"]} <{$GLOBALS["NGINX_FATAL_ERROR"]}>", "{$GLOBALS["NGINX_FATAL_ERROR"]}\n" . @implode("\n", $GLOBALS["NGINX_FATAL_ERRORS"]));
                echo "***                                             ***\n";
                echo "*** Fatal error {$GLOBALS["NGINX_FATAL_ERROR"]} ***\n";
                echo "***                                             ***\n";
                build_progress("{$ligne["servername"]}: {failed} {$GLOBALS["NGINX_FATAL_ERROR"]}", 110);
                return;
            }
            build_progress("{$ligne["servername"]}: {failed}", 110);
            return;
        }
        if (!$GLOBALS["NO_RELOAD"]) {
            build_progress("{$ligne["servername"]}: {done}", 80);
            return true;
        }
    }
    if ($ligne["ssl"] == 1) {
        echo "Starting......: " . date("H:i:s") . " [INIT]:  SSL Enabled...\n";
        $ligne2["ssl"] = 1;
    }
    if ($ligne["port"] == 443) {
        $ligne2["ssl"] = 1;
    }
    build_progress("{$ligne["servername"]}", 50);
    $host->BackupBefore = $backupBefore;
    $host->set_owa($ligne["owa"]);
    $host->set_RedirectQueries($ligne["RedirectQueries"]);
    $host->set_ssl_certificate($certificate);
    $host->set_ssl_certificate($ligne2["ssl_commname"]);
    $host->set_forceddomain($ligne2["forceddomain"]);
    $host->set_ssl($ligne2["ssl"]);
    $host->set_proxy_port($ligne2["port"]);
    $host->set_listen_port($ligne["port"]);
    $host->set_poolid($ligne["poolid"]);
    $host->set_owa($ligne["owa"]);
    $host->set_storeid($ligne["cacheid"]);
    $host->set_cache_peer_id($cache_peer_id);
    $host->build_proxy();
    if ($GLOBALS["NGINX_FATAL_ERROR"] != null) {
        nginx_admin_mysql(0, "Fatal error on {$ligne["servername"]} <{$GLOBALS["NGINX_FATAL_ERROR"]}>", "{$GLOBALS["NGINX_FATAL_ERROR"]}\n" . @implode("\n", $GLOBALS["NGINX_FATAL_ERRORS"]), __FILE__, __LINE__);
        echo "*** Fatal error {$GLOBALS["NGINX_FATAL_ERROR"]} ***\n";
        build_progress("{$ligne["servername"]}: {failed}", 110);
        return;
    }
    $Took = distanceOfTimeInWords($T1, time(), true);
    nginx_admin_mysql(2, "Success build configuration for {$ligne["servername"]} took: {$Took}", "Took: {$Took}", __FILE__, __LINE__);
    build_progress("{$ligne["servername"]}: {done}", 80);
    return true;
}
コード例 #4
0
ファイル: exec.nginx.php プロジェクト: brucewu16899/1.6.x
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";
    }
}