Ejemplo n.º 1
0
function ChangeRoot($instance_id)
{
    echo "Loading instance {$instance_id}\n";
    $mysqld = new mysqlserver_multi($instance_id);
    $username = $mysqld->mysql_admin;
    $password = $mysqld->mysql_password;
    if ($password == null) {
        echo "Password is null, aborting\n";
        return;
    }
    $unix = new unix();
    $mysqld_safe = $unix->find_program("mysqld_safe");
    $nohup = $unix->find_program("nohup");
    $killbin = $unix->find_program("kill");
    echo "mysqld_safe:{$mysqld_safe}\n";
    $ini = new Bs_IniHandler();
    $ini->loadFile("/etc/mysql-multi.cnf");
    $array = $ini->_params["mysqld{$instance_id}"];
    $datadir = $ini->get("mysqld{$instance_id}", "datadir");
    while (list($key, $value) = each($array)) {
        $tt[] = "{$key} = {$value}";
    }
    $newconfig = "[mysqld]\n" . @implode("\n", $tt) . "\n";
    @file_put_contents("/etc/mysql-temp-{$instance_id}.cf", $newconfig);
    for ($i = 0; $i < 5; $i++) {
        $pid = multi_get_pid($instance_id);
        if ($pid > 0) {
            echo "Stopping mysqld safe pid:{$pid}\n";
            unix_system_kill_force($pid);
            sleep(1);
        } else {
            break;
        }
    }
    echo "Stopping instance {$instance_id}\n";
    //shell_exec($unix->LOCATE_PHP5_BIN()." /usr/share/artica-postfix/exec.mysql.build.php --multi-stop $instance_id >/dev/null 2>&1");
    for ($i = 0; $i < 5; $i++) {
        $pid = multi_get_pidNormal($instance_id);
        if ($pid > 0) {
            echo "Stopping mysqld pid:{$pid}\n";
            unix_system_kill_force($pid);
            sleep(1);
        } else {
            break;
        }
    }
    $pid = @file_get_contents("/var/run/mysqld/mysqld{$instance_id}.pid");
    if ($unix->process_exists($pid)) {
        echo "Stopping instance {$instance_id} failed...\n";
        return;
    }
    echo "Running instance {$instance_id} in safe mode...\n";
    if (file_exists("{$datadir}/error.log")) {
        @unlink("{$datadir}/error.log");
    }
    $cmd = "{$nohup} {$mysqld_safe} --defaults-file=/etc/mysql-temp-{$instance_id}.cf --datadir=\"{$datadir}\" --skip-grant-tables --skip-networking --skip-external-locking --log-error=\"{$datadir}/error.log\" --pid-file=/var/run/mysqld/mysqld{$instance_id}.pid >/dev/null 2>&1 &";
    if ($GLOBALS["VERBOSE"]) {
        echo "{$cmd}\n";
    }
    shell_exec($cmd);
    for ($i = 0; $i < 4; $i++) {
        sleep(1);
        $pid = @file_get_contents("/var/run/mysqld/mysqld{$instance_id}.pid");
        if ($unix->process_exists($pid)) {
            sleep(1);
            break;
        }
    }
    $pid = @file_get_contents("/var/run/mysqld/mysqld{$instance_id}.pid");
    if (!$unix->process_exists($pid)) {
        echo "Failed to run mysqld safe\n";
        if (file_exists("{$datadir}/error.log")) {
            echo @file_get_contents("{$datadir}/error.log");
        }
        shell_exec($nohup . " " . $unix->LOCATE_PHP5_BIN() . " /usr/share/artica-postfix/exec.mysql.build.php --multi-start {$instance_id} >/dev/null 2>&1 &");
        return;
    }
    $q = new mysql_multi($instance_id);
    $ligne = mysql_fetch_array($q->QUERY_SQL("SELECT User from user WHERE User='******' LIMIT 0,1", "mysql"));
    if (!$q->ok) {
        echo $q->mysql_error . "\n";
    }
    echo "User:{$username} = {$ligne["User"]}\n";
    if ($ligne["User"] != null) {
        echo "User: Already exists, update password\n";
        $sqlstring = "UPDATE user SET password=PASSWORD(\"{$password}\") WHERE user=\"{$username}\"";
        $q->QUERY_SQL($sqlstring, "mysql");
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
        }
        $q->QUERY_SQL_NO_BASE("FLUSH PRIVILEGES");
        if (!$q->ok) {
            echo $q->mysql_error . "\n";
        }
    } else {
        echo "Root: did not exists, Create a new one...\n";
        $q->QUERY_SQL_NO_BASE("create user root@localhost");
        $q->QUERY_SQL_NO_BASE("GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' with grant option");
        $q->QUERY_SQL_NO_BASE("FLUSH PRIVILEGES");
    }
    echo "Stopping mysqld safe....\n";
    for ($i = 0; $i < 5; $i++) {
        $pid = multi_get_pid($instance_id);
        if ($pid > 0) {
            echo "Stopping mysqld safe pid:{$pid}\n";
            unix_system_kill_force($pid);
            sleep(1);
        } else {
            break;
        }
    }
    exec($unix->LOCATE_PHP5_BIN() . " /usr/share/artica-postfix/exec.mysql.build.php --multi-stop {$instance_id} 2>&1", $results);
    while (list($key, $value) = each($results)) {
        echo "{$value}\n";
    }
    $results = array();
    echo "Start mysqld in normal mode\n";
    exec($unix->LOCATE_PHP5_BIN() . " /usr/share/artica-postfix/exec.mysql.build.php --multi-start {$instance_id} 2>&1", $results);
    while (list($key, $value) = each($results)) {
        echo "{$value}\n";
    }
}
Ejemplo n.º 2
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";
    }
}
Ejemplo n.º 3
0
function multi_delete($ID)
{
    $unix = new unix();
    $rm = $unix->find_program("rm");
    echo "Deleting......: zarafa-server instance id:{$ID}..\n";
    echo "Deleting......: zarafa-server disable instance\n";
    $q = new mysql();
    $q->QUERY_SQL("UPDATE zarafamulti SET enabled=0 WHERE ID='{$ID}'", "artica_backup");
    echo "Deleting......: zarafa-server stopping instance\n";
    multi_stop($ID);
    $zarafa = new zarafamulti($ID);
    echo "Deleting......: zarafa-server removing directory {$zarafa->attachment_path}\n";
    if (is_dir($zarafa->attachment_path)) {
        recursive_remove_directory($zarafa->attachment_path);
    }
    echo "Deleting......: zarafa-server removing directory /etc/zarafa-{$ID}\n";
    if (is_dir("/etc/zarafa-{$ID}")) {
        recursive_remove_directory("/etc/zarafa-{$ID}");
    }
    $database = "zarafa{$ID}";
    echo "Deleting......: zarafa-server removing database {$database}\n";
    if ($zarafa->mysql_instance_id > 0) {
        $q = new mysql_multi($zarafa->mysql_instance_id);
        $q->QUERY_SQL_NO_BASE("DROP DATABASE `{$database}`");
    } else {
        $q = new mysql();
        $q->DELETE_DATABASE($database);
    }
    echo "Deleting......: zarafa-server removing entry\n";
    $q = new mysql();
    $q->QUERY_SQL("DELETE FROM zarafamulti WHERE ID={$ID}", "artica_backup");
    if ($zarafa->PostfixInstance != null) {
        echo "Deleting......: zarafa-server reconfigure {$zarafa->PostfixInstance} postfix instance \n";
        $sock = new sockets();
        $sock->getFrameWork("postfix.php?reconfigure-single-instance={$zarafa->PostfixInstance}");
    }
    echo "Deleting......: zarafa-server done...\n";
}