예제 #1
0
    def _fix_percona_debian_cnf(self):
        if __mysql__['behavior'] == 'percona' and \
                                                os.path.exists(__mysql__['debian.cnf']):
            LOG.info('Fixing socket options in %s', __mysql__['debian.cnf'])
            debian_cnf = metaconf.Configuration('mysql')
            debian_cnf.read(__mysql__['debian.cnf'])

            sock = mysql2_svc.my_print_defaults('mysqld')['socket']
            debian_cnf.set('client/socket', sock)
            debian_cnf.set('mysql_upgrade/socket', sock)
            debian_cnf.write(__mysql__['debian.cnf'])
예제 #2
0
 def __init__(self, path, autosave=True):
     super(MySQLConf, self).__init__(path, autosave=True)
     self.data = metaconf.Configuration(self.config_type)
     if os.path.exists(self.path):
         self.data.read(self.path)
     try:
         self.data.options('mysqld')
     except metaconf.NoPathError:
         self.data.add('mysqld')
     finally:
         # WHY?
         self.data = None
예제 #3
0
    def _destroy(self):
        """
        Reads chunks paths from manifest, then deletes manifest and chunks
        from cloud storage.
        """
        self._check_attr('path')
        scheme = urlparse.urlparse(self.path).scheme
        storage_drv = cloudfs.cloudfs(scheme)

        base_url = os.path.dirname(self.path)
        manifest_path = tempfile.mktemp()
        try:
            with open(manifest_path, 'w') as f:
                storage_drv.get(self.path, f)

            c = metaconf.Configuration('ini')
            c.read(manifest_path)
            for chunk in c.children('./chunks/'):
                chunk_path = os.path.join(base_url, chunk)
                storage_drv.delete(chunk_path)
            storage_drv.delete(self.path)
            self.path = None
        finally:
            os.remove(manifest_path)
예제 #4
0
 def reload(self):
     '''Reload metaconf.Configuration object inside HAProxyCfg'''
     LOG.debug('services.haproxy.HAProxyCfg.reload path=`%s`',
               self.cnf_path)
     self.conf = metaconf.Configuration('haproxy')
     self.conf.read(self.cnf_path)
예제 #5
0
 def __init__(self, path=None):
     self.conf = metaconf.Configuration('haproxy')
     self.cnf_path = path or HAPROXY_CFG_PATH
     self.conf.read(self.cnf_path)
