Пример #1
0
    def __init__(self, manifest=None):
        mgr_name = "apt" if disttool.is_debian_based() else "yum"
        self.mgr = AptPackageMgr() if disttool.is_debian_based() else YumPackageMgr()

        self.manifest = os.path.abspath(manifest or self.DEFAULT_MANIFEST)
        self.conf = configparser.ConfigParser()
        self.conf.read(self.manifest)

        dist_id, release = disttool.linux_dist()[0:2]
        if disttool.is_redhat_based() and not disttool.is_fedora():
            dist_id = "el"
        dist_id = dist_id.lower()
        major_release = release.split(".")[0]
        self.sections = [
            s % locals()
            for s in (
                "%(mgr_name)s",
                "%(mgr_name)s:%(dist_id)s",
                "%(mgr_name)s:%(dist_id)s%(major_release)s",
                "%(mgr_name)s:%(dist_id)s%(release)s",
            )
        ]
        self.sections.reverse()

        LOG.debug(
            "Initialized ImpLoader with such settings\n" "  manifest: %s\n" "  sections: %s\n",
            self.manifest,
            self.sections,
        )
Пример #2
0
    def __init__(self, manifest=None):
        mgr_name = 'apt' if disttool.is_debian_based() else 'yum'
        self.mgr = AptPackageMgr() if disttool.is_debian_based(
        ) else YumPackageMgr()

        self.manifest = os.path.abspath(manifest or self.DEFAULT_MANIFEST)
        self.conf = configparser.ConfigParser()
        self.conf.read(self.manifest)

        dist_id, release = disttool.linux_dist()[0:2]
        if disttool.is_redhat_based() and not disttool.is_fedora():
            dist_id = 'el'
        dist_id = dist_id.lower()
        major_release = release.split('.')[0]
        self.sections = [
            s % locals() for s in ('%(mgr_name)s', '%(mgr_name)s:%(dist_id)s',
                                   '%(mgr_name)s:%(dist_id)s%(major_release)s',
                                   '%(mgr_name)s:%(dist_id)s%(release)s')
        ]
        self.sections.reverse()

        LOG.debug(
            'Initialized ImpLoader with such settings\n'
            '  manifest: %s\n'
            '  sections: %s\n', self.manifest, self.sections)
Пример #3
0
    def move_mysqldir_to(self, storage_path):
        LOG.info('Moving mysql dir to %s' % storage_path)
        for directive, dirname in (
                        ('mysqld/log_bin', os.path.join(storage_path,STORAGE_BINLOG)),
                        ('mysqld/datadir', os.path.join(storage_path,STORAGE_DATA_DIR) + '/')
                        ):

            dest = os.path.dirname(dirname)
            if os.path.isdir(dest):
                LOG.info('No need to move %s to %s: already in place.' % (directive, dest))
            else:
                os.makedirs(dest)

                raw_value = self.my_cnf.get(directive)
                LOG.debug('directive %s:%s' % (directive, raw_value))
                if raw_value:
                    src_dir = os.path.dirname(raw_value + "/") + "/"
                    LOG.debug('source path: %s' % src_dir)
                    if os.path.isdir(src_dir) and src_dir != dest:
                        selinuxenabled = software.which('selinuxenabled')
                        if selinuxenabled:
                            if not system2((selinuxenabled, ), raise_exc=False)[2]:
                                if not system2((software.which('getsebool'), 'mysqld_disable_trans'), raise_exc=False)[2]:
                                    LOG.debug('Make SELinux rule for rsync')
                                    system2((software.which('setsebool'), '-P', 'mysqld_disable_trans', '1'))

                        LOG.info('Copying mysql directory \'%s\' to \'%s\'', src_dir, dest)
                        rsync(src_dir, dest, archive=True, exclude=['ib_logfile*', '*.sock'])

            self.my_cnf.set(directive, dirname)
            chown_r(dest, "mysql", "mysql")
            # Adding rules to apparmor config
            if disttool.is_debian_based():
                _add_apparmor_rules(dest)
Пример #4
0
    def test_DistTool(self):
        self.assertTrue(disttool.is_linux())
        self.assertTrue(disttool.is_redhat_based())
        self.assertTrue(disttool.is_fedora())

        self.assertFalse(disttool.is_win())
        self.assertFalse(disttool.is_sun())
        self.assertFalse(disttool.is_debian_based())
