示例#1
0
function stop()
{
    $unix = new unix();
    $sock = new sockets();
    $masterbin = $unix->find_program("ntopng");
    if (!is_file($masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Not installed\n";
        }
        return;
    }
    $pid = ntopng_pid();
    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 = ntopng_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 = ntopng_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 = ntopng_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";
        }
    }
}
示例#2
0
function ntopng()
{
    $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"));
    $EnableIntelCeleron = intval($GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableIntelCeleron"));
    if ($SquidPerformance > 2) {
        $Enablentopng = 0;
    }
    if ($EnableIntelCeleron == 1) {
        $Enablentopng = 0;
    }
    $l[] = "[APP_NTOPNG]";
    $l[] = "service_name=APP_NTOPNG";
    $l[] = "master_version=" . ntopng_version();
    $l[] = "service_cmd=/etc/init.d/ntopng";
    $l[] = "service_disabled={$enabled}";
    $l[] = "family=proxy";
    $l[] = "watchdog_features=1";
    if ($enabled == 0) {
        $master_pid = ntopng_pid();
        if ($GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
            ToSyslog("Stopping ntopng pid {$master_pid}, service disabled");
            shell_exec2("{$GLOBALS["nohup"]} /etc/init.d/ntopng stop >/dev/null 2>&1 &");
        }
        return implode("\n", $l);
        return;
    }
    $master_pid = ntopng_pid();
    if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
        if (!$GLOBALS["DISABLE_WATCHDOG"]) {
            shell_exec2("{$GLOBALS["nohup"]} /etc/init.d/ntopng start >/dev/null 2>&1 &");
        }
        $l[] = "running=0\ninstalled=1";
        $l[] = "";
        return implode("\n", $l);
        return;
    }
    $l[] = "running=1";
    $l[] = GetMemoriesOf($master_pid);
    $l[] = "";
    $CacheFile = "/etc/artica-postfix/settings/Daemons/NTOPNgSize";
    if (!is_file($CacheFile)) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.ntopng.php --clean  >/dev/null 2>&1 &");
        return implode("\n", $l);
        return;
    }
    $time_file = $GLOBALS["CLASS_UNIX"]->file_time_min("/etc/artica-postfix/pids/exec.ntopng.php.cleanstorage.time");
    if ($time_file > 1880) {
        shell_exec2("{$GLOBALS["nohup"]} {$GLOBALS["NICE"]} {$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.ntopng.php --clean  >/dev/null 2>&1 &");
    }
    return implode("\n", $l);
    return;
}