示例#1
0
    die;
}
if ($argv[1] == "--changemysqldir") {
    changemysqldir($argv[2]);
    die;
}
if ($argv[1] == "--databasesize") {
    databasesize($GLOBALS["FORCE"]);
    die;
}
if ($argv[1] == "--restorefrom") {
    RestoreFromBackup($argv[2]);
    die;
}
if ($argv[1] == "--keys") {
    GetStartedValues();
    die;
}
function ToCopy($WORKDIR)
{
    $f[] = "host.frm";
    $f[] = "host.MYD";
    $f[] = "host.MYI";
    while (list($key, $filename) = each($results)) {
        if (!is_file("{$WORKDIR}/mysql/{$filename}")) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: copy /var/lib/mysql/mysql/{$filename} {$WORKDIR}/mysql/{$filename}\n";
            }
            @copy("/var/lib/mysql/mysql/{$filename} {$WORKDIR}/mysql/{$filename}");
        }
    }
示例#2
0
function SERVICE_START($nochecks = false, $nopid = false)
{
    $unix = new unix();
    $sock = new sockets();
    $kill = $unix->find_program("kill");
    if (!$nopid) {
        $pidfile = "/etc/artica-postfix/pids/" . basename(__FILE__) . "." . __FUNCTION__ . ".pid";
        $pid = @file_get_contents($pidfile);
        if ($unix->process_exists($pid, basename(__FILE__))) {
            $time = $unix->PROCCESS_TIME_MIN($pid);
            echo "Starting......: " . date("H:i:s") . " MySQL this script is already executed PID: {$pid} since {$time}Mn\n";
            if ($time < 5) {
                if (!$GLOBALS["FORCE"]) {
                    return;
                }
            }
            unix_system_kill_force($pid);
        }
        @file_put_contents($pidfile, getmypid());
    }
    if (is_file("/etc/artica-postfix/mysql.stop")) {
        echo "Starting......: " . date("H:i:s") . " MySQL locked, exiting\n";
        return;
    }
    $PID_NUM = PID_NUM();
    if ($unix->process_exists($PID_NUM)) {
        $timemin = $unix->PROCCESS_TIME_MIN($PID_NUM);
        echo "Starting......: " . date("H:i:s") . " MySQL already running PID \"{$PID_NUM}\" since {$timemin}Mn\n";
        return;
    }
    $mysql_install_db = $unix->find_program('mysql_install_db');
    $mysqlbin = $unix->LOCATE_mysqld_bin();
    $php5 = $unix->LOCATE_PHP5_BIN();
    $nohup = $unix->find_program("nohup");
    if (!is_file($mysqlbin)) {
        echo "Starting......: " . date("H:i:s") . " MySQL is not installed, abort\n";
        return;
    }
    $EnableMysqlFeatures = $sock->GET_INFO('EnableMysqlFeatures');
    $MysqlBinAllAdresses = $sock->GET_INFO('MysqlBinAllAdresses');
    $MySQLTMPMEMSIZE = $sock->GET_INFO('MySQLTMPMEMSIZE');
    $MysqlTooManyConnections = $sock->GET_INFO("MysqlTooManyConnections");
    $MysqlRemoveidbLogs = $sock->GET_INFO("MysqlRemoveidbLogs");
    $innodb_force_recovery = $sock->GET_INFO("innodb_force_recovery");
    if (!is_numeric($innodb_force_recovery)) {
        $innodb_force_recovery = 0;
    }
    if (!is_numeric($MysqlRemoveidbLogs)) {
        $MysqlRemoveidbLogs = 0;
    }
    if (!is_numeric($MysqlBinAllAdresses)) {
        $MysqlBinAllAdresses = 0;
    }
    if (!is_numeric($MySQLTMPMEMSIZE)) {
        $MySQLTMPMEMSIZE = 0;
    }
    if (!is_numeric($MysqlTooManyConnections)) {
        $MysqlTooManyConnections = 0;
    }
    if (!is_numeric($EnableMysqlFeatures)) {
        $EnableMysqlFeatures = 1;
    }
    $MySqlTmpDir = $sock->GET_INFO('MySQLTMPDIR');
    $MySQLLOgErrorPath = $sock->GET_INFO('MySQLLOgErrorPath');
    $datadir = $unix->MYSQL_DATA_DIR();
    $EnableMysqlLog = $sock->GET_INFO("EnableMysqlLog");
    if (!is_numeric($EnableMysqlLog)) {
        $EnableMysqlLog = 0;
    }
    if ($datadir == null) {
        $datadir = '/var/lib/mysql';
    }
    if ($MySqlTmpDir == '/tmp') {
        $MySqlTmpDir = null;
    }
    if ($MySQLLOgErrorPath == null) {
        $MySQLLOgErrorPath = $datadir . '/mysqld.err';
    }
    if ($MysqlTooManyConnections == 1) {
        echo "Starting......: " . date("H:i:s") . " MySQL MysqlTooManyConnections=1, abort\n";
        return;
    }
    if (isset($GLOBALS["RECOVERY"])) {
        $innodb_force_recovery = $GLOBALS["RECOVERY"];
    }
    if (strlen($MySqlTmpDir) > 3) {
        echo "Starting......: " . date("H:i:s") . " MySQL tempdir : {$MySqlTmpDir}\n";
        shell_exec("{$php5} /usr/share/artica-postfix/exec.mysql.build.php --tmpfs");
        $MySqlTmpDir = str_replace("//", "/", $MySqlTmpDir);
        if (!is_dir($MySqlTmpDir)) {
            @mkdir($MySqlTmpDir, 0755, true);
            $unix->chown_func("mysql", "mysql", $MySqlTmpDir);
        }
        $MySqlTmpDirCMD = " --tmpdir={$MySqlTmpDir}";
    }
    if ($EnableMysqlFeatures == 0) {
        echo "Starting......: " . date("H:i:s") . " MySQL is disabled by \"EnableMysqlFeatures\"...\n";
        return;
    }
    $pid_file = "/var/run/mysqld/mysqld.pid";
    $socket = "/var/run/mysqld/mysqld.sock";
    $mysql_user = "******";
    @mkdir("/var/run/mysqld", 0755, true);
    @mkdir("/var/log/mysql", 0755, true);
    @mkdir($datadir, 0755, true);
    $dirs = $unix->dirdir("/var/lib/mysql");
    while (list($num, $directory) = each($dirs)) {
        echo "Starting......: " . date("H:i:s") . " MySQL, apply permissions on " . basename($directory) . "\n";
        $unix->chown_func("mysql", "mysql", "{$directory}/*");
    }
    $bind_address = ' --bind-address=127.0.0.1';
    $bind_address2 = "127.0.0.1";
    if ($MysqlBinAllAdresses == 1) {
        $bind_address2 = 'All (0.0.0.0)';
        $bind_address = ' --bind-address=0.0.0.0';
    }
    echo "Starting......: " . date("H:i:s") . " MySQL Pid path.......:{$pid_file}\n";
    echo "Starting......: " . date("H:i:s") . " datadir..............:{$datadir}\n";
    echo "Starting......: " . date("H:i:s") . " Log error............:{$MySQLLOgErrorPath}\n";
    echo "Starting......: " . date("H:i:s") . " socket...............:{$socket}\n";
    echo "Starting......: " . date("H:i:s") . " user.................:{$mysql_user}\n";
    echo "Starting......: " . date("H:i:s") . " LOGS ENABLED.........:{$EnableMysqlLog}\n";
    echo "Starting......: " . date("H:i:s") . " Daemon...............:{$mysqlbin}\n";
    echo "Starting......: " . date("H:i:s") . " Bind address.........:{$bind_address2}\n";
    echo "Starting......: " . date("H:i:s") . " Temp Dir.............:{$MySqlTmpDir}\n";
    echo "Starting......: " . date("H:i:s") . " innodb_force_recovery:{$innodb_force_recovery}\n";
    mysql_admin_mysql(1, "Starting MySQL service...", null, __FILE__, __LINE__);
    echo "Starting......: " . date("H:i:s") . " Settings permissions..\n";
    @mkdir("/var/run/mysqld", 0755, true);
    $unix->chown_func($mysql_user, $mysql_user, "/var/run/mysqld");
    $unix->chown_func($mysql_user, $mysql_user, "/var/log/mysql");
    $unix->chown_func($mysql_user, $mysql_user, $datadir);
    $unix->chown_func($mysql_user, $mysql_user, "{$datadir}/*");
    if ($unix->is_socket("/var/run/mysqld/mysqld.sock")) {
        @unlink("/var/run/mysqld/mysqld.sock");
    }
    if (is_file('/var/run/mysqld/mysqld.err')) {
        @unlink('/var/run/mysqld/mysqld.err');
    }
    if (is_file("/var/run/mysqld/mysqld.pid")) {
        $unix->chown_func($mysql_user, $mysql_user, "/var/run/mysqld/mysqld.pid");
    }
    if ($MysqlRemoveidbLogs == 1) {
        shell_exec('/bin/mv /var/lib/mysql/ib_logfile* /tmp/');
        $sock->SET_INFO('MysqlRemoveidbLogs', '0');
    }
    $logpathstring = " --log-error={$MySQLLOgErrorPath}";
    if ($EnableMysqlLog == 1) {
        $logpathstring = " --log=/var/log/mysql.log --log-slow-queries=/var/log/mysql-slow-queries.log --log-error={$MySQLLOgErrorPath} --log-warnings";
    }
    $toTouch[] = "/var/log/mysql-slow-queries.log";
    $toTouch[] = "/var/log/mysql.error";
    $toTouch[] = "/var/log/mysql.log";
    $toTouch[] = "/var/log/mysql.warn";
    while (list($num, $filename) = each($toTouch)) {
        if (!is_file($filename)) {
            @file_put_contents($filename, "#\n");
        }
        $unix->chown_func($mysql_user, $mysql_user, $filename);
    }
    echo "Starting......: " . date("H:i:s") . " MySQL Checking : {$datadir}/mysql/host.frm\n";
    if (!is_file("{$datadir}/mysql/host.frm")) {
        if (is_file($mysql_install_db)) {
            echo "Starting......: " . date("H:i:s") . " MySQL Installing default databases\n";
            shell_exec("{$mysql_install_db} --datadir=\"{$datadir}\"");
        }
    } else {
        echo "Starting......: " . date("H:i:s") . " MySQL Checking : {$datadir}/mysql/host.frm OK\n";
    }
    $cmd2 = array();
    $MEMORY = $unix->MEM_TOTAL_INSTALLEE();
    $AsCategoriesAppliance = intval(@file_get_contents("/etc/artica-postfix/settings/Daemons/AsCategoriesAppliance"));
    if ($AsCategoriesAppliance == 1) {
        $MEMORY = 620288;
    }
    if ($MEMORY < 624288) {
        $GetStartedValues = GetStartedValues();
        echo "Starting......: " . date("H:i:s") . " MySQL Warning memory did not respond to pre-requesites, tuning to lower memory\n";
        if ($GetStartedValues["--key-buffer-size"]) {
            $cmd2[] = "--key-buffer-size=8M";
        }
        if ($GetStartedValues["--max-allowed-packet"]) {
            $cmd2[] = "--max-allowed-packet=4M";
        }
        if ($GetStartedValues["--table-cache"]) {
            $cmd2[] = "--table-cache=4";
        }
        if ($GetStartedValues["--sort-buffer-size"]) {
            $cmd2[] = "--sort-buffer-size=64k";
        }
        if ($GetStartedValues["--read-buffer-size"]) {
            $cmd2[] = "--read-buffer-size=256k";
        }
        if ($GetStartedValues["--read-rnd-buffer-size"]) {
            $cmd2[] = "--read-rnd-buffer-size=128k";
        }
        if ($GetStartedValues["--net-buffer-length"]) {
            $cmd2[] = "--net-buffer-length=2k";
        }
        if ($GetStartedValues["--thread-stack"]) {
            $cmd2[] = "--thread-stack=192k";
        }
        if ($GetStartedValues["--thread-cache-size"]) {
            $cmd2[] = "--thread-cache-size=128";
        }
        if ($GetStartedValues["--thread-concurrency"]) {
            $cmd2[] = "--thread-concurrency=10";
        }
        if ($GetStartedValues["--default-storage-engine"]) {
            $cmd2[] = "--default-storage-engine=MyISAM";
        }
        if ($GetStartedValues["--default-tmp-storage-engine"]) {
            $cmd2[] = "--default-tmp-storage-engine=MyISAM";
        }
        if ($GetStartedValues["--tmp-table-size"]) {
            $cmd2[] = "--tmp-table-size=16M";
        }
        if ($GetStartedValues["--table-cache"]) {
            $cmd2[] = "--table-cache=64";
        }
        if ($GetStartedValues["--query-cache-limit"]) {
            $cmd2[] = "--query-cache-limit=4M";
        }
        if ($GetStartedValues["--query-cache-size"]) {
            $cmd2[] = "--query-cache-size=32M";
        }
        if ($GetStartedValues["--max-connections"]) {
            $cmd2[] = "--max-connections=50";
        }
        if (is_file("/etc/artica-postfix/WORDPRESS_APPLIANCE")) {
            $cmd2[] = "--innodb=OFF";
        }
        echo "Starting......: " . date("H:i:s") . " MySQL " . count($cmd2) . " forced option(s)\n";
    }
    if (is_file($MySQLLOgErrorPath)) {
        @unlink($MySQLLOgErrorPath);
    }
    $cmds[] = $mysqlbin;
    if ($MEMORY < 624288) {
        $cmds[] = "--no-defaults --user=mysql";
    }
    $cmds[] = "--pid-file=/var/run/mysqld/mysqld.pid";
    $cmds[] = trim($logpathstring);
    $cmds[] = trim($MySqlTmpDirCMD);
    $cmds[] = "--socket={$socket}";
    $cmds[] = "--datadir=\"{$datadir}\"";
    if (count($cmd2) == 0) {
        if ($innodb_force_recovery > 0) {
            $cmds[] = "--innodb-force-recovery={$innodb_force_recovery}";
        }
    }
    if (count($cmd2) > 0) {
        $cmds[] = @implode(" ", $cmd2);
    }
    $cmds[] = ">/dev/null 2>&1 &";
    if (is_file('/usr/sbin/aa-complain')) {
        echo "Starting......: " . date("H:i:s") . " Mysql Adding mysql in apparamor complain mode...\n";
        shell_exec("/usr/sbin/aa-complain {$mysqlbin} >/dev/null 2>&1");
    }
    $cmd = @implode(" ", $cmds);
    while (list($num, $ligne) = each($cmds)) {
        echo "Starting......: " . date("H:i:s") . " MySQL Option: {$ligne}\n";
    }
    echo "Starting......: " . date("H:i:s") . " MySQL Starting daemon, please wait\n";
    writelogs("Starting MySQL {$cmd}", __FUNCTION__, __FILE__, __LINE__);
    shell_exec($cmd);
    $count = 0;
    sleep(2);
    for ($i = 0; $i < 6; $i++) {
        $pid = PID_NUM();
        if ($unix->process_exists($pid, $mysqlbin)) {
            echo "Starting......: " . date("H:i:s") . " MySQL Checks daemon running...\n";
            break;
        }
        echo "Starting......: " . date("H:i:s") . " MySQL Checks daemon, please wait ({$i}/6)\n";
        sleep(1);
    }
    $pid = PID_NUM();
    if (!$unix->process_exists($pid)) {
        echo "Starting......: " . date("H:i:s") . " MySQL failed\n";
        echo "Starting......: " . date("H:i:s") . " {$cmd}\n";
        system_admin_events("Failed to start MySQL server", __FUNCTION__, __FILE__, __LINE__, "services");
        $php5 = $unix->LOCATE_PHP5_BIN();
        shell_exec("{$nohup} {$php5} /usr/share/artica-postfix/exec.mysql.build.php >/dev/null 2>&1 &");
    } else {
        for ($i = 0; $i < 4; $i++) {
            echo "Starting......: " . date("H:i:s") . " MySQL Checks mysqld.sock waiting {$i}/3\n";
            if ($unix->is_socket("/var/run/mysqld/mysqld.sock")) {
                break;
            }
            sleep(1);
        }
        if (!$unix->is_socket("/var/run/mysqld/mysqld.sock")) {
            mysql_admin_mysql(0, "Failed to start MySQL Server /var/run/mysqld/mysqld.sock no such socket after 4 seconds", null, __FILE__, __LINE__);
            echo "Starting......: " . date("H:i:s") . " MySQL Checks mysqld.sock failed...\n";
        }
        mysql_admin_mysql(1, "Success to start MySQL Server with new pid {$pid}", null, __FILE__, __LINE__);
        echo "Starting......: " . date("H:i:s") . " MySQL Success pid {$pid}\n";
        $q = new mysql_squid_builder();
        $q->MEMORY_TABLES_RESTORE();
    }
}
示例#3
0
function start($skipGrant = false)
{
    if (is_file("/etc/artica-postfix/FROM_ISO")) {
        if (!is_file("/etc/artica-postfix/artica-iso-setup-launched")) {
            return;
        }
    }
    $unix = new unix();
    $pidfile = "/etc/artica-postfix/pids/squiddbstart.pid";
    $sock = new sockets();
    $WORKDIR = $sock->GET_INFO("SquidStatsDatabasePath");
    if ($WORKDIR == null) {
        $WORKDIR = "/opt/squidsql";
    }
    $SERV_NAME = "squid-db";
    $pid = $unix->get_pid_from_file($pidfile);
    $sock = new sockets();
    $nohup = $unix->find_program("nohup");
    $php5 = $unix->LOCATE_PHP5_BIN();
    $lnbin = $unix->find_program("ln");
    if (!$GLOBALS["FORCE"]) {
        if (!$GLOBALS["NOPID"]) {
            if ($unix->process_exists($pid, basename(__FILE__))) {
                $time = $unix->PROCCESS_TIME_MIN($pid);
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: Starting Task Already running PID {$pid} since {$time}mn\n";
                }
                return;
            }
        }
    }
    @file_put_contents($pidfile, getmypid());
    $GetStartedValues = GetStartedValues();
    $sock = new sockets();
    $ProxyUseArticaDB = $sock->GET_INFO("ProxyUseArticaDB");
    $DisableArticaProxyStatistics = $sock->GET_INFO("DisableArticaProxyStatistics");
    if (!is_numeric($ProxyUseArticaDB)) {
        $ProxyUseArticaDB = 0;
    }
    if (!is_numeric($DisableArticaProxyStatistics)) {
        $DisableArticaProxyStatistics = 0;
    }
    if (!is_dir($WORKDIR)) {
        @mkdir($WORKDIR, 0755, true);
    }
    if ($ProxyUseArticaDB == 0) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} is disabled...\n";
        }
        stop();
        return;
    }
    $mysqld = $unix->find_program("mysqld");
    if (!is_file($mysqld)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]:{$SERV_NAME} is not installed...\n";
        }
        return;
    }
    $pid = SQUIDDB_PID();
    if ($unix->process_exists($pid)) {
        $time = $unix->PROCCESS_TIME_MIN($pid);
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} MySQL Database Engine already running pid {$pid} since {$time}mn\n";
        }
        return;
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} writing init.d\n";
    }
    initd();
    $memory = get_memory();
    $swap = get_swap();
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} Server available memory `{$memory}MB`\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} Server available swap `{$swap}MB`\n";
    }
    $SquidDBTuningParameters = unserialize(base64_decode($sock->GET_INFO("SquidDBTuningParameters")));
    $ListenPort = $SquidDBTuningParameters["ListenPort"];
    if (!is_numeric($ListenPort)) {
        $ListenPort = 0;
    }
    if ($ListenPort == 0) {
        $ListenPort = rand(8900, 45890);
        $SquidDBTuningParameters["ListenPort"] = $ListenPort;
        $sock->SET_INFO("SquidDBTuningParameters", base64_encode(serialize($SquidDBTuningParameters)));
    }
    @mkdir($WORKDIR, 0755, true);
    $mysqlserv = new mysql_services();
    $mysqlserv->WORKDIR = $WORKDIR;
    $mysqlserv->MYSQL_PID_FILE = "/var/run/squid-db.pid";
    $mysqlserv->MYSQL_SOCKET = "/var/run/mysqld/squid-db.sock";
    $mysqlserv->SERV_NAME = $SERV_NAME;
    $mysqlserv->TokenParams = "SquidDBTuningParameters";
    $mysqlserv->INSTALL_DATABASE = true;
    $mysqlserv->MYSQL_BIN_DAEMON_PATH = $unix->find_program("mysqld");
    //$mysqlserv->MYSQL_ERRMSG=$GLOBALS["MYSQL_ERRMSG"];
    $mysqlserv->InnoDB = false;
    $cmdline = $mysqlserv->BuildParams();
    $CREATEDB = false;
    if (!is_file("{$WORKDIR}/my.cnf")) {
        @file_put_contents("{$WORKDIR}/my.cnf", "\n");
    }
    if (!is_file("{$WORKDIR}/bin/my_print_defaults")) {
        $my_print_defaults = $unix->find_program("my_print_defaults");
        shell_exec("{$lnbin} -s {$my_print_defaults} {$WORKDIR}/bin/my_print_defaults");
    }
    if (!is_file("{$WORKDIR}/data/mysql/user.MYD")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$SERV_NAME} Installing defaults databases, Please Wait...\n";
        }
        install_db($WORKDIR);
        $CREATEDB = true;
    }
    $topCopyMysql["host.frm"] = true;
    $topCopyMysql["host.MYD"] = true;
    $topCopyMysql["host.MYI"] = true;
    $topCopyMysql["servers.frm"] = true;
    $topCopyMysql["servers.MYD"] = true;
    $topCopyMysql["servers.MYI"] = true;
    $MYSQL_DATA_DIR = $unix->MYSQL_DATA_DIR();
    $topCopyMysqlForce["tables_priv.frm"] = true;
    $topCopyMysqlForce["tables_priv.MYD"] = true;
    $topCopyMysqlForce["tables_priv.MYI"] = true;
    $topCopyMysqlForce["columns_priv.frm"] = true;
    $topCopyMysqlForce["columns_priv.MYD"] = true;
    $topCopyMysqlForce["columns_priv.MYI"] = true;
    $topCopyMysqlForce["procs_priv.frm"] = true;
    $topCopyMysqlForce["procs_priv.MYD"] = true;
    $topCopyMysqlForce["procs_priv.MYI"] = true;
    $topCopyMysqlForce["plugin.frm"] = true;
    $topCopyMysqlForce["plugin.MYD"] = true;
    $topCopyMysqlForce["plugin.MYI"] = true;
    $topCopyMysqlForce["user.frm"] = true;
    $topCopyMysqlForce["user.MYD"] = true;
    $topCopyMysqlForce["user.MYI"] = true;
    $topCopyMysqlForce["db.frm"] = true;
    $topCopyMysqlForce["db.MYD"] = true;
    $topCopyMysqlForce["db.MYI"] = true;
    $ToCopyForce = false;
    while (list($filename, $ligne) = each($topCopyMysql)) {
        if (!is_file("{$WORKDIR}/data/mysql/{$filename}")) {
            $ToCopyForce = true;
            if (is_file("{$MYSQL_DATA_DIR}/mysql/{$filename}")) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: Installing {$filename}\n";
                }
                @copy("{$MYSQL_DATA_DIR}/mysql/{$filename}", "{$WORKDIR}/data/mysql/{$filename}");
                $CREATEDB = true;
            }
        }
    }
    while (list($filename, $ligne) = each($topCopyMysqlForce)) {
        if (!is_file("{$WORKDIR}/data/mysql/{$filename}")) {
            if (is_file("{$MYSQL_DATA_DIR}/mysql/{$filename}")) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: Installing {$filename}\n";
                }
                @copy("{$MYSQL_DATA_DIR}/mysql/{$filename}", "{$WORKDIR}/data/mysql/{$filename}");
            }
        }
    }
    @mkdir("{$WORKDIR}/share/mysql/english", 0755, true);
    $Get_errmsgsys = Get_errmsgsys();
    if (!is_file("{$WORKDIR}/share/mysql/english/errmsg.sys")) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: Creating errmsg.sys\n";
        }
        ini_set('error_reporting', E_ALL);
        ini_set('error_prepend_string', null);
        ini_set('error_append_string', null);
        if (is_file($Get_errmsgsys)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: copy {$Get_errmsgsys} -> {$WORKDIR}/share/mysql/english/errmsg.sys\n";
            }
            copy(Get_errmsgsys(), "{$WORKDIR}/share/mysql/english/errmsg.sys");
        } else {
            file_put_contents("{$WORKDIR}/share/mysql/english/errmsg.sys", "\n");
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: errmsg.sys OK\n";
        }
    }
    $TMP = $unix->FILE_TEMP();
    $nohup = $unix->find_program("nohup");
    if ($GLOBALS["VERBOSE"]) {
        echo $cmdline . "\n";
    }
    if ($GLOBALS["OUTPUT"]) {
        echo "Starting......: " . date("H:i:s") . " [INIT]: Starting MySQL daemon ({$SERV_NAME})\n";
    }
    @unlink("{$WORKDIR}/error.log");
    shell_exec("{$nohup} {$cmdline} >{$TMP} 2>&1 &");
    sleep(1);
    for ($i = 0; $i < 5; $i++) {
        $pid = SQUIDDB_PID();
        if ($unix->process_exists($pid)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: MySQL daemon ({$SERV_NAME}) started pid .{$pid}..\n";
            }
            break;
        }
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: MySQL daemon wait {$i}/5\n";
        }
        sleep(1);
    }
    sleep(1);
    $pid = SQUIDDB_PID();
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: MySQL daemon ({$SERV_NAME}) failed to start\n";
        }
        if (is_file($TMP)) {
            $f = explode("\n", @file_get_contents($TMP));
            while (list($num, $ligne) = each($f)) {
                if (trim($ligne) == null) {
                    continue;
                }
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: {$ligne}\n";
                }
            }
        }
        $f = explode("\n", @file_get_contents("{$WORKDIR}/error.log"));
        while (list($num, $ligne) = each($f)) {
            if ($GLOBALS["OUTPUT"]) {
                echo "Starting......: " . date("H:i:s") . " [INIT]: MySQL Results \"{$ligne}\"\n";
            }
            if (preg_match("#Incorrect information in file: './mysql/proxies_priv.frm'#", $ligne)) {
                if ($GLOBALS["OUTPUT"]) {
                    echo "Starting......: " . date("H:i:s") . " [INIT]: remove MySQL tables and install again...\n";
                }
                shell_exec("/bin/rm -rf {$WORKDIR}/data/mysql/*");
                shell_exec("{$nohup} {$php5} " . __FILE__ . " --start --recall >/dev/ null 2>&1 &");
                return;
            }
        }
    } else {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: MySQL daemon ({$SERV_NAME}) success\n";
        }
        if ($CREATEDB) {
            $q = new mysql_squid_builder();
            $q->CheckTables();
        }
        $q = new mysql_squid_builder();
        $q->MEMORY_TABLES_RESTORE();
    }
    if (!$unix->process_exists($pid)) {
        if ($GLOBALS["OUTPUT"]) {
            echo "Starting......: " . date("H:i:s") . " [INIT]: {$cmdline}\n";
        }
    }
    $unix->THREAD_COMMAND_SET($unix->LOCATE_PHP5_BIN() . " " . __FILE__ . " --databasesize");
}