Exemplo n.º 1
0
function stop()
{
    $unix = new unix();
    $sock = new sockets();
    $masterbin = $unix->find_program("redis-server");
    $pid = redis_pid();
    if (!is_file($masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Not installed\n";
        }
        return;
    }
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Already stopped...\n";
        }
        return;
    }
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $kill = $unix->find_program("kill");
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Shutdown pid {$pid}...\n";
    }
    unix_system_kill($pid);
    for ($i = 0; $i < 5; $i++) {
        $pid = redis_pid();
        if (!$unix->process_exists($pid)) {
            break;
        }
        unix_system_kill($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting pid:{$pid} {$i}/5...\n";
        }
        sleep(1);
    }
    $pid = redis_pid();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} success...\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} shutdown - force - pid {$pid}...\n";
    }
    unix_system_kill_force($pid);
    for ($i = 0; $i < 5; $i++) {
        $pid = redis_pid();
        if (!$unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} waiting pid:{$pid} {$i}/5...\n";
        }
        unix_system_kill_force($pid);
        sleep(1);
    }
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} success stopped...\n";
        }
        return;
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} failed...\n";
        }
    }
}
Exemplo n.º 2
0
function start($nopid = false)
{
    $sock = new sockets();
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if (!$nopid) {
        $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["SERVICE_NAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
    }
    $pid = ntopng_pid();
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Already running since {$time}Mn...\n";
        }
        return;
    }
    $Enablentopng = $sock->GET_INFO("Enablentopng");
    if (!is_numeric($Enablentopng)) {
        $Enablentopng = 0;
    }
    $SquidPerformance = intval($sock->GET_INFO("SquidPerformance"));
    if ($SquidPerformance > 2) {
        $Enablentopng = 0;
    }
    if ($Enablentopng == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Disabled ( see Enablentopng )...\n";
        }
        return;
    }
    $masterbin = $unix->find_program("ntopng");
    if (!is_file($masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Not installed...\n";
        }
        return;
    }
    $redis_pid = redis_pid();
    if (!$unix->process_exists($redis_pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Starting redis-server\n";
        }
    }
    $redis_pid = redis_pid();
    if (!$unix->process_exists($redis_pid)) {
        $php = $unix->LOCATE_PHP5_BIN();
        system("{$php} /usr/share/artica-postfix/exec.redis-server.php --start");
    }
    $redis_pid = redis_pid();
    if (!$unix->process_exists($redis_pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} failed, unable to start redis-server\n";
        }
        return;
    }
    CheckFilesAndSecurity();
    $version = ntopng_version();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Starting service v{$version}\n";
    }
    $net = new networkscanner();
    while (list($num, $maks) = each($net->networklist)) {
        if (trim($maks) == null) {
            continue;
        }
        if (isset($net->Networks_disabled[$maks])) {
            continue;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Analyze {$maks}\n";
        }
        $hash[$maks] = $maks;
    }
    while (list($a, $b) = each($hash)) {
        $MASKZ[] = $a;
    }
    $arrayConf = unserialize(base64_decode($sock->GET_INFO("ntopng")));
    if (!is_numeric($arrayConf["HTTP_PORT"])) {
        $arrayConf["HTTP_PORT"] = 3000;
    }
    $f[] = $masterbin;
    $f[] = "--daemon";
    $f[] = "--dns-mode 1";
    $f[] = "--http-port {$arrayConf["HTTP_PORT"]}";
    $f[] = "--local-networks \"" . @implode(",", $MASKZ) . "\"";
    $f[] = "--user root";
    $f[] = "--data-dir /home/ntopng";
    $f[] = "--pid /var/run/ntopng/ntopng.pid";
    $f[] = "--dump-flows";
    $f[] = all_interfaces();
    if (intval($arrayConf["ENABLE_LOGIN"]) == 0) {
        $f[] = "--disable-login";
    }
    $cmd = @implode(" ", $f);
    shell_exec($cmd);
    $c = 1;
    for ($i = 0; $i < 10; $i++) {
        sleep(1);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Starting service waiting {$c}/10\n";
        }
        $pid = ntopng_pid();
        if ($unix->process_exists($pid)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Success PID {$pid}\n";
            }
            break;
        }
        $c++;
    }
    $pid = ntopng_pid();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Failed\n";
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} {$cmd}\n";
        }
    }
}
Exemplo n.º 3
0
function redis_server()
{
    $masterbin = $GLOBALS["CLASS_UNIX"]->find_program("ntopng");
    if (!is_file($masterbin)) {
        return;
    }
    $enabled = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("Enablentopng"));
    $SquidPerformance = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("SquidPerformance"));
    if ($SquidPerformance > 2) {
        $Enablentopng = 0;
    }
    $l[] = "[APP_REDIS_SERVER]";
    $l[] = "service_name=APP_REDIS_SERVER";
    $l[] = "master_version=" . redis_version();
    $l[] = "service_cmd=/etc/init.d/redis-server";
    $l[] = "service_disabled={$enabled}";
    $l[] = "family=proxy";
    $l[] = "watchdog_features=1";
    if ($enabled == 0) {
        $master_pid = redis_pid();
        if ($GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
            shell_exec2("{$GLOBALS["nohup"]} /etc/init.d/ntopng stop >/dev/null 2>&1 &");
        }
        return implode("\n", $l);
        return;
    }
    $master_pid = redis_pid();
    if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
        if (!$GLOBALS["DISABLE_WATCHDOG"]) {
            shell_exec2("{$GLOBALS["nohup"]} /etc/init.d/redis-server start >/dev/null 2>&1 &");
        }
        $l[] = "running=0\ninstalled=1";
        $l[] = "";
        return implode("\n", $l);
    }
    $l[] = "running=1";
    $l[] = GetMemoriesOf($master_pid);
    $l[] = "";
    return implode("\n", $l);
    return;
}