Beispiel #1
0
def startup(config):
    rc = iuprocess.run_background_program(
             [os.path.join(config.bin_dir, "mysqld"),
              "--user=%s" % config.os_user,
              "--basedir=%s" % config.home_path,
              "--port=%d" % config.port,
              "--pid-file=%s" % config.pid_file,
              "--socket=%s" % config.socket_file,
              "--log-error=%s" % config.error_log_file,
              "--datadir=%s" % config.data_dir],
             env_mapping=None,
             logfile=os.path.join(config.log_path, "mysqld.out"),
             logger=logger,
             cwd=config.home_path)
    if rc != 0:
        raise MysqlError(ERR_STARTUP, "Startup", config, {"rc": rc})
Beispiel #2
0
    def install(self, package):
        extracted_dir = package.extract(self.config.home_dir_parent)
        if extracted_dir != self.config.home_dir:
            # make the final name of the mysql dir equivalent to the
            # one specified in the resource instance
            shutil.move(os.path.join(self.config.home_dir_parent,
                                     extracted_dir),
                        self.config.home_path)
        # modify configuration files
        self._setup_mysql_config_files()

        # run setup scripts
        os_user_arg = "--user=%s" % self.config.os_user
        base_dir_arg = "--basedir=%s" % self.config.home_path
        data_dir_arg = "--datadir=%s" % self.config.data_dir
        self._run_setup_script(os.path.join(self.config.script_dir,
                                            "mysql_install_db"),
                               [os_user_arg, base_dir_arg, data_dir_arg])
        # start the server in safe mode
        rc = iuprocess.run_background_program(
                 [os.path.join(self.config.bin_dir, "mysqld_safe"),
                  os_user_arg,
                  "--port=%d" % self.config.port,
                  "--pid-file=%s" % self.config.pid_file,
                  "--basedir=%s" % self.config.home_path,
                  "--datadir=%s" % self.config.data_dir,
                  "--skip-syslog",
                  "--log-error=%s" % self.config.error_log_file,
                  "--mysqld=mysqld",
                  "--socket=%s" % self.config.socket_file],
                 env_mapping=None,
                 logfile=os.path.join(self.config.log_path, "mysqld_safe.out"),
                 logger=logger,
                 cwd=self.config.home_path)
        if rc != 0:
            raise MysqlError(ERR_MYSQLD_START, "Install", self.config,
                             {"rc":rc})
        # wait until server responds
        if iutimeout.retry(check_status, TIMEOUT_TRIES, TIME_BETWEEN_TRIES,
                           self.config, root_pw="")==False:
            raise MysqlError(ERR_MYSQL_NO_RESPONSE, "Install", self.config)
        _mysql_secure_installation(self.config)
        if shutdown(self.config)==False:
            raise MysqlError(ERR_POST_CONFIG_SHUTDOWN, "Install", self.config)
        
        # check that everything is now in place
        self.validate_post_install()
Beispiel #3
0
    def install(self, package):
        # We extract the source tree into a directory called mysql_src, build, and
        # then install into mysql.
        source_dir_name = self.config.home_dir + "_src"
        source_dir_path = os.path.join(self.config.home_dir_parent, source_dir_name)
        extracted_dir = package.extract(self.config.home_dir_parent, source_dir_name)
	assert extracted_dir == source_dir_name
        # configure with prefix self.confg.home_path, make and make install
        rc = iuprocess.system('cd %s; ./configure --prefix=%s --with-mysqld-user=%s; make; make install' % 
                              (source_dir_path, self.config.home_path, self.config.os_user), logger,
                              log_output_as_info=True)
        if rc != 0:
            raise MysqlError(ERR_MYSQL_BUILD, "Install",
                             self.config, developer_msg="Return code was %d" % rc)
        # build was successful, delete the source tree
        logger.action("rm -rf %s" % source_dir_path)
        shutil.rmtree(source_dir_path)
        iupath.mkdir_p(os.path.join(self.config.home_path, 'data'))
        iupath.mkdir_p(os.path.join(self.config.home_path, 'var'))
        # modify configuration files
        self._setup_mysql_config_files()
        logger.info('extracted files. will run setup script.')
        # run setup scripts
        os_user_arg = "--user=%s" % self.config.os_user
        base_dir_arg = "--basedir=%s" % self.config.home_path
        data_dir_arg = "--datadir=%s" % self.config.data_dir
        self._run_setup_script(os.path.join(self.config.script_dir,
                                            "mysql_install_db"),
                               [os_user_arg, base_dir_arg, data_dir_arg])
        # start the server in safe mode
        logger.info('will run mysqld_safe in safe mode.')
        rc = iuprocess.run_background_program(
                 [os.path.join(self.config.bin_dir, "mysqld_safe"),
                  os_user_arg,
                  "--port=%d" % self.config.port,
                  "--pid-file=%s" % self.config.pid_file,
                  "--basedir=%s" % self.config.home_path,
                  "--datadir=%s" % self.config.data_dir,
                  "--skip-syslog",
                  "--log-error=%s" % self.config.error_log_file,
                  "--mysqld=mysqld",
                  "--socket=%s" % self.config.socket_file,
                  "--skip-grant-tables"],	# this is required to access the server without getting an access denied
                 env_mapping=None,
                 logfile=os.path.join(self.config.log_path, "mysqld_safe.out"),
                 logger=logger,
                 cwd=self.config.home_path)
        if rc != 0:
            raise MysqlError(ERR_MYSQLD_START, "Install", self.config,
                             {"rc":rc})
        # wait until server responds
        logger.info('waiting till server responds. ')
        if iutimeout.retry(check_status, TIMEOUT_TRIES, TIME_BETWEEN_TRIES,
                           self.config, root_pw=self.config.admin_password)==False:
            raise MysqlError(ERR_MYSQL_NO_RESPONSE, "Install", self.config)
        #rc = iuprocess.run_and_log_program([os.path.join(self.config.script_dir, 'mysqladmin'), '-u root', 'password', self.config.admin_password],
        #                               {}, logger, cwd=self.config.home_path, input=None)
        #if rc != 0:
        #   assert False, "cannot set root password"
        _mysql_secure_installation(self.config)
        if shutdown(self.config)==False:
            raise MysqlError(ERR_POST_CONFIG_SHUTDOWN, "Install", self.config)
        
        # write out the init.d startup script
        # we just stick it in the install directory for now and leave it to 
        # the user to manually copy it to /etc/init.d and enable it.
        startup_script = _mysql_initd_file % {
                "libexec_dir":self.config.libexec_dir,
                "os_user":self.config.os_user,
                "basedir":self.config.home_path,
                "port":self.config.port,
                "pid_file":self.config.pid_file,
                "socket_file":self.config.socket_file,
                "error_log_file":self.config.error_log_file,
                "datadir":self.config.data_dir
            }
        start_script_filepath = os.path.join(self.config.home_path, "mysql.sh")
        start_script_file = open(start_script_filepath, "wb")
        start_script_file.write(startup_script)
        start_script_file.close()
        os.chmod(start_script_filepath, 0755)
                                              
        # check that everything is now in place
        self.validate_post_install()