Пример #5
0
	def update(self, workdir):
		if not os.access(self.executable, os.X_OK):
			self._logger.info('Installing Git SCM...')
			if disttool.is_debian_based():
				system2(('apt-get', '-y', 'install', 'git-core'))
			elif disttool.is_redhat_based():
				system2(('yum', '-y', 'install', 'git'))
			else:
				raise SourceError('Cannot install Git. Unknown distribution %s' %
								str(disttool.linux_dist()))

		#if not os.path.exists(workdir):
		#	self._logger.info('Creating destination directory')
		#	os.makedirs(workdir)

		tmpdir = tempfile.mkdtemp()
		env = {}

		try:
			if self.private_key:
				pk_path = os.path.join(tmpdir, 'pk.pem')
				filetool.write_file(pk_path, self.private_key)
				os.chmod(pk_path, 0400)

				git_ssh_path = os.path.join(tmpdir, 'git_ssh.sh')
				filetool.write_file(git_ssh_path, self.ssh_tpl % pk_path)
				os.chmod(git_ssh_path, 0755)

				env.update(dict(GIT_SSH=git_ssh_path))

			if os.path.exists(os.path.join(workdir, '.git')):
				origin_url = system2(('git', 'config', '--get', 'remote.origin.url'), cwd=workdir, raise_exc=False)[0]
				if origin_url.strip() != self.url.strip():
					self._logger.info('%s is not origin of %s (%s is)', self.url, workdir, origin_url)
					self._logger.info('Remove all files in %s and checkout from %s', workdir, self.url )
					shutil.rmtree(workdir)
					os.mkdir(workdir)

					out, err, ret_code = system2(('git', 'clone', self.url, workdir), env=env)
				else:
					self._logger.info('Updating directory %s (git-pull)', workdir)
					out, err, ret_code = system2(('git', 'pull'), env=env, cwd=workdir)
			else:
				self._logger.info('Checkout from %s', self.url)
				out, err, ret_code = system2(('git', 'clone', self.url, workdir), env=env)

			if ret_code:
				raise Exception('Git failed to clone repository. %s' % out)

			self._logger.info('Successfully deployed %s from %s', workdir, self.url)
		finally:
			shutil.rmtree(tmpdir)
Пример #6
0
    def __init__(self):

        pid_file = None
        if disttool.is_redhat_based():
            pid_file = "/var/run/memcached/memcached.pid"
        elif disttool.is_debian_based():
            pid_file = "/var/run/memcached.pid"

        initd_script = '/etc/init.d/memcached'
        if not os.path.exists(initd_script):
            raise HandlerError("Cannot find Memcached init script at %s. Make sure that memcached is installed" % initd_script)

        initdv2.ParametrizedInitScript.__init__(self, 'memcached', initd_script, pid_file, socks=[initdv2.SockParam(11211)])
Пример #7
0
def main():
    init_script()
    logger = logging.getLogger("scalarizr.scripts.update")
    logger.info("Starting update script...")

    if disttool.is_debian_based():
        logger.info("Updating scalarizr with Apt")
        system2("apt-get -y install scalarizr", shell=True)
    elif disttool.is_redhat_based():
        logger.info("Updating scalarizr with Yum")
        system2("yum -y update scalarizr", shell=True)
    else:
        logger.error("Don't know how to update scalarizr on %s", " ".join(disttool.linux_dist()))
Пример #8
0
def main():
    init_script()
    logger = logging.getLogger("scalarizr.scripts.update")
    logger.info("Starting update script...")

    if disttool.is_debian_based():
        logger.info("Updating scalarizr with Apt")
        system2("apt-get -y install scalarizr", shell=True)
    elif disttool.is_redhat_based():
        logger.info("Updating scalarizr with Yum")
        system2("yum -y update scalarizr", shell=True)
    else:
        logger.error("Don't know how to update scalarizr on %s",
                     " ".join(disttool.linux_dist()))
