Example #1
0
def mount (device, mpoint = '/mnt', options=None, make_fs=False, fstype='ext3', auto_mount=False):
	if not os.path.exists(mpoint):
		os.makedirs(mpoint)
	
	options = options or ('-t', 'auto')
	
	if make_fs:
		mkfs(device,fstype)
	
	out, code = system2(['mount'] + list(options) + [device, mpoint], stderr=subprocess.STDOUT, raise_error=False)[0::2]
	if code:
		if out.find("you must specify the filesystem type") != -1:
			raise FstoolError("No filesystem found on device '%s'" % (device), FstoolError.NO_FS)
		raise FstoolError(out)
	
	if " ".join(options).find("loop") == -1:
		mtab = Mtab()		
		if not mtab.contains(device):
			raise FstoolError("Cannot mount device '%s'. %s" % (device, out), FstoolError.CANNOT_MOUNT)
	
	if auto_mount:
		fstab = Fstab()
		if not fstab.contains(device, mpoint=mpoint, reload=True):
			opts = "defaults"
			if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
				opts += ',comment=cloudconfig,nobootwait'
			fstab.append(device, mpoint, options=opts)
Example #2
0
    def __init__(self):
        if 'gce' == node.__node__['platform'].name:
            self.ensure_pid_directory()

        self.mysql_cli = MySQLClient()

        if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
            initd_script = ('/usr/sbin/service', 'mysql')
        else:
            initd_script = firstmatched(
                os.path.exists, ('/etc/init.d/mysqld', '/etc/init.d/mysql'))

        pid_file = None
        try:
            out = system2("my_print_defaults mysqld", shell=True, silent=True)
            m = re.search("--pid[-_]file=(.*)", out[0], re.MULTILINE)
            if m:
                pid_file = m.group(1)
            m = re.search("--socket=(.*)", out[0], re.MULTILINE)
            if m:
                self.socket_file = m.group(1)
        except:
            pass

        initdv2.ParametrizedInitScript.__init__(
            self,
            SERVICE_NAME,
            initd_script,
            pid_file,
            socks=[initdv2.SockParam(MYSQL_DEFAULT_PORT, timeout=3600)])
Example #3
0
def mount_ex(device, 
             mpoint='/mnt',
             options=None,
             make_fs=False,
             fstype='ext3',
             auto_mount=False):
    if not os.path.exists(mpoint):
        os.makedirs(mpoint)
    
    options = options or ('-t', 'auto')
    
    if make_fs:
        from scalarizr import storage2
        storage2.filesystem(fstype).mkfs(device)
    
    out = mount(device, mpoint, *options)[0]
    
    if " ".join(options).find("loop") == -1:
        mtab = mounts()     
        if not mtab.contains(device):
            raise MountError("Cannot mount device '%s'. %s" % (device, out),
                             MountError.CANNOT_MOUNT)
    
    if auto_mount:
        _fstab = fstab()
        if not _fstab.contains(device, mpoint=mpoint, reload=True):
            opts = "defaults"
            if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
                opts += ',comment=cloudconfig,nobootwait'
            _fstab.append(device, mpoint, options=opts)
Example #4
0
    def __init__(self):
        if 'gce' == node.__node__['platform']:
            self.ensure_pid_directory()

        self.mysql_cli = MySQLClient()


        if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
            initd_script = ('/usr/sbin/service', 'mysql')
        else:
            initd_script = firstmatched(os.path.exists, ('/etc/init.d/mysqld', '/etc/init.d/mysql'))

        pid_file = None
        try:
            out = system2("my_print_defaults mysqld", shell=True, silent=True)
            m = re.search("--pid[-_]file=(.*)", out[0], re.MULTILINE)
            if m:
                pid_file = m.group(1)
            m = re.search("--socket=(.*)", out[0], re.MULTILINE)
            if m:
                self.socket_file = m.group(1)
        except:
            pass

        initdv2.ParametrizedInitScript.__init__(self, SERVICE_NAME,
                        initd_script, pid_file, socks=[initdv2.SockParam(MYSQL_DEFAULT_PORT, timeout=3600)])
