function start()
{
    $unix = new unix();
    $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]: {$GLOBALS["TITLENAME"]} Already Artica task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $PID = GET_PID();
    if ($unix->process_exists($PID)) {
        squid_admin_mysql(1, "Watchdog says that rsyslog is off, but exists [action=stamp-pid]", null, __FILE__, __LINE__);
        $SrcPid = intval(@file_get_contents("/var/run/rsyslogd.pid"));
        if ($SrcPid != $PID) {
            squid_admin_mysql(2, "Watchdog says that rsyslog is off (PID:{$SrcPid}), but exists (PID:{$PID}) [action=stamp-pid]", null, __FILE__, __LINE__);
            @file_put_contents("/var/run/rsyslogd.pid", $PID);
        } else {
            squid_admin_mysql(2, "Watchdog says that rsyslog is off (PID:{$SrcPid}), but exists [action=nothing]", null, __FILE__, __LINE__);
        }
        @unlink($pidfile);
        die(1);
    }
    squid_admin_mysql(0, "Syslog daemon is down [action=start]", null, __FILE__, __LINE__);
    system("/etc/init.d/rsyslog start");
    $squid = $unix->LOCATE_SQUID_BIN();
    if (is_file($squid)) {
        sleep(3);
        squid_admin_mysql(1, "Reloading proxy service after starting syslog daemon", null, __FILE__, __LINE__);
        system("{$squid} -f /etc/squid3/squid.conf -k reconfigure");
    }
}
Esempio n. 2
0
function stop($ID)
{
    $SERV_NAME = $GLOBALS["SERV_NAME"];
    $unix = new unix();
    $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]: Already task running PID {$pid} since {$time}mn\n";
        }
        return;
    }
    $pid = GET_PID($ID);
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} already stopped...\n";
        }
        return;
    }
    $kill = $unix->find_program("kill");
    $time = $unix->PROCCESS_TIME_MIN($pid);
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: Stopping {$SERV_NAME} with a ttl of {$time}mn\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: Stopping {$SERV_NAME} smoothly...\n";
    }
    $cmd = "{$kill} {$pid} >/dev/null";
    shell_exec($cmd);
    $pid = GET_PID($ID);
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} success...\n";
        }
        return;
    }
    for ($i = 0; $i < 10; $i++) {
        $pid = GET_PID($ID);
        if ($unix->process_exists($pid)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} kill pid {$pid}..\n";
            }
            unix_system_kill_force($pid);
        } else {
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} wait {$i}/10\n";
        }
        sleep(1);
    }
    $pid = GET_PID($ID);
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} success...\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Stopping......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} Failed...\n";
    }
}