示例#1
0
function CheckInstances(){
	$pidfile="/etc/artica-postfix/pids/".basename(__FILE__).".".__FUNCTION__.".pid";
	$unix=new unix();
	if($unix->process_exists(@file_get_contents($pidfile))){
		echo "Starting......: CheckInstances function already executed PID ". @file_get_contents($pidfile)."\n";
		die();
	}

		$pid=getmypid();
		echo "Starting......: CheckInstances configurator running $pid\n";
		file_put_contents($pidfile,$pid);		
	
		$maincf=new maincf_multi("");
		$maincf->PostfixMainCfDefaultInstance();
		$sql="SELECT `value` FROM postfix_multi WHERE `key`='myhostname' GROUP BY `value`";
		echo "Starting......: Postfix activate HUB(s)\n";

		$q=new mysql();
		$results=$q->QUERY_SQL($sql,"artica_backup");
		while($ligne=@mysql_fetch_array($results,MYSQL_ASSOC)){	
			$myhostname=trim($ligne["value"]);
			if($myhostname==null){continue;}
			if($myhostname=="master"){continue;}
			echo "Starting......: Postfix \"$myhostname\" checking HUB\n";
			ConfigureMainCF($myhostname);
			
		}
	@unlink($pidfile);
}
示例#2
0
function _start_instance($hostname)
{
    if ($hostname == "master") {
        return;
    }
    if (trim($hostname) == null) {
        return;
    }
    $unix = new unix();
    $main = new maincf_multi($hostname);
    $PostFixEnableQueueInMemory = $main->GET("PostFixEnableQueueInMemory");
    $PostFixQueueInMemory = $main->GET("PostFixQueueInMemory");
    $ifconfig = $unix->find_program("ifconfig");
    $ln = $unix->find_program("ln");
    $route = $unix->find_program("route");
    $directory = "/var/spool/postfix-{$hostname}";
    $postfixbin = $unix->find_program("postfix");
    if ($PostFixEnableQueueInMemory == 1) {
        reconfigure_instance_tmpfs($hostname, $PostFixQueueInMemory);
    } else {
        $MOUNTED_TMPFS_MEM = $unix->MOUNTED_TMPFS_MEM($directory);
        if ($MOUNTED_TMPFS_MEM > 0) {
            reconfigure_instance_tmpfs_umount($hostname);
        }
    }
    if (!is_file("/etc/postfix-{$hostname}/main.cf")) {
        echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" /etc/postfix-{$hostname}/main.cf no such file (reconfigure)\n";
        ConfigureMainCF($hostname, true);
    }
    $pidfile = "/var/spool/postfix-{$hostname}/pid/master.pid";
    if ($GLOBALS["postmulti"] == null) {
        $GLOBALS["postmulti"] = $unix->find_program("postmulti");
    }
    $pid = $unix->get_pid_from_file($pidfile);
    writelogs("{$hostname}:: Checking directories IP address={$main->ip_addr}", __FUNCTION__, __FILE__, __LINE__);
    $q = new mysql();
    $sql = "SELECT * FROM nics_virtuals WHERE ipaddr='{$main->ip_addr}'";
    $ligne = mysql_fetch_array($q->QUERY_SQL($sql, "artica_backup"));
    echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" {$main->ip_addr} on {$ligne["nic"]}:{$ligne["ID"]}\n";
    if ($ligne["ipv6"] == 0) {
        if ($ligne["ID"] > 0) {
            shell_exec("{$ifconfig} {$ligne["nic"]}:{$ligne["ID"]} {$main->ip_addr} >/dev/null 2>&1");
            shell_exec("{$route} add -host {$main->ip_addr} dev {$ligne["nic"]}:{$ligne["ID"]} >/dev/null 2>&1");
        }
    }
    $main->CheckDirectories($hostname);
    writelogs("{$hostname}:: {$pidfile}={$pid}", __FUNCTION__, __FILE__, __LINE__);
    if ($unix->process_exists($pid)) {
        echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" reloading\n";
        writelogs("{$hostname}::reloading postfix {$GLOBALS["postmulti"]} -i postfix-{$hostname} -p reload", __FUNCTION__, __FILE__, __LINE__);
        exec("{$GLOBALS["postmulti"]} -i postfix-{$hostname} -p reload 2>&1", $results);
        while (list($num, $line) = each($results)) {
            if (preg_match("#unused parameter#", $line)) {
                continue;
            }
            writelogs("{$line}", __FUNCTION__, __FILE__, __LINE__);
            echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" {$line}\n";
            if (preg_match("#fatal: open /etc/postfix-(.+?)\\/main\\.cf#", $line, $re)) {
                echo "Starting......: " . date("H:i:s") . " Postfix reconfigure \"{$re[1]}\"\n";
                reconfigure_instance($re[1]);
            }
        }
        return;
    }
    echo "Starting......: " . date("H:i:s") . " Postfix starting \"{$hostname}\"\n";
    writelogs("{$hostname}::Starting postfix {$GLOBALS["postmulti"]} -i postfix-{$hostname} -p start", __FUNCTION__, __FILE__, __LINE__);
    exec("{$GLOBALS["postmulti"]} -i postfix-{$hostname} -p start 2>&1", $results);
    writelogs("{$hostname}::Starting LOG=" . count($results) . " lines", __FUNCTION__, __FILE__, __LINE__);
    while (list($num, $line) = each($results)) {
        if (preg_match("#unused parameter:#", $line)) {
            continue;
        }
        writelogs("{$line}", __FUNCTION__, __FILE__, __LINE__);
        echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" {$line}\n";
        if (preg_match("#fatal: open /etc/postfix-(.+?)\\/main\\.cf#", $line, $re)) {
            echo "Starting......: " . date("H:i:s") . " Postfix reconfigure \"{$re[1]}\"\n";
            reconfigure_instance($re[1]);
        }
    }
    $pid = $unix->get_pid_from_file($pidfile);
    for ($i = 0; $i < 10; $i++) {
        if ($GLOBALS["VERBOSE"]) {
            echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" DEBUG open \"{$pidfile}\"\n";
        }
        if ($unix->process_exists($pid)) {
            break;
        }
        echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" waiting run ({$pid})\n";
        sleep(1);
        $pid = $unix->get_pid_from_file($pidfile);
    }
    $pid = $unix->get_pid_from_file($pidfile);
    if ($unix->process_exists($pid)) {
        echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" SUCCESS with PID={$pid}\n";
        writelogs("{$hostname}::DONE", __FUNCTION__, __FILE__, __LINE__);
        return;
    }
    echo "Starting......: " . date("H:i:s") . " Postfix \"{$hostname}\" FAILED\n";
    writelogs("{$hostname}::FAILED", __FUNCTION__, __FILE__, __LINE__);
}
function CheckInstances()
{
    $maincf = new maincf_multi("");
    $maincf->PostfixMainCfDefaultInstance();
    $sql = "SELECT `value` FROM postfix_multi WHERE `key`='myhostname' GROUP BY `value`";
    echo "Starting......: Postfix activate HUB(s)\n";
    $q = new mysql();
    $results = $q->QUERY_SQL($sql, "artica_backup");
    while ($ligne = @mysql_fetch_array($results, MYSQL_ASSOC)) {
        $myhostname = trim($ligne["value"]);
        if ($myhostname == null) {
            continue;
        }
        echo "Starting......: Postfix checking HUB {$myhostname}\n";
        ConfigureMainCF($myhostname);
    }
}