예제 #1
0
function CHECK_STREAMCACHE()
{
    $unix = new unix();
    $sock = new sockets();
    $squid = new squidbee();
    $masterbin = $unix->find_program("streamsquidcache");
    if (!is_file($masterbin)) {
        return;
    }
    $enabled = intval($sock->GET_INFO("EnableStreamCache"));
    if ($enabled == 0) {
        return;
    }
    $php = $unix->LOCATE_PHP5_BIN();
    if (!is_file("/usr/share/videocache/videocache.py")) {
        squid_admin_mysql(0, "VideoCache backend ( missing videocache.py) not installed, re-install it...", null, __FILE__, __LINE__);
        shell_exec("{$php} /usr/share/artica-postfix/exec.squidstream.php --reinstall");
        return;
    }
    if (!is_file("/usr/share/videocache/vc-scheduler")) {
        squid_admin_mysql(0, "VideoCache backend ( missing vc-scheduler) not installed, re-install it...", null, __FILE__, __LINE__);
        shell_exec("{$php} /usr/share/artica-postfix/exec.squidstream.php --reinstall");
        return;
    }
    $VerifStreamProxyBindIP = $squid->VerifStreamProxyBindIP();
    $pid = streamsquidcache_pid();
    if ($GLOBALS["VERBOSE"]) {
        echo "streamsquidcache: PID: {$pid}\n";
    }
    if ($unix->process_exists($pid)) {
        if ($GLOBALS["VERBOSE"]) {
            echo "streamsquidcache: Running -> YES\n";
        }
    } else {
        if ($GLOBALS["VERBOSE"]) {
            echo "streamsquidcache: Running -> NO\n";
        }
        squid_admin_mysql(0, "VideoCache backend not running, start it...", null, __FILE__, __LINE__);
        shell_exec("/etc/init.d/squid-stream start");
        return;
    }
    $StreamCachePort = intval($sock->GET_INFO("StreamCachePort"));
    if ($StreamCachePort == 0) {
        $StreamCachePort = 5559;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "streamsquidcache: {$VerifStreamProxyBindIP}:{$StreamCachePort}\n";
    }
    if (!@fsockopen($VerifStreamProxyBindIP, $StreamCachePort, $errno, $errstr, 1)) {
        squid_admin_mysql(0, "VideoCache backend unable to open port {$VerifStreamProxyBindIP}:{$StreamCachePort} (action = restart)", "Err.{$errno} {$errstr}\n", __FILE__, __LINE__);
        shell_exec("/etc/init.d/squid-stream restart");
        return;
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "streamsquidcache: {$VerifStreamProxyBindIP}:{$StreamCachePort} OK\n";
    }
}
예제 #2
0
function reload($nopid = false)
{
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    if (!$nopid) {
        $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]: Already Artica task running PID {$pid} since {$time}mn\n";
            }
            return;
        }
    }
    @file_put_contents($pidfile, getmypid());
    $sock = new sockets();
    $EnableStreamCache = intval($sock->GET_INFO("EnableStreamCache"));
    if ($EnableStreamCache == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Reload........: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Disabled ( see EnableStreamCache )...\n";
        }
        return;
    }
    $masterbin = $unix->find_program("streamsquidcache");
    if (!is_file($masterbin)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Reload........: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} not installed\n";
        }
        return;
    }
    $pid = streamsquidcache_pid();
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        $php = $unix->LOCATE_PHP5_BIN();
        if ($GLOBALS["OUTPUT"]) {
            echo "Reload........: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Service running since {$time}Mn...\n";
        }
        shell_exec("{$masterbin} -f /etc/streamsquidcache/squid.conf -k reconfigure");
        reload_vc_scheduler();
        if ($GLOBALS["OUTPUT"]) {
            echo "Reload........: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Reloading Apache\n";
        }
        shell_exec("{$php} /usr/share/artica-postfix/exec.freeweb.php --reload");
        if ($GLOBALS["OUTPUT"]) {
            echo "Reload........: " . date("H:i:s") . " [INIT]: {$GLOBALS["SERVICE_NAME"]} Reloading Main Proxy\n";
        }
        shell_exec("/etc/init.d/squid reload --script=" . basename(__FILE__));
        return;
    }
    start(true);
}