function start_watchdog()
{
    if ($GLOBALS["VERBOSE"]) {
        $GLOBALS["FORCE"] = true;
    }
    $pidtime = "/etc/artica-postfix/pids/exec.squid.watchdog.php.start_watchdog.time";
    $pidFile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $pidtimeNTP = "/etc/artica-postfix/pids/exec.squid.watchdog.php.start_watchdog.ntp.time";
    $unix = new unix();
    $pid = $unix->get_pid_from_file($pidFile);
    if ($unix->process_exists($pid)) {
        $pptime = $unix->PROCCESS_TIME_MIN($pid, 10);
        if ($GLOBALS["VERBOSE"]) {
            echo "Process already running PID {$pid} since {$pptime}Mn\n";
        }
        return;
    }
    @file_put_contents($pidFile, getmypid());
    $time = $unix->file_time_min($pidtime);
    $sock = new sockets();
    $nohup = $unix->find_program("nohup");
    $php = $unix->LOCATE_PHP5_BIN();
    $NtpdateAD = intval($sock->GET_INFO("NtpdateAD"));
    $EnableFailover = $sock->GET_INFO("EnableFailover");
    $GLOBALS["EnableFailover"] = $sock->GET_INFO("EnableFailover");
    $SQUIDEnable = trim($sock->GET_INFO("SQUIDEnable"));
    if (!is_numeric($SQUIDEnable)) {
        $SQUIDEnable = 1;
    }
    if (!is_numeric($EnableFailover)) {
        $EnableFailover = 1;
    }
    if (!is_file("/usr/share/squid3/icons/silk/bigshield-256.png")) {
        @copy("/usr/share/artica-postfix/img/bigshield-256.png", "/usr/share/squid3/icons/silk/bigshield-256.png");
    }
    if (!is_file("/usr/share/squid3/icons/silk/logo-artica-64.png")) {
        @copy("/usr/share/artica-postfix/img/logo-artica-64.png", "/usr/share/squid3/icons/silk/logo-artica-64.png");
    }
    $articafiles[] = "exec.logfile_daemon.php";
    $articafiles[] = "external_acl_squid_ldap.php";
    $articafiles[] = "external_acl_dynamic.php";
    $articafiles[] = "external_acl_quota.php";
    $articafiles[] = "external_acl_basic_auth.php";
    $articafiles[] = "external_acl_squid.php";
    $articafiles[] = "external_acl_restrict_access.php";
    while (list($num, $filename) = each($articafiles)) {
        $filepath = "/usr/share/artica-postfix/{$filename}";
        @chmod($filepath, 0755);
        @chown($filepath, "squid");
        @chgrp($filepath, "squid");
    }
    @unlink($pidtime);
    @file_put_contents($pidtime, time());
    if ($SQUIDEnable == 0) {
        die;
    }
    ALL_STATUS(true);
    $MonitConfig = unserialize(base64_decode($sock->GET_INFO("SquidWatchdogMonitConfig")));
    $MonitConfig["EnableFailover"] = $EnableFailover;
    $MonitConfig = watchdog_config_default($MonitConfig);
    $unix->chmod_func(0755, "/etc/artica-postfix/settings/Daemons/*");
    @mkdir("{$GLOBALS["ARTICALOGDIR"]}/squid/mysql-failed", 0755, true);
    $unix->chown_func("squid", "squid", "{$GLOBALS["ARTICALOGDIR"]}/squid/mysql-failed");
    if (!$GLOBALS["VERBOSE"]) {
        if ($time < $MonitConfig["MIN_INTERVAL"]) {
            return;
        }
    }
    $STAMP_MAX_RESTART_TIME = $unix->file_time_min($GLOBALS["STAMP_MAX_RESTART"]);
    if ($STAMP_MAX_RESTART_TIME > 60) {
        @unlink($GLOBALS["STAMP_MAX_RESTART"]);
    }
    //Events("Start: ". basename($pidtime).":{$time}Mn / {$MonitConfig["MIN_INTERVAL"]}Mn STAMP_MAX_RESTART_TIME={$STAMP_MAX_RESTART_TIME}Mn");
    if (!is_file("/etc/artica-postfix/SQUID_TEMPLATE_DONE")) {
        mysql_admin_mysql(1, "SQUID_TEMPLATE_DONE: No such file, launch build template action...", null, __FILE__, __LINE__);
        shell_exec("{$nohup} {$php} " . dirname(__FILE__) . "/exec.squid.php --tpl-save >/dev/null 2>&1 &");
    }
    $GLOBALS["ALL_SCORES"] = 0;
    $pid = SQUID_PID();
    $processtime = $unix->PROCCESS_TIME_MIN($pid);
    if (!$GLOBALS["FORCE"]) {
        if ($processtime < 2) {
            return;
        }
    }
    CHECK_STREAMCACHE();
    CACHE_DIR_SIZE_CACHES();
    verify_var_log();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after START";
    CHECK_SARG();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after CHECK_SARG();";
    Checks_mgrinfos($MonitConfig, true);
    ntlmauthenticator();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after ntlmauthenticator()";
    CheckOldCachesLog();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after CheckOldCachesLog()";
    DeletedCaches();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after DeletedCaches()";
    caches_center(true);
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after caches_center()";
    squid_stores_status();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after squid_stores_status()";
    squid_mem_status();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after squid_mem_status()";
    squid_memory_monitor();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after squid_memory_monitor()";
    caches_size();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after caches_size()";
    if ($MonitConfig["watchdog"] == 0) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Watchdog is disabled...\n";
        }
        counters(true);
        return;
    }
    if ($processtime < 5) {
        return;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "Check DefaultRoute\n";
    }
    DefaultRoute();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after DefaultRoute()";
    if ($GLOBALS["VERBOSE"]) {
        echo "Check UFDB\n";
    }
    CheckUFDBGuardLocalThreads();
    CheckUFDBGuardConfig();
    CheckUFDBGuardPort();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after CheckUFDBGuardConfig()";
    if ($GLOBALS["VERBOSE"]) {
        echo "PING_GATEWAY()\n";
    }
    PING_GATEWAY();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after PING_GATEWAY()";
    if ($GLOBALS["VERBOSE"]) {
        echo "SwapWatchdog()\n";
    }
    SwapWatchdog();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after SwapWatchdog()";
    if ($GLOBALS["VERBOSE"]) {
        echo "Checks_Winbindd()\n";
    }
    Checks_Winbindd();
    if ($GLOBALS["VERBOSE"]) {
        echo "CheckStoreDirs()\n";
    }
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after Checks_Winbindd()";
    CheckStoreDirs();
    if ($GLOBALS["VERBOSE"]) {
        echo "MemBoosters()\n";
    }
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after CheckStoreDirs()";
    MemBoosters();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after MemBoosters()";
    if ($GLOBALS["VERBOSE"]) {
        echo "SwapCache()\n";
    }
    SwapCache($MonitConfig);
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after SwapCache()";
    MaxSystemLoad($MonitConfig);
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after MaxSystemLoad()";
    if ($GLOBALS["VERBOSE"]) {
        echo "CheckAvailableSize()\n";
    }
    CheckAvailableSize();
    $GLOBALS["ALL_SCORES_WHY"][] = "score: {$GLOBALS["ALL_SCORES"]} after CheckAvailableSize()";
    FailOverCheck();
    DNSCACHE();
    cache_center_status();
    if ($GLOBALS["VERBOSE"]) {
        echo "counters()\n";
    }
    counters(true);
    if ($NtpdateAD == 1) {
        $pidtimeNTPT = $unix->file_time_min($pidtimeNTP);
        if ($pidtimeNTPT > 120) {
            if ($GLOBALS["VERBOSE"]) {
                echo "/usr/share/artica-postfix/exec.kerbauth.php --ntpdate\n";
            }
            shell_exec("{$nohup} {$php} /usr/share/artica-postfix/exec.kerbauth.php --ntpdate >/dev/null 2>&1 &");
            @unlink($pidtimeNTP);
            @file_put_contents($pidtimeNTP, time());
        }
    }
}
Beispiel #2
0
include_once dirname(__FILE__) . '/framework/class.monit.inc';
include_once dirname(__FILE__) . "/framework/frame.class.inc";
$GLOBALS["FORCE"] = false;
if (preg_match("#--force#", implode(" ", $argv))) {
    $GLOBALS["FORCE"] = true;
}
if ($argv[1] == "--start-process") {
    startprocess($argv[2], $argv[3]);
    exit;
}
if ($argv[1] == "--monit") {
    monit();
    die(0);
}
if ($argv[1] == "--squid-mem") {
    squid_memory_monitor();
    die;
}
if (!$GLOBALS["FORCE"]) {
    if (systemMaxOverloaded()) {
        error_log(basename(__FILE__) . "::Fatal: Aborting report, this system is too many overloaded...");
        die;
    }
}
$unix = new unix();
$GLOBALS["CLASS_UNIX"] = $unix;
$pidfile = "/etc/artica-postfix/" . basename(__FILE__) . "pid";
$currentpid = trim(@file_get_contents($pidfile));
if ($unix->process_exists($currentpid)) {
    die;
}