Пример #1
0
function start($aspid = false)
{
    $unix = new unix();
    $scriptlog = null;
    if ($GLOBALS["BYSCRIPT"]) {
        $scriptlog = " by init.d script";
    }
    if (is_file("/etc/artica-postfix/FROM_ISO")) {
        if ($unix->file_time_min("/etc/artica-postfix/FROM_ISO") < 1) {
            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]: Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = LIGHTTPD_PID();
    @mkdir("/usr/share/artica-postfix/ressources/web", 0755, true);
    if (!is_dir("/usr/share/artica-postfix/ressources/web")) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service Warning !!! /usr/share/artica-postfix/ressources/web (permission denied !)\n";
    }
    if ($unix->process_exists($pid)) {
        if (!$unix->is_socket("/usr/share/artica-postfix/ressources/web/framework.sock")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service framework.sock no such socket, stop framework\n";
            }
            stop(true);
        } else {
            $timepid = $unix->PROCCESS_TIME_MIN($pid);
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: Framework Service already started {$pid} since {$timepid}Mn...\n";
            }
            return;
        }
    }
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $lighttpd_bin = $unix->find_program("lighttpd");
    if (!is_file($lighttpd_bin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service lighttpd not found..\n";
        }
        return;
    }
    @mkdir("/var/run/lighttpd", 0755, true);
    $cmd = "{$nohup} {$php5} /usr/share/artica-postfix/exec.web-community-filter.php --register-lic >/dev/null 2>&1 &";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    buildConfig();
    $cmd = "{$lighttpd_bin} -f /etc/artica-postfix/framework.conf";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    for ($i = 0; $i < 6; $i++) {
        $pid = LIGHTTPD_PID();
        if ($unix->process_exists($pid)) {
            if (!$unix->is_socket("/usr/share/artica-postfix/ressources/web/framework.sock")) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service waiting framework.sock\n";
                }
            } else {
                break;
            }
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service waiting {$i}/6...\n";
        }
        sleep(1);
    }
    $pid = LIGHTTPD_PID();
    if ($unix->process_exists($pid)) {
        FrmToSyslog("Success service started pid:{$pid}{$scriptlog}");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service apply permissions on framework.sock\n";
        }
        @chmod("/usr/share/artica-postfix/ressources/web/framework.sock", 0777);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service apply permissions on Settings direcotry\n";
        }
        $unix->chmod_alldirs(0755, "/etc/artica-postfix/settings/Daemons/*");
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Framework Success service started pid:{$pid}...\n";
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Framework service failed...\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmd}\n";
        }
    }
}
Пример #2
0
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";
        }
    }
}