Exemplo n.º 1
0
function stop($aspid = false)
{
    $unix = new unix();
    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 "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
        @file_put_contents($pidfile, getmypid());
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service already stopped...\n";
        }
        return;
    }
    $pid = PID_NUM();
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $kill = $unix->find_program("kill");
    vsftpd_admin_mysql(1, "Shutdown VSFTPD service...", null, __FILE__, __LINE__);
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service Shutdown pid {$pid}...\n";
    }
    unix_system_kill($pid);
    for ($i = 0; $i < 5; $i++) {
        $pid = PID_NUM();
        if (!$unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n";
        }
        sleep(1);
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service success...\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service shutdown - force - pid {$pid}...\n";
    }
    unix_system_kill_force($pid);
    for ($i = 0; $i < 5; $i++) {
        $pid = PID_NUM();
        if (!$unix->process_exists($pid)) {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service waiting pid:{$pid} {$i}/5...\n";
        }
        sleep(1);
    }
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$GLOBALS["TITLENAME"]} service failed...\n";
        }
        return;
    }
}
Exemplo n.º 2
0
function vsftpd()
{
    $snmpd = $GLOBALS["CLASS_UNIX"]->find_program("vsftpd");
    if (!is_file($snmpd)) {
        return;
    }
    $enabled = $GLOBALS["CLASS_SOCKETS"]->GET_INFO("EnableVSFTPDDaemon");
    if (!is_numeric($enabled)) {
        $enabled = 0;
    }
    $master_pid = vsftpd_pid();
    $l[] = "[APP_VSFTPD]";
    $l[] = "service_name=APP_VSFTPD";
    $l[] = "master_version=2.3.5";
    $l[] = "service_cmd=/etc/init.d/vsftpd";
    $l[] = "service_disabled={$enabled}";
    $l[] = "family=system";
    $l[] = "pid_path={$pid_path}";
    $l[] = "watchdog_features=1";
    if ($enabled == 0) {
        return implode("\n", $l);
        return;
    }
    if (!$GLOBALS["CLASS_UNIX"]->process_exists($master_pid)) {
        if (!$GLOBALS["DISABLE_WATCHDOG"]) {
            vsftpd_admin_mysql(0, "Starting VSFTPD service [not running]", null, __FILE__, __LINE__);
            $cmd = trim("{$GLOBALS["NICE"]}{$GLOBALS["PHP5"]} " . dirname(__FILE__) . "/exec.vsftpd.php --start");
            shell_exec2($cmd);
        }
        $l[] = "running=0\ninstalled=1";
        $l[] = "";
        return implode("\n", $l);
        return;
    } else {
        if ($enabled == 0) {
            vsftpd_admin_mysql(0, "Stopping VSFTPD service EnableVSFTPDDaemon = 0", null, __FILE__, __LINE__);
            shell_exec2("{$GLOBALS["nohup"]} /etc/init.d/vsftpd stop >/dev/null 2>&1 &");
        }
    }
    $l[] = "running=1";
    $l[] = GetMemoriesOf($master_pid);
    $l[] = "";
    return implode("\n", $l);
    return;
}