Beispiel #1
0
function multi_start($ID)
{
    $q = new mysqlserver();
    $GLOBALS["MULTI"] = true;
    $GLOBALS["SHOWLOGONLYFOR"] = $ID;
    multi_monit($ID);
    multi_create_cache();
    $q->mysql_multi();
    echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID}..\n";
    $pidfile = "/var/run/mysqld/mysqld{$ID}.pid";
    echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID} PID:{$pidfile}..\n";
    $unix = new unix();
    if ($unix->process_exists($unix->get_pid_from_file($pidfile))) {
        echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID} already running...\n";
        return;
    }
    $chmod = $unix->find_program("chmod");
    $ini = new iniFrameWork("/etc/mysql-multi.cnf");
    $database_path = $ini->get("mysqld{$ID}", "datadir");
    if (is_file("{$database_path}/error.log")) {
        @unlink("{$database_path}/error.log");
    }
    echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID} database={$database_path}\n";
    $cmd = "{$chmod} 755 {$database_path}";
    exec($cmd, $results);
    $mysqld_multi = $unix->find_program("mysqld_multi");
    $cmd = "{$mysqld_multi} --defaults-file=/etc/mysql-multi.cnf start {$ID} --verbose --no-log 2>&1";
    if (is_file("{$database_path}/maria_log_control")) {
        @unlink("{$database_path}/maria_log_control");
    }
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    exec($cmd, $results);
    while (list($index, $ligne) = each($results)) {
        echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID} {$ligne}\n";
    }
    for ($i = 0; $i < 4; $i++) {
        sleep(1);
        if ($unix->process_exists(multi_get_pid($ID))) {
            sleep(1);
            break;
        }
    }
    if (!$unix->process_exists(multi_get_pid($ID))) {
        echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID} failed..\n";
    } else {
        $q = new mysql_multi($ID);
        $q->QUERY_SQL_NO_BASE("create user 'mysqld_multi'@'127.0.0.1' identified by 'mysqld_multi'");
        $q->QUERY_SQL_NO_BASE("create user 'mysqld_multi'@'localhost' identified by 'mysqld_multi'");
        $q->QUERY_SQL_NO_BASE("create user 'grant shutdown on *.* to mysqld_multi'");
        $q = new mysqlserver_multi($ID);
        $q->setssl();
    }
    if (is_file("{$database_path}/error.log")) {
        echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID} {$database_path}/error.log\n";
        $f = explode("\n", @file_get_contents("{$database_path}/error.log"));
        while (list($index, $ligne) = each($f)) {
            if (trim($ligne) == null) {
                continue;
            }
            if (preg_match("#^[0-9]+\\s+[0-9\\:]+\\s+(.+)#", $ligne, $re)) {
                $ligne = $re[1];
            }
            echo "Starting......: " . date("H:i:s") . " {$ligne}\n";
        }
    } else {
        echo "Starting......: " . date("H:i:s") . " Mysql instance id:{$ID} {$database_path}/error.log no such file\n";
    }
}