コード例 #1
0
function start_squid($aspid = false)
{
    $GLOBALS["LOGS"] = array();
    $suffix = null;
    if ($GLOBALS["MONIT"]) {
        $suffix = " (by system monitor)";
    }
    if ($GLOBALS["BY_CACHE_LOGS"]) {
        $suffix = " (by cache.log monitor)";
    }
    if ($GLOBALS["BY_STATUS"]) {
        $suffix = " (by Artica monitor)";
    }
    if ($GLOBALS["BY_CLASS_UNIX"]) {
        $suffix = " (by Artica class.unix.inc)";
    }
    if ($GLOBALS["BY_FRAMEWORK"]) {
        $suffix = " (by Artica framework)";
    }
    if ($GLOBALS["BY_OTHER_SCRIPT"]) {
        $suffix = " (by other script)";
    }
    if ($GLOBALS["BY_ARTICA_INSTALL"]) {
        $suffix = " (by artica-install)";
    }
    if ($GLOBALS["BY_FORCE_RECONFIGURE"]) {
        $suffix = " (after building settings)";
    }
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    $sock = new sockets();
    $reconfigure = false;
    $SQUIDEnable = $sock->GET_INFO("SQUIDEnable");
    $NtpdateAD = $sock->GET_INFO("NtpdateAD");
    if (!is_numeric($SQUIDEnable)) {
        $SQUIDEnable = 1;
    }
    $kill = $unix->find_program("kill");
    if (!is_numeric($NtpdateAD)) {
        $NtpdateAD = 0;
    }
    $su_bin = $unix->find_program("su");
    $sysctl = $unix->find_program("sysctl");
    $squidbin = $unix->LOCATE_SQUID_BIN();
    if (!is_file($squidbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Restart......: Squid-cache, not installed\n";
        }
        return;
    }
    if ($GLOBALS["MONIT"]) {
        if (function_exists("debug_backtrace")) {
            $trace = debug_backtrace();
            if (isset($trace[1])) {
                $file = basename($trace[1]["file"]);
                $function = $trace[1]["function"];
                $line = $trace[1]["line"];
                $called = "Called by {$function}() from line {$line}";
            }
        }
        $pid = SQUID_PID();
        if ($unix->process_exists($pid)) {
            $ps = $unix->find_program("ps");
            $grep = $unix->find_program("grep");
            exec("{$ps} aux|{$grep} squid 2>&1", $results);
            squid_admin_mysql(2, "Monit ordered to start squid but squid is still in memory PID {$pid} ??", "I cannot accept this order, see details\n" . @implode("\n", $results), __FILE__, __LINE__);
            $squidpidfile = $unix->LOCATE_SQUID_PID();
            @file_put_contents($squidpidfile, $pid);
            return;
        }
        squid_admin_mysql(1, "Monit ordered to start squid", $called, __FILE__, __LINE__);
    }
    if ($SQUIDEnable == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " Squid is disabled...\n";
        }
        return;
    }
    if (is_file("/etc/artica-postfix/squid.lock")) {
        $time = $unix->file_time_min("/etc/artica-postfix/squid.lock");
        if ($time < 60) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " Squid is locked (since {$time}Mn...\n";
            }
            return;
        }
        @unlink("/etc/artica-postfix/squid.lock");
    }
    $pids = $unix->PIDOF_PATTERN_ALL("exec.squid.watchdog.php --start");
    if (count($pids) > 2) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " Too many instances " . count($pids) . " starting squid, kill them!\n";
        }
        $mypid = getmypid();
        while (list($pid, $ligne) = each($pids)) {
            if ($pid == $mypid) {
                continue;
            }
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " killing {$pid}\n";
            }
            unix_system_kill_force($pid);
        }
    }
    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 ($time < 5) {
                Events("Task Already running PID {$pid} since {$time}mn");
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " Already task running PID {$pid} since {$time}mn, Aborting operation (" . __LINE__ . ")\n";
                }
                return;
            }
            squid_admin_mysql(0, "Too long time for artica task PID {$pid} running since {$time}mn", "Process will be killed");
            Tosyslog("Too long time for artica task PID {$pid} running since {$time}mn -> kill");
            unix_system_kill_force($pid);
        }
        @file_put_contents($pidfile, getmypid());
    }
    $squidbin = $unix->find_program("squid");
    if (!is_file($squidbin)) {
        $squidbin = $unix->find_program("squid3");
    }
    if (!is_file($squidbin)) {
        system_admin_events("Squid not seems to be installed", __FUNCTION__, __FILE__, __LINE__, "proxy");
        return;
    }
    @chmod($squidbin, 0755);
    $sock = new sockets();
    $DisableForceFCK = intval($sock->GET_INFO("DisableForceFCK"));
    if ($DisableForceFCK == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " Will force a checkdisk At next reboot\n";
        }
        @touch("/forcefsck");
    }
    start_prepare();
    $pid = SQUID_PID();
    if ($GLOBALS["CRASHED"]) {
        for ($i = 0; $i < 10; $i++) {
            sleep(1);
            $pid = SQUID_PID();
            if ($unix->process_exists($pid)) {
                continue;
            }
            break;
        }
        squid_admin_mysql(2, "No need to start Proxy service after a crash", "It seems the watchdog detect a crash but after 10s the proxy still running\nOperation is aborted", __FILE__, __LINE__);
        return;
    }
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " Proxy service already running pid {$pid} since {$time}mn\n";
        }
        system_admin_events("Squid seems to already running pid {$pid} since {$time}mn", __FUNCTION__, __FILE__, __LINE__, "proxy");
        return;
    }
    $unix->TCP_TUNE_SQUID_DEFAULT();
    $t1 = time();
    SendLogs("Checking caches...");
    $cacheBooster = new squidbooster();
    $cacheBooster->cache_booster();
    CheckStoreDirs(true);
    SendLogs("Checking caches done...");
    SendLogs("Checking Ports...");
    $array = CheckAllports();
    SendLogs("Checking " . count($array) . " ports");
    while (list($port, $ligne) = each($array)) {
        $portZ = $unix->PIDOF_BY_PORT($port);
        SendLogs("Checking port {$port} - " . count($portZ) . " process(es)");
        if (count($portZ) > 0) {
            while (list($pid, $ligne) = each($portZ)) {
                SendLogs("Checking port {$port} - killing pid {$pid}");
                shell_exec("kill -9 {$pid} >/dev/null 2>&1");
            }
        }
    }
    SendLogs("Starting squid {$squidbin}....");
    $echo = $unix->find_program("echo");
    $size = round(@filesize("/var/log/squid/cache.log") / 1024, 2) / 1024;
    if ($size > 10) {
        @copy("/var/log/squid/cache.log", "/var/log/squid/cache.log." . time());
        shell_exec("{$echo} \" \"> /var/log/squid/cache.log 2>&1");
    }
    @chmod($squidbin, 0755);
    @chmod("/var/log/squid", 0755);
    if (is_link("/var/log/squid")) {
        @chmod(readlink("/var/log/squid"), 0755);
    }
    squid_admin_mysql(1, "Starting Squid-cache service {$suffix}", @implode("\n", $GLOBALS["LOGS"]), __FILE__, __LINE__);
    exec("{$squidbin} -f /etc/squid3/squid.conf 2>&1", $GLOBALS["LOGS"]);
    $PRC = 40;
    $MAXPRC = 60;
    $AB = 0;
    for ($i = 0; $i < 10; $i++) {
        $PRC++;
        if ($PRC > $MAXPRC - 1) {
            $PRC = $MAXPRC - 1;
        }
        build_progress_restart("{starting_service}", $PRC);
        $pid = SQUID_PID();
        if ($unix->process_exists($pid)) {
            SendLogs("Starting squid started pid {$pid}...");
            break;
        }
        ToSyslog("Starting squid waiting {$i}/10s");
        SendLogs("Starting squid waiting {$i}/10s");
        sleep(1);
    }
    if (!$unix->process_exists($pid)) {
        SendLogs("Starting Squid failed to start...");
        ToSyslog("Starting Squid failed to start...");
        if (function_exists("debug_backtrace")) {
            $trace = debug_backtrace();
            if (isset($trace[1])) {
                $sourcefunction = $trace[1]["function"];
                $sourceline = $trace[1]["line"];
                $executed = "Executed by {$sourcefunction}() line {$sourceline}\nusing argv:{$GLOBALS["ARGVS"]}\n";
            }
        }
        squid_admin_mysql(0, "Squid failed to start {$suffix}", @implode("\n", $GLOBALS["LOGS"]) . "\n{$executed}");
        squid_admin_notifs("Starting Squid failed to start\n" . @implode("\n", $GLOBALS["LOGS"]) . "\n{$executed}", __FUNCTION__, __FILE__, __LINE__, "proxy");
        system_admin_events("Starting Squid failed to start\n" . @implode("\n", $GLOBALS["LOGS"]), __FUNCTION__, __FILE__, __LINE__, "proxy");
        return;
    }
    SendLogs("Starting Squid Tests if it listen all connections....");
    for ($i = 0; $i < 10; $i++) {
        if (is_started()) {
            SendLogs("Starting squid listen All connections OK");
            break;
        }
        SendLogs("Starting squid listen All connections... waiting {$i}/10");
        sleep(1);
    }
    $took = $unix->distanceOfTimeInWords($t1, time());
    $nohup = $unix->find_program("nohup");
    SendLogs("Starting Squid success to start PID {$pid}...");
    if (function_exists("debug_backtrace")) {
        $trace = debug_backtrace();
        if (isset($trace[1])) {
            $sourcefunction = $trace[1]["function"];
            $sourceline = $trace[1]["line"];
            $executed = "Executed by {$sourcefunction}() line {$sourceline}\nusing argv:{$GLOBALS["ARGVS"]}\n";
        }
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    system_admin_events("Starting Squid success to start PID {$pid} took {$took}\n" . @implode("\n", $GLOBALS["LOGS"]), __FUNCTION__, __FILE__, __LINE__, "proxy");
    SendLogs("Starting Squid finishing Reloading DNSMasq");
    shell_exec("{$nohup} /etc/init.d/dnsmasq reload >/dev/null 2>&1 &");
    SendLogs("Starting Squid finishing Starting Squid-cache tail");
    shell_exec("{$nohup} /etc/init.d/artica-postfix start squidcache-tail >/dev/null 2>&1 &");
    SendLogs("Starting Squid finishing Starting auth-cache tail");
    shell_exec("{$nohup} /etc/init.d/auth-tail restart >/dev/null 2>&1 &");
    SendLogs("Starting Squid finishing Reconfiguring proxy.pac scripts");
    shell_exec("{$nohup} {$php5} " . basename(__FILE__) . "/exec.proxy.pac.php --write 2>&1 &");
    SendLogs("Starting Squid done...");
    shell_exec("{$nohup} {$php5} " . basename(__FILE__) . "/exec.cache.pages.php --force >/dev/null 2>&1 &");
}
コード例 #2
0
function start_squid($aspid = false)
{
    $GLOBALS["LOGS"] = array();
    $suffix = null;
    if ($GLOBALS["MONIT"]) {
        $suffix = " (by system monitor)";
    }
    if ($GLOBALS["BY_CACHE_LOGS"]) {
        $suffix = " (by cache.log monitor)";
    }
    if ($GLOBALS["BY_STATUS"]) {
        $suffix = " (by Artica monitor)";
    }
    if ($GLOBALS["BY_CLASS_UNIX"]) {
        $suffix = " (by Artica class.unix.inc)";
    }
    if ($GLOBALS["BY_FRAMEWORK"]) {
        $suffix = " (by Artica framework)";
    }
    if ($GLOBALS["BY_OTHER_SCRIPT"]) {
        $suffix = " (by other script)";
    }
    if ($GLOBALS["BY_ARTICA_INSTALL"]) {
        $suffix = " (by artica-install)";
    }
    if ($GLOBALS["BY_FORCE_RECONFIGURE"]) {
        $suffix = " (after building settings)";
    }
    $unix = new unix();
    $php = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    $sock = new sockets();
    $reconfigure = false;
    $SQUIDEnable = $sock->GET_INFO("SQUIDEnable");
    $NtpdateAD = $sock->GET_INFO("NtpdateAD");
    if (!is_numeric($SQUIDEnable)) {
        $SQUIDEnable = 1;
    }
    $kill = $unix->find_program("kill");
    if (!is_numeric($NtpdateAD)) {
        $NtpdateAD = 0;
    }
    $su_bin = $unix->find_program("su");
    $sysctl = $unix->find_program("sysctl");
    $squidbin = $unix->LOCATE_SQUID_BIN();
    if (!is_file($squidbin)) {
        build_progress_start("Not installed", 110);
        if ($GLOBALS["OUTPUT"]) {
            echo "Restart......: Squid-cache, not installed\n";
        }
        return;
    }
    if ($GLOBALS["MONIT"]) {
        if (function_exists("debug_backtrace")) {
            $trace = debug_backtrace();
            if (isset($trace[1])) {
                $file = basename($trace[1]["file"]);
                $function = $trace[1]["function"];
                $line = $trace[1]["line"];
                $called = "Called by {$function}() from line {$line}";
            }
        }
        $pid = SQUID_PID();
        if ($unix->process_exists($pid)) {
            $ps = $unix->find_program("ps");
            $grep = $unix->find_program("grep");
            exec("{$ps} aux|{$grep} squid 2>&1", $results);
            squid_admin_mysql(2, "Monit ordered to start squid but squid is still in memory PID {$pid} ??", "I cannot accept this order, see details\n" . @implode("\n", $results), __FILE__, __LINE__);
            $squidpidfile = $unix->LOCATE_SQUID_PID();
            @file_put_contents($squidpidfile, $pid);
            return;
        }
        squid_admin_mysql(1, "Monit ordered to start squid", $called, __FILE__, __LINE__);
    }
    if ($SQUIDEnable == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " Squid is disabled...\n";
        }
        build_progress_start("Proxy service is disabled", 110);
        return;
    }
    if (is_file("/etc/init.d/iptables-transparent")) {
        shell_exec("/etc/init.d/iptables-transparent start");
    }
    if (is_file("/etc/artica-postfix/squid.lock")) {
        $time = $unix->file_time_min("/etc/artica-postfix/squid.lock");
        if ($time < 60) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " Proxy is locked (since {$time}Mn...\n";
            }
            build_progress_start(" Proxy is locked (since {$time}Mn", 110);
            return;
        }
        @unlink("/etc/artica-postfix/squid.lock");
    }
    $pids = $unix->PIDOF_PATTERN_ALL("exec.squid.watchdog.php --start");
    if (count($pids) > 2) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " Too many instances " . count($pids) . " starting squid, kill them!\n";
        }
        $mypid = getmypid();
        while (list($pid, $ligne) = each($pids)) {
            if ($pid == $mypid) {
                continue;
            }
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " killing {$pid}\n";
            }
            unix_system_kill_force($pid);
        }
    }
    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 ($time < 5) {
                build_progress_start("Task Already running PID {$pid} since {$time}mn", 110);
                Events("Task Already running PID {$pid} since {$time}mn");
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " Already task running PID {$pid} since {$time}mn, Aborting operation (" . __LINE__ . ")\n";
                }
                return;
            }
            squid_admin_mysql(0, "Too long time for artica task PID {$pid} running since {$time}mn", "Process will be killed");
            Tosyslog("Too long time for artica task PID {$pid} running since {$time}mn -> kill");
            unix_system_kill_force($pid);
        }
        @file_put_contents($pidfile, getmypid());
    }
    $squidbin = $unix->find_program("squid");
    if (!is_file($squidbin)) {
        $squidbin = $unix->find_program("squid3");
    }
    if (!is_file($squidbin)) {
        build_progress_start("Not installed", 110);
        system_admin_events("Squid not seems to be installed", __FUNCTION__, __FILE__, __LINE__, "proxy");
        return;
    }
    @chmod($squidbin, 0755);
    $sock = new sockets();
    $DisableForceFCK = intval($sock->GET_INFO("DisableForceFCK"));
    if ($DisableForceFCK == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " Will force a checkdisk At next reboot\n";
        }
        @touch("/forcefsck");
    }
    $pid = SQUID_PID();
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        build_progress_start("Proxy service already running since {$time}Mn", 50);
        if ($GLOBALS["START_PROGRESS"]) {
            $php = $unix->LOCATE_PHP5_BIN();
            build_progress_start("Removing caches...", 55);
            @unlink("/usr/share/artica-postfix/ressources/databases/ALL_SQUID_STATUS");
            build_progress_start("Building caches...", 70);
            system("{$php} /usr/share/artica-postfix/exec.status.php --all-squid");
            if (!is_file("/usr/share/artica-postfix/ressources/databases/ALL_SQUID_STATUS")) {
                build_progress_start("Fatal!! Watchdog issue!!", 110);
                return;
            }
            build_progress_start("{done}", 100);
        }
        return;
    }
    build_progress_start("Preparing proxy service", 50);
    start_prepare();
    $squid_checks = new squid_checks();
    $squid_checks->squid_parse();
    build_progress_start("{starting_proxy_service}", 60);
    $pid = SQUID_PID();
    if ($GLOBALS["CRASHED"]) {
        for ($i = 0; $i < 10; $i++) {
            sleep(1);
            $pid = SQUID_PID();
            if ($unix->process_exists($pid)) {
                continue;
            }
            break;
        }
        squid_admin_mysql(2, "No need to start Proxy service after a crash", "It seems the watchdog detect a crash but after 10s the proxy still running\nOperation is aborted", __FILE__, __LINE__);
        return;
    }
    build_progress_start("Tuning network", 70);
    $unix->TCP_TUNE_SQUID_DEFAULT();
    $t1 = time();
    build_progress_start("Checking caches", 71);
    SendLogs("Checking caches...");
    $cacheBooster = new squidbooster();
    $cacheBooster->cache_booster();
    build_progress_start("Checking caches", 73);
    CheckStoreDirs(true);
    SendLogs("Checking caches done...");
    build_progress_start("Checking Ports", 75);
    SendLogs("Checking Ports...");
    $array = CheckAllports();
    SendLogs("Checking " . count($array) . " ports");
    while (list($port, $ligne) = each($array)) {
        $portZ = $unix->PIDOF_BY_PORT($port);
        SendLogs("Checking port {$port} - " . count($portZ) . " process(es)");
        if (count($portZ) > 0) {
            while (list($pid, $ligne) = each($portZ)) {
                SendLogs("Checking port {$port} - killing pid {$pid}");
                shell_exec("kill -9 {$pid} >/dev/null 2>&1");
            }
        }
    }
    build_progress_start("Checking SHM", 75);
    system("{$php} /usr/share/artica-postfix/exec.squid.smp.php");
    SendLogs("Starting squid {$squidbin}....");
    $echo = $unix->find_program("echo");
    $size = round(@filesize("/var/log/squid/cache.log") / 1024, 2) / 1024;
    if ($size > 50) {
        squid_admin_mysql(2, "Cleaning cache.log {$size}MB", null, __FILE__, __LINE__);
        @copy("/var/log/squid/cache.log", "/var/log/squid/cache.log." . time());
        shell_exec("{$echo} \" \"> /var/log/squid/cache.log 2>&1");
    }
    @chmod($squidbin, 0755);
    @chmod("/var/log/squid", 0755);
    if (is_link("/var/log/squid")) {
        @chmod(readlink("/var/log/squid"), 0755);
    }
    squid_admin_mysql(1, "Starting Squid-cache service {$suffix}", @implode("\n", $GLOBALS["LOGS"]), __FILE__, __LINE__);
    build_progress_start("Remove SystemV5 Memory", 80);
    kill_shm();
    CHECK_WIFIDOG_IPTABLES_RULES();
    $PIDFILE = $unix->LOCATE_SQUID_PID();
    $f = array();
    $f[] = "#! /bin/sh";
    $f[] = ". /lib/lsb/init-functions";
    $f[] = "PATH=/bin:/usr/bin:/sbin:/usr/sbin";
    $f[] = "DAEMON=\"{$squidbin}\"";
    $f[] = "CONFIG=\"/etc/squid3/squid.conf\"";
    $f[] = "SQUID_ARGS=\"-YC -f \$CONFIG\"";
    $f[] = "PIDFILE=\"{$PIDFILE}\"";
    $f[] = "";
    $f[] = "KRB5RCACHETYPE=none";
    $f[] = "KRB5_KTNAME=/etc/squid3/PROXY.keytab";
    $f[] = "export KRB5RCACHETYPE";
    $f[] = "export KRB5_KTNAME";
    $f[] = "";
    $f[] = "";
    $f[] = "umask 027";
    $f[] = "ulimit -n 65535";
    $f[] = "start-stop-daemon --start --pidfile \$PIDFILE --exec \$DAEMON -- \$SQUID_ARGS";
    $f[] = "status=\$?";
    $f[] = "if [ \$status -eq 0 ]";
    $f[] = "\tthen";
    $f[] = "\t        echo \"Success starting Proxy service\"";
    $f[] = "\tfi ";
    $f[] = "exit 0\n";
    @file_put_contents("/usr/sbin/squid-start", @implode("\n", $f));
    $f = array();
    @chmod("/usr/sbin/squid-start", 0755);
    exec("/usr/sbin/squid-start 2>&1", $GLOBALS["LOGS"]);
    $PRC = 40;
    $MAXPRC = 60;
    $AB = 0;
    $TESTFAILED = false;
    while (list($index, $line) = each($GLOBALS["LOGS"])) {
        if (preg_match("#FATAL: Bungled#", $line)) {
            squid_admin_mysql(1, "Alert: Bungled configuration when starting Proxy", $line, __FILE__, __LINE__);
            $TESTFAILED = true;
            break;
        }
    }
    if ($TESTFAILED) {
        $TESTFAILED = false;
        if (!is_file("/etc/artica-postfix/SQUID_TEST_FAILED")) {
            build_progress_start("Reconfigure Proxy service", 80);
            system("{$php} /usr/share/artica-postfix/exec.squid.php --build --force");
        }
        $GLOBALS["LOGS"] = array();
        exec("{$squidbin} -f /etc/squid3/squid.conf 2>&1", $GLOBALS["LOGS"]);
        while (list($index, $line) = each($GLOBALS["LOGS"])) {
            if (preg_match("#FATAL: Bungled#", $line)) {
                squid_admin_mysql(1, "Alert: Bungled configuration after reconfiguring Proxy", $line, __FILE__, __LINE__);
                $TESTFAILED = true;
                break;
            }
        }
    }
    if ($TESTFAILED) {
        @touch("/etc/artica-postfix/SQUID_TEST_FAILED");
        build_progress_start("Start Proxy service {failed}", 110);
        die;
    }
    @unlink("/etc/artica-postfix/SQUID_TEST_FAILED");
    for ($i = 0; $i < 10; $i++) {
        $PRC++;
        if ($PRC > $MAXPRC - 1) {
            $PRC = $MAXPRC - 1;
        }
        build_progress_start("{starting_service} {$i}/10", 85);
        build_progress_restart("{starting_service}", $PRC);
        $pid = SQUID_PID();
        if ($unix->process_exists($pid)) {
            SendLogs("Starting squid started pid {$pid}...");
            break;
        }
        ToSyslog("Starting squid waiting {$i}/10s");
        SendLogs("Starting squid waiting {$i}/10s");
        sleep(1);
    }
    if (!$unix->process_exists($pid)) {
        build_progress_start("{failed}", 110);
        SendLogs("Starting Squid failed to start...");
        ToSyslog("Starting Squid failed to start...");
        if (function_exists("debug_backtrace")) {
            $trace = debug_backtrace();
            if (isset($trace[1])) {
                $sourcefunction = $trace[1]["function"];
                $sourceline = $trace[1]["line"];
                $executed = "Executed by {$sourcefunction}() line {$sourceline}\nusing argv:{$GLOBALS["ARGVS"]}\n";
            }
        }
        squid_admin_mysql(0, "Squid failed to start {$suffix}", @implode("\n", $GLOBALS["LOGS"]) . "\n{$executed}");
        system_admin_events("Starting Squid failed to start\n" . @implode("\n", $GLOBALS["LOGS"]), __FUNCTION__, __FILE__, __LINE__, "proxy");
        return;
    }
    SendLogs("Starting Squid Tests if it listen all connections....");
    for ($i = 0; $i < 10; $i++) {
        build_progress_start("{checking} {$i}/10", 90);
        if (is_started()) {
            SendLogs("Starting squid listen All connections OK");
            break;
        }
        SendLogs("Starting squid listen All connections... waiting {$i}/10");
        sleep(1);
    }
    $took = $unix->distanceOfTimeInWords($t1, time());
    $nohup = $unix->find_program("nohup");
    SendLogs("Starting Squid success to start PID {$pid}...");
    if (function_exists("debug_backtrace")) {
        $trace = debug_backtrace();
        if (isset($trace[1])) {
            $sourcefunction = $trace[1]["function"];
            $sourceline = $trace[1]["line"];
            $executed = "Executed by {$sourcefunction}() line {$sourceline}\nusing argv:{$GLOBALS["ARGVS"]}\n";
        }
    }
    $php5 = $unix->LOCATE_PHP5_BIN();
    taskset();
    build_progress_start("Restarting cache-tail", 91);
    shell_exec("{$nohup} /etc/init.d/cache-tail restart >/dev/null 2>&1 &");
    build_progress_start("Restarting access-tail", 92);
    shell_exec("{$nohup} /etc/init.d/squid-tail restart >/dev/null 2>&1 &");
    build_progress_start("Restarting auth-tail", 93);
    shell_exec("{$nohup} /etc/init.d/auth-tail restart >/dev/null 2>&1 &");
    build_progress_start("{done}", 100);
    system_admin_events("Starting Squid success to start PID {$pid} took {$took}\n" . @implode("\n", $GLOBALS["LOGS"]), __FUNCTION__, __FILE__, __LINE__, "proxy");
    SendLogs("Starting Squid done...");
    if (is_file("/usr/share/artica-postfix/ressources/databases/ALL_SQUID_STATUS")) {
        @unlink("/usr/share/artica-postfix/ressources/databases/ALL_SQUID_STATUS");
    }
}