if (class_exists("mysql")) {
    $mysql = new mysql();
    if (!$mysql->TestingConnection()) {
        WriteToSyslogMail("Fatal: connecting to MySQL server {$mysql->mysql_error}", basename(__FILE__), true);
        echo "Starting......: " . date("H:i:s") . " failed connecting to ldap server {$mysql->mysql_error}\n";
        $unix->send_email_events("Postfix user databases aborted (MySQL failed)", "The process has been scheduled to start in few seconds.", "postfix");
        $unix->THREAD_COMMAND_SET(trim($unix->LOCATE_PHP5_BIN() . " " . __FILE__ . " {$argv[1]}"));
        die;
    }
}
if ($argv[1] == '--reconfigure-all') {
    reconfigure();
    die;
}
if ($argv[1] == '--restart-all') {
    restart_all_instances();
    die;
}
if ($argv[1] == '--aliases') {
    build_all_aliases();
    die;
}
if ($argv[1] == '--instance-memory') {
    reconfigure_instance_tmpfs($argv[2], $argv[3]);
    die;
}
if ($argv[1] == '--instance-memory-kill') {
    reconfigure_instance_tmpfs_umount($argv[2]);
    die;
}
if ($argv[1] == '--destroy') {
include_once(dirname(__FILE__) . '/ressources/class.maincf.multi.inc');


$_GET["LOGFILE"]="/usr/share/artica-postfix/ressources/logs/web/interface-postfix.log";
if(!is_file("/usr/share/artica-postfix/ressources/settings.inc")){shell_exec("/usr/share/artica-postfix/bin/process1 --force --verbose");}
if(preg_match("#--verbose#",implode(" ",$argv))){$GLOBALS["DEBUG"]=true;$GLOBALS["VERBOSE"]=true;}
if(preg_match("#--reload#",implode(" ",$argv))){$GLOBALS["RELOAD"]=true;}

$unix=new unix();
$GLOBALS["postmulti"]=$unix->find_program("postmulti");
$GLOBALS["postconf"]=$unix->find_program("postconf");
$GLOBALS["postmap"]=$unix->find_program("postmap");
$GLOBALS["postalias"]=$unix->find_program("postalias");
$GLOBALS["postfix"]=$unix->find_program("postfix");

if($argv[1]=='--restart-all'){restart_all_instances();die();}
if($argv[1]=='--aliases'){build_all_aliases();die();}
if($argv[1]=='--instance-memory'){reconfigure_instance_tmpfs($argv[2],$argv[3]);die();}
if($argv[1]=='--instance-memory-kill'){reconfigure_instance_tmpfs_umount($argv[2]);die();}
if($argv[1]=='--destroy'){DestroyInstance($argv[2]);die();}




$sock=new sockets();
$GLOBALS["EnablePostfixMultiInstance"]=$sock->GET_INFO("EnablePostfixMultiInstance");
if($GLOBALS["EnablePostfixMultiInstance"]<>1){
		echo "Starting......: Multi-instances is not enabled ({$GLOBALS["EnablePostfixMultiInstance"]})\n";
		PostfixMultiDisable();
		die();
}