Пример #9
0
    def move_mysqldir_to(self, storage_path):
        LOG.info('Moving mysql dir to %s' % storage_path)
        for directive, dirname in (
            ('mysqld/log_bin', os.path.join(storage_path, STORAGE_BINLOG)),
            ('mysqld/datadir',
             os.path.join(storage_path, STORAGE_DATA_DIR) + '/')):

            dest = os.path.dirname(dirname)
            if os.path.isdir(dest):
                LOG.info('No need to move %s to %s: already in place.' %
                         (directive, dest))
            else:
                os.makedirs(dest)

                raw_value = self.my_cnf.get(directive)
                LOG.debug('directive %s:%s' % (directive, raw_value))
                if raw_value and node.__node__['platform'] != 'openstack':
                    src_dir = os.path.dirname(raw_value + "/") + "/"
                    LOG.debug('source path: %s' % src_dir)
                    if os.path.isdir(src_dir) and src_dir != dest:
                        selinuxenabled = software.which('selinuxenabled')
                        if selinuxenabled:
                            if not system2(
                                (selinuxenabled, ), raise_exc=False)[2]:
                                if not system2((software.which('getsebool'),
                                                'mysqld_disable_trans'),
                                               raise_exc=False)[2]:
                                    LOG.debug('Make SELinux rule for rsync')
                                    system2((software.which('setsebool'), '-P',
                                             'mysqld_disable_trans', '1'))
                                else:
                                    semanage = get_semanage()
                                    system2((semanage, 'fcontext', '-a', '-t',
                                             'bin_t', '/usr/bin/rsync'))
                                    system2((software.which('restorecon'),
                                             '-v', '/usr/bin/rsync'))

                        LOG.info('Copying mysql directory \'%s\' to \'%s\'',
                                 src_dir, dest)
                        rsync(src_dir,
                              dest,
                              archive=True,
                              exclude=['ib_logfile*', '*.sock'])

            self.my_cnf.set(directive, dirname)
            chown_r(dest, "mysql", "mysql")
            # Adding rules to apparmor config
            if disttool.is_debian_based():
                _add_apparmor_rules(dest)
Пример #10
0
	def update(self, workdir):
		if not os.access(self.executable, os.X_OK):
			self._logger.info('Installing Subversion SCM...')
			if disttool.is_debian_based():
				system2(('apt-get', '-y', '--force-yes', 'install', 'subversion'))
			elif disttool.is_redhat_based():
				system2(('yum', '-y', 'install', 'subversion'))
			else:
				raise SourceError('Cannot install Subversion. Unknown distribution %s' % 
								str(disttool.linux_dist()))
		
		do_update = False
		if os.path.exists(os.path.join(workdir, '.svn')):
			out = system2(('svn', 'info', workdir))[0]
			try:
				svn_url = filter(lambda line: line.startswith('URL:'), out.split('\n'))[0].split(':', 1)[1].strip()
			except IndexError:
				raise SourceError('Cannot extract Subversion URL. Text:\n %s', out)
			if svn_url != self.url:
				#raise SourceError('Working copy %s is checkouted from different repository %s' % (workdir, svn_url))
				self._logger.info('%s is not origin of %s (%s is)', self.url, workdir, svn_url)
				self._logger.info('Remove all files in %s and checkout from %s', workdir, self.url)
				shutil.rmtree(workdir)
				os.mkdir(workdir)
			else:
				do_update = True
			
		args = [
			'svn' , 
			'update' if do_update else 'co'
		]
		if self.login and self.password:
			args += [
				'--username', self.login,
				'--password', self.password,
				'--non-interactive'
			]
			if self.client_version >= (1, 5, 0):
				args += ['--trust-server-cert']
			
		if args[1] == 'co':
			args += [self.url]
		args += [workdir]
		
		self._logger.info('Updating source from %s into working dir %s', self.url, workdir)		
		out = system2(args)[0]
		self._logger.info(out)
		self._logger.info('Deploying %s to %s has been completed successfully.' % (self.url,workdir))