Example #5
0
 def __init__(self):
     initd_script = None
     if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
         initd_script = ("/usr/sbin/service", "mongodb")
     else:
         initd_script = firstmatched(os.path.exists, ("/etc/init.d/mongodb", "/etc/init.d/mongod"))
     initdv2.ParametrizedInitScript.__init__(self, name=SERVICE_NAME, initd_script=initd_script)
Example #6
0
    def _init_service(self, mpoint, password):
        self.service.stop()

        self.root_user = self.create_linux_user(ROOT_USER, password)
        self.master_user = self.create_linux_user(MASTER_USER, password)

        move_files = not self.cluster_dir.is_initialized(mpoint)
        self.postgresql_conf.data_directory = self.cluster_dir.move_to(
            mpoint, move_files)
        self.postgresql_conf.listen_addresses = '*'
        self.postgresql_conf.wal_level = 'hot_standby'
        self.postgresql_conf.max_wal_senders = 5

        wks = self.postgresql_conf.wal_keep_segments
        if not wks or int(wks) < 32:
            self.postgresql_conf.wal_keep_segments = 32  # [TTM-8]

        if disttool.is_ubuntu() and disttool.version_info() == (
                12, 4) and '9.1' == self.version:
            #SEE: https://bugs.launchpad.net/ubuntu/+source/postgresql-9.1/+bug/1018307
            self.postgresql_conf.ssl_renegotiation_limit = 0

        self.cluster_dir.clean()

        if disttool.is_redhat_based():
            self.config_dir.move_to(self.unified_etc_path)
            make_symlinks(os.path.join(mpoint, STORAGE_DATA_DIR),
                          self.unified_etc_path)
            self.postgresql_conf = PostgresqlConf.find(self.config_dir)
            self.pg_hba_conf = PgHbaConf.find(self.config_dir)

        self.pg_hba_conf.allow_local_connections()
Example #7
0
    def _init_service(self, mpoint, password):
        self.service.stop()

        self.root_user = self.create_linux_user(ROOT_USER, password)
        self.master_user = self.create_linux_user(MASTER_USER, password)

        move_files = not self.cluster_dir.is_initialized(mpoint)
        self.postgresql_conf.data_directory = self.cluster_dir.move_to(mpoint, move_files)
        self.postgresql_conf.listen_addresses = "*"
        self.postgresql_conf.wal_level = "hot_standby"
        self.postgresql_conf.max_wal_senders = 5

        wks = self.postgresql_conf.wal_keep_segments
        if not wks or int(wks) < 32:
            self.postgresql_conf.wal_keep_segments = 32  # [TTM-8]

        if disttool.is_ubuntu() and disttool.version_info() == (12, 4) and "9.1" == self.version:
            # SEE: https://bugs.launchpad.net/ubuntu/+source/postgresql-9.1/+bug/1018307
            self.postgresql_conf.ssl_renegotiation_limit = 0

        self.cluster_dir.clean()

        if disttool.is_redhat_based():
            self.config_dir.move_to(self.unified_etc_path)
            make_symlinks(os.path.join(mpoint, STORAGE_DATA_DIR), self.unified_etc_path)
            self.postgresql_conf = PostgresqlConf.find(self.config_dir)
            self.pg_hba_conf = PgHbaConf.find(self.config_dir)

        self.pg_hba_conf.allow_local_connections()
Example #8
0
 def __init__(self):
     initd_script = None
     if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
         initd_script = ('/usr/sbin/service', 'redis-server')
     else:
         initd_script = firstmatched(os.path.exists, ('/etc/init.d/redis', '/etc/init.d/redis-server'))
     initdv2.ParametrizedInitScript.__init__(self, name=SERVICE_NAME,
             initd_script=initd_script)
