function FailOverUp()
{
    if ($GLOBALS["EnableFailover"] == 0) {
        return;
    }
    if (!is_file($GLOBALS["STAMP_FAILOVER"])) {
        return;
    }
    $sock = new sockets();
    $unix = new unix();
    $FailOverArtica = $sock->GET_INFO("FailOverArtica");
    if (!is_numeric($FailOverArtica)) {
        $FailOverArtica = 1;
    }
    if ($FailOverArtica == 0) {
        return;
    }
    if (isset($GLOBALS[__FUNCTION__])) {
        return;
    }
    $GLOBALS[__FUNCTION__] = true;
    $users = new settings_inc();
    if (!$users->CORP_LICENSE) {
        Events("Unable to switch to failover master, license error");
        return;
    }
    $sock = new sockets();
    $MonitConfig = unserialize(base64_decode($sock->GET_INFO("SquidWatchdogMonitConfig")));
    $MonitConfig = watchdog_config_default($MonitConfig);
    $TimeEx = $unix->file_time_min($GLOBALS["STAMP_FAILOVER"]);
    if ($TimeEx < $MonitConfig["MinTimeFailOverSwitch"]) {
        Events("Need to wait {$MonitConfig["MinTimeFailOverSwitch"]}mn before switch to master (current is {$TimeEx}Mn");
        return;
    }
    if (function_exists("debug_backtrace")) {
        $trace = debug_backtrace();
        if (isset($trace[1])) {
            $sourcefile = basename($trace[1]["file"]);
            $sourcefunction = $trace[1]["function"];
            $sourceline = $trace[1]["line"];
        }
    }
    system_failover_events("Return to master:<br>Up failover network interface in order to turn back to master", $sourcefunction, basename(__FILE__), $sourceline);
    Events("Up failover network interface in order to turn back to master...");
    if (!is_file("/etc/init.d/artica-failover")) {
        $unix = new unix();
        $php = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$php} " . dirname(__FILE__) . "/exec.initslapd.php --failover");
    }
    @unlink($GLOBALS["STAMP_FAILOVER"]);
    shell_exec("/etc/init.d/artica-failover start");
}
function ucarp_start()
{
    $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
    $unix = new unix();
    $sock = new sockets();
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid, basename(__FILE__))) {
        echo "Starting......: " . date("H:i:s") . " UCARP Start task already running PID: {$pid}\n";
        return;
    }
    @file_put_contents($pidfile, getmypid());
    $users = new settings_inc();
    if (!$users->CORP_LICENSE) {
        echo "Starting......: " . date("H:i:s") . " UCARP No license set, aborting...\n";
        return;
    }
    $ucarp_bin = $unix->find_program("ucarp");
    if (!is_file($ucarp_bin)) {
        echo "Starting......: " . date("H:i:s") . " UCARP Not installed...\n";
        return;
    }
    if (is_file("/etc/network/if-up.d/ucarp")) {
        if (!is_file("/usr/share/ucarp/ETH_LIST")) {
            if (!$GLOBALS["AFTER_REBUILD"]) {
                ucarp_build(true);
            }
            return;
        }
    }
    if (!is_file("/usr/share/ucarp/ETH_LIST")) {
        echo "Starting......: " . date("H:i:s") . " UCARP Not configured, Apply network parameters first (1)...\n";
        return;
    }
    $ETHS = unserialize(@file_get_contents("/usr/share/ucarp/ETH_LIST"));
    if (!is_array($ETHS)) {
        echo "Starting......: " . date("H:i:s") . " UCARP Not configured (2 not an array), Apply network parameters first...\n";
        return;
    }
    if (count($ETHS) == 0) {
        echo "Starting......: " . date("H:i:s") . " UCARP Not configured (3)...\n";
        return;
    }
    while (list($eth, $ucarpcmdLINE) = each($ETHS)) {
        $pid = ucarp_pid($eth);
        if ($unix->process_exists($pid)) {
            echo "Starting......: " . date("H:i:s") . " UCARP `{$eth}` already running pid {$pid}\n";
            if (ucarp_eth_ucarped($eth)) {
                echo "Starting......: " . date("H:i:s") . " UCARP `{$eth}` alreaded linked\n";
                continue;
            }
            shell_exec("/usr/share/ucarp/vip-{$eth}-up.sh");
            continue;
        }
        shell_exec($ucarpcmdLINE);
        sleep(1);
        $pid = ucarp_pid($eth);
        echo "Starting......: " . date("H:i:s") . " UCARP `{$eth}` PID:{$pid}\n";
        if (!$unix->process_exists($pid)) {
            system_failover_events("Fatal:<br>Unable to start daemon for {$eth}", __FUNCTION__, basename(__FILE__), __LINE__);
            echo "Starting......: " . date("H:i:s") . " UCARP `{$eth}` failed `{$ucarpcmdLINE}`\n";
            continue;
        }
        if (!ucarp_eth_ucarped($eth)) {
            system_failover_events("Daemon:<br>`{$eth}` linking to network", __FUNCTION__, basename(__FILE__), __LINE__);
            echo "Starting......: " . date("H:i:s") . " UCARP `{$eth}` linking to network...\n";
            shell_exec("/usr/share/ucarp/vip-{$eth}-up.sh");
            echo "Starting......: " . date("H:i:s") . " UCARP `{$eth}` linking to network success...\n";
        }
    }
}