Пример #11
0
 def disable_requiretty(self):
     '''
     requiretty      If set, sudo will only run when the user is logged in to a real tty.  
     When this flag is set, sudo can only be  run from a login session and not via other means 
     such  as cron(8) or cgi-bin scripts.  This flag is off by default on all systems but CentOS5.
     '''
     path = '/etc/sudoers'
     self._logger.debug('Disabling requiretty in %s' % path)
     if not disttool.is_debian_based():
         orig = None
         with open(path, 'r') as fp:
             orig = fp.read()
         new = re.sub('Defaults\s+requiretty', '\n', orig)
         if new != orig:
             with open(path, 'w') as fp:
                 fp.write(new)
Пример #12
0
 def disable_requiretty(self):
     '''
     requiretty      If set, sudo will only run when the user is logged in to a real tty.  
     When this flag is set, sudo can only be  run from a login session and not via other means 
     such  as cron(8) or cgi-bin scripts.  This flag is off by default on all systems but CentOS5.
     '''
     path = '/etc/sudoers'
     self._logger.debug('Disabling requiretty in %s' % path)
     if not disttool.is_debian_based():
         orig = None
         with open(path, 'r') as fp:
             orig = fp.read()
         new = re.sub('Defaults\s+requiretty', '\n', orig)
         if new != orig:
             with open(path, 'w') as fp:
                 fp.write(new)
Пример #13
0
    def move_mysqldir_to(self, storage_path):
        LOG.info("Moving mysql dir to %s" % storage_path)
        for directive, dirname in (
            ("mysqld/log_bin", os.path.join(storage_path, STORAGE_BINLOG)),
            ("mysqld/datadir", os.path.join(storage_path, STORAGE_DATA_DIR) + "/"),
        ):

            dest = os.path.dirname(dirname)
            if os.path.isdir(dest):
                LOG.info("No need to move %s to %s: already in place." % (directive, dest))
            else:
                os.makedirs(dest)

                raw_value = self.my_cnf.get(directive)
                LOG.debug("directive %s:%s" % (directive, raw_value))
                if raw_value:
                    src_dir = os.path.dirname(raw_value + "/") + "/"
                    LOG.debug("source path: %s" % src_dir)
                    if os.path.isdir(src_dir) and src_dir != dest:
                        try:
                            if not system2((software.which("selinuxenabled"),), raise_exc=False)[2]:
                                if not system2((software.which("getsebool"), "mysqld_disable_trans"), raise_exc=False)[
                                    2
                                ]:
                                    LOG.debug("Make SELinux rule for rsync")
                                    system2((software.which("setsebool"), "-P", "mysqld_disable_trans", "1"))
                        except LookupError:
                            pass

                        LOG.info("Copying mysql directory '%s' to '%s'", src_dir, dest)
                        rsync = filetool.Rsync().archive()
                        rsync.source(src_dir).dest(dest).exclude(["ib_logfile*"])
                        system2(str(rsync), shell=True)
            self.my_cnf.set(directive, dirname)

            rchown("mysql", dest)
            # Adding rules to apparmor config
            if disttool.is_debian_based():
                _add_apparmor_rules(dest)
Пример #14
0
 def _copy_debian_cnf_back(self):
     debian_cnf = os.path.join(__mysql__['storage_dir'], 'debian.cnf')
     if disttool.is_debian_based() and os.path.exists(debian_cnf):
         LOG.debug("Copying debian.cnf from storage to mysql configuration directory")
         shutil.copy(debian_cnf, '/etc/mysql/')
Пример #15
0
        else:
            self._logger.debug('config contains proxies.include: %s \n%s' %
                               (self.api.proxies_inc_path, include_list))

        if remove_server_section:
            self._logger.debug('removing http/server section')
            try:
                config.remove('http/server')
            except (ValueError, IndexError):
                self._logger.debug('no http/server section')
        else:
            self._logger.debug('Do not removing http/server section')
            if not config.get_list('http/server'):
                config.read(os.path.join(bus.share_path, "nginx/server.tpl"))

        if disttool.is_debian_based():
        # Comment /etc/nginx/sites-enabled/*
            try:
                i = config.get_list('http/include').index('/etc/nginx/sites-enabled/*')
                config.comment('http/include[%d]' % (i+1))
                self._logger.debug('comment site-enabled include')
            except (ValueError, IndexError):
                self._logger.debug('site-enabled include already commented')
        elif disttool.is_redhat_based():
            def_host_path = '/etc/nginx/conf.d/default.conf'
            if os.path.exists(def_host_path):
                default_host = Configuration('nginx')
                default_host.read(def_host_path)
                default_host.comment('server')
                default_host.write(def_host_path)
