Exemple #1
0
    def _start_stop_reload(self, action):
        chef_client_bin = which('chef-client')
        if action == "start":
            if not self.running:
                # Stop default chef-client init script
                if os.path.exists(self._default_init_script):
                    system2((self._default_init_script, "stop"),
                            close_fds=True,
                            preexec_fn=os.setsid,
                            raise_exc=False)

                cmd = (chef_client_bin, '--daemonize', '--logfile',
                       '/var/log/chef-client.log', '--pid', PID_FILE)
                try:
                    out, err, rcode = system2(cmd,
                                              close_fds=True,
                                              preexec_fn=os.setsid,
                                              env=self._env)
                except PopenError, e:
                    raise initdv2.InitdError('Failed to start chef: %s' % e)

                if rcode:
                    msg = ('Chef failed to start daemonized. '
                           'Return code: %s\nOut:%s\nErr:%s')
                    raise initdv2.InitdError(msg % (rcode, out, err))
Exemple #2
0
    def start(self):
        try:
            if not self.running:

                #TODO: think about moving this code elsewhere
                if self.port == __redis__['defaults']['port']:
                    base_dir = self.redis_conf.dir
                    snap_src = os.path.join(base_dir, __redis__['db_filename'])
                    snap_dst = os.path.join(base_dir, get_snap_db_filename(__redis__['defaults']['port']))
                    if os.path.exists(snap_src) and not os.path.exists(snap_dst):
                        shutil.move(snap_src, snap_dst)
                        if 'snapshotting' == __redis__["persistence_type"]:
                            self.redis_conf.dbfilename = snap_dst
                    aof_src = os.path.join(base_dir, __redis__['aof_filename'])
                    aof_dst = os.path.join(base_dir, get_aof_db_filename(__redis__['defaults']['port']))
                    if os.path.exists(aof_src) and not os.path.exists(aof_dst):
                        shutil.move(aof_src, aof_dst)
                        if 'aof' == __redis__["persistence_type"]:
                            self.redis_conf.appendfilename = aof_dst

                LOG.debug('Starting %s on port %s' % (__redis__['redis-server'], self.port))
                system2('%s %s -s %s -c "%s %s"' % (
                    __redis__['su'], 
                    __redis__['defaults']['user'], 
                    __redis__['bash'], 
                    __redis__['redis-server'], 
                    self.config_path), shell=True, close_fds=True, preexec_fn=os.setsid)
                wait_until(lambda: self.running)
                #wait_until(lambda: self.cli.test_connection())
                LOG.debug('%s process has been started.' % SERVICE_NAME)

        except PopenError, e:
            LOG.error('Unable to start redis process: %s' % e)
            raise initdv2.InitdError(e)
Exemple #3
0
    def start(self):
        try:
            if not self.running:

                #TODO: think about moving this code elsewhere
                if self.port == DEFAULT_PORT:
                    base_dir = self.redis_conf.dir
                    snap_src = os.path.join(base_dir, DB_FILENAME)
                    snap_dst = os.path.join(base_dir, get_snap_db_filename(DEFAULT_PORT))
                    if os.path.exists(snap_src) and not os.path.exists(snap_dst):
                        shutil.move(snap_src, snap_dst)
                        self.redis_conf.dbfilename = snap_dst
                    aof_src = os.path.join(base_dir, AOF_FILENAME)
                    aof_dst = os.path.join(base_dir, get_aof_db_filename(DEFAULT_PORT))
                    if os.path.exists(aof_src) and not os.path.exists(aof_dst):
                        shutil.move(aof_src, aof_dst)
                        self.redis_conf.appendfilename = aof_dst


                LOG.debug('Starting %s on port %s' % (BIN_PATH, self.port))
                system2('%s %s -s %s -c "%s %s"'%(SU_EXEC, DEFAULT_USER, BASH, BIN_PATH, self.config_path), shell=True, close_fds=True, preexec_fn=os.setsid)
                wait_until(lambda: self.running, timeout=MAX_START_TIMEOUT)
                wait_until(lambda: self.cli.test_connection(), timeout=MAX_START_TIMEOUT)
                LOG.debug('%s process has been started.' % SERVICE_NAME)

        except PopenError, e:
            LOG.error('Unable to start redis process: %s' % e)
            raise initdv2.InitdError(e)
Exemple #4
0
 def reload(self):
     try:
         if os.path.exists(self.pid_file):
             pid = self.pid()
             if pid:
                 args = [
                     self.haproxy_exec, '-f', self.config_path, '-p',
                     self.pid_file, '-D', '-sf', pid
                 ]
                 util.system2(args,
                              close_fds=True,
                              logger=LOG,
                              preexec_fn=os.setsid)
                 util.wait_until(
                     lambda: self.pid() and self.pid() != pid,
                     timeout=self.timeout,
                     sleep=0.5,
                     error_text="Error reloading HAProxy service process.")
                 if self.status() != 0:
                     raise initdv2.InitdError(
                         "HAProxy service not running.")
         else:
             raise LookupError('File %s not exist' % self.pid_file)
     except:
         raise initdv2.InitdError, "HAProxy service not running can't reload it."\
                 " Details: %s" % sys.exc_info()[1], sys.exc_info()[2]