예제 #6
0
    def _init_master(self, message):
        """
        Initialize MySQL master
        @type message: scalarizr.messaging.Message
        @param message: HostUp message
        """
        LOG.info("Initializing MySQL master")
        log = bus.init_op.logger

        log.info('Create storage')
        if 'restore' in __mysql__ and \
                        __mysql__['restore'].type == 'snap_mysql':
            __mysql__['restore'].run()
        else:
            if __node__['platform'].name == 'idcf':
                if __mysql__['volume'].id:
                    LOG.info('Cloning volume to workaround reattachment limitations of IDCF')
                    __mysql__['volume'].snap = __mysql__['volume'].snapshot()

            __mysql__['volume'].ensure(mount=True, mkfs=True)
            LOG.debug('MySQL volume config after ensure: %s', dict(__mysql__['volume']))

        coreutils.clean_dir(__mysql__['defaults']['datadir'])
        self.mysql.flush_logs(__mysql__['data_dir'])
        self.mysql.move_mysqldir_to(__mysql__['storage_dir'])
        self._change_selinux_ctx()

        storage_valid = self._storage_valid()
        user_creds = self.get_user_creds()
        self._fix_percona_debian_cnf()
        #datadir = mysql2_svc.my_print_defaults('mysqld').get('datadir', __mysql__['defaults']['datadir'])
        #if not storage_valid and datadir.find(__mysql__['data_dir']) == 0:
        #    # When role was created from another mysql role it contains modified my.cnf settings
        #    #self.mysql.my_cnf.datadir = '/var/lib/mysql'
        #    self.mysql.my_cnf.delete_options(['mysqld/log_bin'])



        if not storage_valid:
            '''
            if linux.os['family'] == 'RedHat':
                try:
                    # Check if selinux enabled
                    selinuxenabled_bin = software.which('selinuxenabled')
                    if selinuxenabled_bin:
                        se_enabled = not system2((selinuxenabled_bin, ), raise_exc=False)[2]
                        if se_enabled:
                            # Set selinux context for new mysql datadir
                            semanage = mysql_svc.get_semanage()
                            linux.system('%s fcontext -a -t mysqld_db_t "%s(/.*)?"'
                                         % (semanage, __mysql__['storage_dir']), shell=True)
                            # Restore selinux context
                            restorecon = software.which('restorecon')
                            linux.system('%s -R -v %s' % (restorecon, __mysql__['storage_dir']), shell=True)
                except:
                    LOG.debug('Selinux context setup failed', exc_info=sys.exc_info())
                '''

            self.mysql.my_cnf.delete_options(['mysqld/log_bin'])
            linux.system(['mysql_install_db', '--user=mysql', '--datadir=%s' % __mysql__['data_dir']])

        # Patch configuration
        options = {
            'bind-address': '0.0.0.0',
            'datadir': __mysql__['data_dir'],
            'log_bin': os.path.join(__mysql__['binlog_dir'], 'binlog'),
            'log-bin-index': os.path.join(__mysql__['binlog_dir'], 'binlog.index'),  # MariaDB
            'sync_binlog': '1',
            'innodb_flush_log_at_trx_commit': '1',
            'expire_logs_days': '10'
        }
        for key, value in options.items():
            self.mysql.my_cnf.set('mysqld/' + key, value)

        if not storage_valid:
            if linux.os.debian_family and os.path.exists(__mysql__['debian.cnf']):
                self.mysql.service.start()
                debian_cnf = metaconf.Configuration('mysql')
                debian_cnf.read(__mysql__['debian.cnf'])
                sql = ("GRANT ALL PRIVILEGES ON *.* "
                        "TO 'debian-sys-maint'@'localhost' "
                        "IDENTIFIED BY '{0}'").format(debian_cnf.get('client/password'))
                linux.system(['mysql', '-u', 'root', '-e', sql])
                self.mysql.service.stop()

            coreutils.chown_r(__mysql__['data_dir'], 'mysql', 'mysql')
        if 'restore' in __mysql__ and \
                        __mysql__['restore'].type == 'xtrabackup':
            # XXX: when restoring data bundle on ephemeral storage, data dir should by empty
            # but move_mysqldir_to call required to set several options in my.cnf
            coreutils.clean_dir(__mysql__['data_dir'])

        #self._change_selinux_ctx()

        log.info('Patch my.cnf configuration file')
        # Init replication
        self.mysql._init_replication(master=True)

        if 'restore' in __mysql__ and \
                        __mysql__['restore'].type == 'xtrabackup':
            __mysql__['restore'].run()


        # If It's 1st init of mysql master storage
        if not storage_valid:
            if os.path.exists(__mysql__['debian.cnf']):
                log.info("Copying debian.cnf file to mysql storage")
                shutil.copy(__mysql__['debian.cnf'], __mysql__['storage_dir'])

        # If volume has mysql storage directory structure (N-th init)
        else:
            log.info('InnoDB recovery')
            self._copy_debian_cnf_back()
            if 'restore' in __mysql__ and  __mysql__['restore'].type != 'xtrabackup':
                self._innodb_recovery()
                self.mysql.service.start()

        log.info('Create Scalr users')
        # Check and create mysql system users
        self.create_users(**user_creds)

        log.info('Create data bundle')
        if 'backup' in __mysql__:
            __mysql__['restore'] = __mysql__['backup'].run()

        # Update HostUp message
        log.info('Collect HostUp data')
        md = dict(
                replication_master=__mysql__['replication_master'],
                root_password=__mysql__['root_password'],
                repl_password=__mysql__['repl_password'],
                stat_password=__mysql__['stat_password'],
                master_password=__mysql__['master_password']
        )
        if __mysql__['compat_prior_backup_restore']:
            if 'restore' in __mysql__:
                md.update(dict(
                                log_file=__mysql__['restore'].log_file,
                                log_pos=__mysql__['restore'].log_pos,
                                snapshot_config=dict(__mysql__['restore'].snapshot)))
            elif 'log_file' in __mysql__:
                md.update(dict(
                                log_file=__mysql__['log_file'],
                                log_pos=__mysql__['log_pos']))
            md.update(dict(
                                    volume_config=dict(__mysql__['volume'])))
        else:
            md.update(dict(
                    volume=dict(__mysql__['volume'])
            ))
            for key in ('backup', 'restore'):
                if key in __mysql__:
                    md[key] = dict(__mysql__[key])


        message.db_type = __mysql__['behavior']
        setattr(message, __mysql__['behavior'], md)