Example #9
0
 def __init__(self):
     initd_script = None
     if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
         initd_script = ('/usr/sbin/service', 'redis-server')
     else:
         initd_script = firstmatched(os.path.exists, ('/etc/init.d/redis', '/etc/init.d/redis-server'))
     initdv2.ParametrizedInitScript.__init__(self, name=SERVICE_NAME,
             initd_script=initd_script)
Example #10
0
    def __init__(self):
        self._logger = logging.getLogger(__name__)

        if disttool.is_redhat_based():
            init_script = ('/sbin/service', 'sshd')
        elif disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
            init_script = ('/usr/sbin/service', 'ssh')
        else:
            init_script = firstmatched(os.path.exists, ('/etc/init.d/ssh', '/etc/init.d/sshd'))
        self._sshd_init = ParametrizedInitScript('sshd', init_script)

        bus.on(init=self.on_init)
Example #11
0
class MysqlInitScript(initdv2.ParametrizedInitScript):

    socket_file = None
    cli = None
    sgt_pid_path = '/tmp/mysqld-sgt.pid'

    @lazy
    def __new__(cls, *args, **kws):
        obj = super(MysqlInitScript, cls).__new__(cls, *args, **kws)
        cls.__init__(obj)
        return obj

    def __init__(self):
        if 'gce' == node.__node__['platform'].name:
            self.ensure_pid_directory()

        self.mysql_cli = MySQLClient()

        if disttool.is_ubuntu() and disttool.version_info() >= (10, 4):
            initd_script = ('/usr/sbin/service', 'mysql')
        else:
            initd_script = firstmatched(
                os.path.exists, ('/etc/init.d/mysqld', '/etc/init.d/mysql'))

        pid_file = None
        try:
            out = system2("my_print_defaults mysqld", shell=True, silent=True)
            m = re.search("--pid[-_]file=(.*)", out[0], re.MULTILINE)
            if m:
                pid_file = m.group(1)
            m = re.search("--socket=(.*)", out[0], re.MULTILINE)
            if m:
                self.socket_file = m.group(1)
        except:
            pass

        initdv2.ParametrizedInitScript.__init__(
            self,
            SERVICE_NAME,
            initd_script,
            pid_file,
            socks=[initdv2.SockParam(MYSQL_DEFAULT_PORT, timeout=3600)])

    def _start_stop_reload(self, action):
        ''' XXX: Temporary ugly hack (Ubuntu 1004 upstart problem - Job is already running)'''
        try:
            args = [self.initd_script] \
                            if isinstance(self.initd_script, basestring) \
                            else list(self.initd_script)
            args.append(action)
            out, err, returncode = system2(args,
                                           close_fds=True,
                                           preexec_fn=os.setsid)
        except PopenError, e:
            if 'Job is already running' not in str(e):
                raise InitdError("Popen failed with error %s" % (e, ))

        if action == 'restart':
            if err and 'stop: Job has already been stopped: mysql' in err:
                return True
            else:
                LOG.debug('waiting for mysql process')
                wait_until(lambda: MYSQLD_PATH in system2(
                    ('ps', '-G', DEFAULT_OWNER, '-o', 'command', '--no-headers'
                     ))[0],
                           timeout=10,
                           sleep=1)

        if action == 'start' and disttool.is_ubuntu(
        ) and disttool.version_info() >= (10, 4):
            try:
                LOG.debug('waiting for mysql process')
                wait_until(lambda: MYSQLD_PATH in system2(
                    ('ps', '-G', DEFAULT_OWNER, '-o', 'command', '--no-headers'
                     ))[0],
                           timeout=10,
                           sleep=1)
                LOG.debug('waiting for debian-start finish')
                out = system2(
                    'ps axo pid,command --noheaders | grep /etc/mysql/debian-start',
                    shell=True)[0].strip()
                if out:
                    pid = out.split('\n')[0].split(' ')[0]
                    wait_until(lambda: not os.path.exists('/proc/%s' % pid),
                               sleep=1)
            except:
                self._start_stop_reload('restart')
                return True

        if self.socks and (action != "stop"
                           and not (action == 'reload' and not self.running)):
            for sock in self.socks:
                wait_sock(sock)

        return True