Exemple #5
0
 def __init__(self):
     try:
         self.bin_path = software.which('mysql-proxy')
     except LookupError:
         raise initdv2.InitdError(
             "Mysql-proxy binary not found. Check your installation")
     version_str = system2((self.bin_path, '-V'))[0].splitlines()[0]
     self.version = tuple(map(int, version_str.split()[1].split('.')))
     self.sock = initdv2.SockParam(4040)
Exemple #6
0
 def __init__(self):
     res = software.whereis('mysql-proxy')
     if not res:
         raise initdv2.InitdError(
             "Mysql-proxy binary not found. Check your installation")
     self.bin_path = res[0]
     version_str = system2((self.bin_path, '-V'))[0].splitlines()[0]
     self.version = tuple(map(int, version_str.split()[1].split('.')))
     self.sock = initdv2.SockParam(4040)
Exemple #7
0
 def reload(self, reason=None):
     if self.running:
         LOG.info("Reloading apache: %s" % str(reason) if reason else '')
         try:
             out, err, retcode = system2(__apache__["apachectl"] +
                                         " graceful",
                                         shell=True)
             if retcode > 0:
                 raise initdv2.InitdError("Cannot reload apache: %s" % err)
         except PopenError, e:
             raise InitdError(e)
Exemple #8
0
 def configtest(self, path=None):
     args = __apache__["apachectl"] + " configtest"
     if path:
         args += "-f %s" % path
     try:
         out = system2(args, shell=True)[1]
         if "error" in out.lower():
             raise initdv2.InitdError("Invalid Apache configuration: %s" %
                                      out)
     except PopenError, e:
         raise InitdError(e)
Exemple #9
0
 def start(self):
     if not self._main_process_started() and not self.running:
         LOG.info("Starting apache")
         initdv2.ParametrizedInitScript.start(self)
         if self.pid_file:
             try:
                 wait_until(lambda: os.path.exists(self.pid_file) or self.
                            _main_process_started(),
                            sleep=0.2,
                            timeout=30)
             except (Exception, BaseException), e:
                 raise initdv2.InitdError("Cannot start Apache (%s)" %
                                          str(e))
         time.sleep(0.5)
Exemple #10
0
    def start(self):
        if self.status() == 0:
            raise initdv2.InitdError("Cannot start HAProxy. It already running.")

        util.system2([self.haproxy_exec, '-f', self.config_path, '-p', self.pid_file, '-D'],)
        if self.pid_file:
            try:
                util.wait_until(lambda: os.path.exists(self.pid_file), timeout=self.timeout,
                                sleep=0.2, error_text="HAProxy pid file %s does'not exist"%
                                self.pid_file)
            except:
                err = "Cannot start HAProxy: pid file %s hasn't been created. " \
                        "Details: %s" % (self.pid_file, sys.exc_info()[1])
                raise initdv2.InitdError, err, sys.exc_info()[2]
Exemple #11
0
 def restart(self, reason=None):
     if not self._main_process_started():
         self.start()
     else:
         LOG.info("Restarting apache: %s" % str(reason) if reason else '')
         initdv2.ParametrizedInitScript.restart(self)
     if self.pid_file:
         try:
             wait_until(lambda: os.path.exists(self.pid_file),
                        sleep=0.2,
                        timeout=5,
                        error_text="Apache pid file %s doesn`t exists" %
                        self.pid_file)
         except:
             raise initdv2.InitdError(
                 "Cannot start Apache: pid file %s hasn`t been created" %
                 self.pid_file)
     time.sleep(0.5)
Exemple #12
0
    def _start_stop_reload(self, action):
        chef_client_bin = linux.which('chef-client')
        if action == "start":
            if not self.running:
                # Stop default chef-client init script
                if os.path.exists(self._default_init_script):
                    linux.system(
                        (self._default_init_script, "stop"), 
                        close_fds=True, 
                        preexec_fn=os.setsid, 
                        raise_exc=False
                    )

                cmd = (chef_client_bin, '--daemonize', '--logfile', 
                        '/var/log/chef-client.log', '--pid', self.pid_file)
                out, err, rcode = linux.system(cmd, close_fds=True, 
                            preexec_fn=os.setsid, env=self._env,
                            stdout=open(os.devnull, 'w+'), 
                            stderr=open(os.devnull, 'w+'), 
                            raise_exc=False)
                if rcode == 255:
                    LOG.debug('chef-client daemon already started')
                elif rcode:
                    msg = (
                        'Chef failed to start daemonized. '
                        'Return code: %s\nOut:%s\nErr:%s'
                        )
                    raise initdv2.InitdError(msg % (rcode, out, err))

        elif action == "stop":
            if self.running:
                with open(self.pid_file) as f:
                    pid = int(f.read().strip())
                try:
                    os.getpgid(pid)
                except OSError:
                    os.remove(self.pid_file)
                else:
                    os.kill(pid, signal.SIGTERM)