Пример #16
0
 def find(cls, mongo_conf):
     dir = mongo_conf.dbpath
     if not dir:
         dir = DEFAULT_UBUNTU_DB_PATH if disttool.is_debian_based(
         ) else DEFAULT_CENTOS_DB_PATH
     return cls(dir)
Пример #17
0
import pymongo

MONGOD = software.which('mongod')
MONGO_CLI = software.which('mongo')
MONGO_DUMP = software.which('mongodump')
MONGOS = software.which('mongos')

ROUTER_DEFAULT_PORT = 27017
ARBITER_DEFAULT_PORT = 27020
REPLICA_DEFAULT_PORT = 27018
CONFIG_SERVER_DEFAULT_PORT = 27019

SERVICE_NAME = BuiltinBehaviours.MONGODB
STORAGE_PATH = "/mnt/mongodb-storage"

DEFAULT_USER = '******' if disttool.is_debian_based() else 'mongod'
LOG_DIR = '/var/log/mongodb'
if not os.path.isdir(LOG_DIR):
    os.makedirs(LOG_DIR)
chown_r(LOG_DIR, DEFAULT_USER)

LOG_PATH_DEFAULT = os.path.join(LOG_DIR, 'mongodb.shardsrv.log')
DEFAULT_UBUNTU_DB_PATH = '/var/lib/mongodb'
DEFAULT_CENTOS_DB_PATH = '/var/lib/mongo'
LOCK_FILE = 'mongod.lock'

SCALR_USER = '******'
STORAGE_DATA_DIR = os.path.join(STORAGE_PATH, 'data')

UBUNTU_CONFIG_PATH = '/etc/mongodb.conf'
CENTOS_CONFIG_PATH = '/etc/mongod.conf'
Пример #18
0

MONGOD = software.which('mongod')
MONGO_CLI = software.which('mongo')
MONGO_DUMP = software.which('mongodump')
MONGOS = software.which('mongos')

ROUTER_DEFAULT_PORT = 27017
ARBITER_DEFAULT_PORT = 27020
REPLICA_DEFAULT_PORT = 27018
CONFIG_SERVER_DEFAULT_PORT = 27019

SERVICE_NAME = BuiltinBehaviours.MONGODB
STORAGE_PATH = "/mnt/mongodb-storage"

DEFAULT_USER = '******' if disttool.is_debian_based() else 'mongod'
LOG_DIR = '/var/log/mongodb'
if not os.path.isdir(LOG_DIR):
    os.makedirs(LOG_DIR)
chown_r(LOG_DIR, DEFAULT_USER)

LOG_PATH_DEFAULT = os.path.join(LOG_DIR, 'mongodb.shardsrv.log') 
DEFAULT_UBUNTU_DB_PATH = '/var/lib/mongodb'
DEFAULT_CENTOS_DB_PATH = '/var/lib/mongo'
LOCK_FILE = 'mongod.lock'

SCALR_USER = '******'
STORAGE_DATA_DIR = os.path.join(STORAGE_PATH, 'data')

UBUNTU_CONFIG_PATH = '/etc/mongodb.conf'
CENTOS_CONFIG_PATH = '/etc/mongod.conf'
Пример #19
0
class MemcachedConf(BaseConfig):

    config_type = 'app'
    config_name = 'apache2.conf' if disttool.is_debian_based() else 'httpd.conf'
Пример #20
0
 def find(cls, mongo_conf):
     dir = mongo_conf.dbpath
     if not dir:
         dir = DEFAULT_UBUNTU_DB_PATH if disttool.is_debian_based() else DEFAULT_CENTOS_DB_PATH
     return cls(dir) 
Пример #21
0
def package_mgr():
    return AptPackageMgr() if disttool.is_debian_based() else YumPackageMgr()
Пример #22
0
class ApacheConf(BaseConfig):

    config_type = "app"
    config_name = "apache2.conf" if disttool.is_debian_based() else "httpd.conf"
Пример #23
0
def package_mgr():
    return AptPackageMgr() if disttool.is_debian_based() else YumPackageMgr()