예제 #1
0
 def stop(self, name, *args, **kargs):
     with sh.Rooted(kargs.get("run_as_root", True)):
         trace_dir = kargs.get("trace_dir")
         if not trace_dir or not sh.isdir(trace_dir):
             msg = "No trace directory found from which to stop %s" % (name)
             raise excp.StopException(msg)
         fn_name = FORK_TEMPL % (name)
         (pid_file, stderr_fn, stdout_fn) = self._form_file_names(trace_dir, fn_name)
         trace_fn = tr.trace_fn(trace_dir, fn_name)
         if sh.isfile(pid_file) and sh.isfile(trace_fn):
             pid = int(sh.load_file(pid_file).strip())
             (killed, attempts) = self._stop_pid(pid)
             #trash the files
             if killed:
                 LOG.debug("Killed pid %s after %s attempts" % (pid, attempts))
                 LOG.debug("Removing pid file %s" % (pid_file))
                 sh.unlink(pid_file)
                 LOG.debug("Removing stderr file %s" % (stderr_fn))
                 sh.unlink(stderr_fn)
                 LOG.debug("Removing stdout file %s" % (stdout_fn))
                 sh.unlink(stdout_fn)
                 LOG.debug("Removing %s trace file %s" % (name, trace_fn))
                 sh.unlink(trace_fn)
             else:
                 msg = "Could not stop %s after %s attempts" % (name, attempts)
                 raise excp.StopException(msg)
         else:
             msg = "No pid or trace file could be found to stop %s in directory %s" % (name, trace_dir)
             raise excp.StopException(msg)
예제 #2
0
 def stop(self, app_name):
     with sh.Rooted(ROOT_GO):
         if not sh.isdir(self.trace_dir):
             msg = "No trace directory found from which to stop %s" % (app_name)
             raise excp.StopException(msg)
         fn_name = FORK_TEMPL % (app_name)
         (pid_file, stderr_fn, stdout_fn) = self._form_file_names(fn_name)
         trace_fn = tr.trace_fn(self.trace_dir, fn_name)
         if sh.isfile(pid_file) and sh.isfile(trace_fn):
             pid = int(sh.load_file(pid_file).strip())
             (killed, attempts) = self._stop_pid(pid)
             # Trash the files if it worked
             if killed:
                 LOG.debug("Killed pid %s after %s attempts" % (pid, attempts))
                 LOG.debug("Removing pid file %s" % (pid_file))
                 sh.unlink(pid_file)
                 LOG.debug("Removing stderr file %s" % (stderr_fn))
                 sh.unlink(stderr_fn)
                 LOG.debug("Removing stdout file %s" % (stdout_fn))
                 sh.unlink(stdout_fn)
                 LOG.debug("Removing %s trace file %s" % (app_name, trace_fn))
                 sh.unlink(trace_fn)
             else:
                 msg = "Could not stop %s after %s attempts" % (app_name, attempts)
                 raise excp.StopException(msg)
         else:
             msg = "No pid or trace file could be found to stop %s in directory %s" % (app_name, self.trace_dir)
             raise excp.StopException(msg)
예제 #3
0
 def _begin_start(self, name, program, args):
     run_trace = tr.TraceWriter(
         tr.trace_fn(self.trace_dir, SCREEN_TEMPL % (name)))
     run_trace.trace(TYPE, RUN_TYPE)
     run_trace.trace(NAME, name)
     run_trace.trace(ARGS, json.dumps(args))
     full_cmd = [program] + list(args)
     session_name = self._get_session()
     inited_screen = False
     if session_name is None:
         inited_screen = True
         self._do_screen_init()
         session_name = self._get_session()
         if session_name is None:
             msg = "After initializing screen with session named [%s], no screen session with that name was found!" % (
                 SESSION_NAME)
             raise excp.StartException(msg)
     run_trace.trace(SESSION_ID, session_name)
     if inited_screen or not sh.isfile(SCREEN_RC):
         rc_gen = ScreenRcGenerator(self)
         rc_contents = rc_gen.create(session_name, self._get_env())
         out_fn = sh.abspth(SCREEN_RC)
         LOG.info("Writing your created screen rc file to [%s]" % (out_fn))
         sh.write_file(out_fn, rc_contents)
     self._do_start(session_name, name, full_cmd)
     return run_trace.filename()
예제 #4
0
 def _pre_run(self, instances, component_order):
     if not sh.isdir(self.directory):
         sh.mkdir(self.directory)
     if self.rc_file:
         try:
             LOG.info("Attempting to load rc file at [%s] which has your environment settings." % (self.rc_file))
             am_loaded = env_rc.RcReader().load(self.rc_file)
             LOG.info("Loaded [%s] settings from rc file [%s]" % (am_loaded, self.rc_file))
         except IOError:
             LOG.warn('Error reading rc file located at [%s]. Skipping loading it.' % (self.rc_file))
     LOG.info("Verifying that the components are ready to rock-n-roll.")
     for component in component_order:
         inst = instances[component]
         inst.verify()
     LOG.info("Warming up your component configurations (ie so you won't be prompted later)")
     for component in component_order:
         inst = instances[component]
         inst.warm_configs()
     if self.gen_rc and self.rc_file:
         writer = env_rc.RcWriter(self.cfg)
         if not sh.isfile(self.rc_file):
             LOG.info("Generating a file at [%s] that will contain your environment settings." % (self.rc_file))
             writer.write(self.rc_file)
         else:
             LOG.info("Updating a file at [%s] that contains your environment settings." % (self.rc_file))
             am_upd = writer.update(self.rc_file)
             LOG.info("Updated [%s] settings in rc file [%s]" % (am_upd, self.rc_file))
예제 #5
0
def _pre_run(action_name, root_dir, pkg_manager, config, component_order, instances):
    loaded_env = False
    rc_fn = _RC_FILE
    try:
        if sh.isfile(rc_fn):
            LOG.info("Attempting to load rc file at [%s] which has your environment settings." % (rc_fn))
            am_loaded = env_rc.load_local_rc(rc_fn)
            loaded_env = True
            LOG.info("Loaded [%s] settings from rc file [%s]" % (am_loaded, rc_fn))
    except IOError:
        LOG.warn('Error reading rc file located at [%s]. Skipping loading it.' % (rc_fn))
    if action_name == settings.INSTALL:
        if root_dir:
            sh.mkdir(root_dir)
    LOG.info("Verifying that the components are ready to rock-n-roll.")
    all_instances = instances[0]
    prerequisite_instances = instances[1]
    for component in component_order:
        base_inst = all_instances.get(component)
        if base_inst:
            base_inst.verify()
        pre_inst = prerequisite_instances.get(component)
        if pre_inst:
            pre_inst.verify()
    LOG.info("Warming up your component configurations (ie so you won't be prompted later)")
    for component in component_order:
        base_inst = all_instances.get(component)
        if base_inst:
            base_inst.warm_configs()
        pre_inst = prerequisite_instances.get(component)
        if pre_inst:
            pre_inst.warm_configs()
    if action_name in _RC_FILE_MAKE_ACTIONS and not loaded_env:
        _gen_localrc(config, rc_fn)
예제 #6
0
 def _begin_start(self, name, program, args):
     fn_name = SCREEN_TEMPL % (name)
     tracefn = tr.touch_trace(self.trace_dir, fn_name)
     runtrace = tr.Trace(tracefn)
     runtrace.trace(TYPE, RUN_TYPE)
     runtrace.trace(NAME, name)
     runtrace.trace(ARGS, json.dumps(args))
     full_cmd = [program] + list(args)
     session_name = self._get_session()
     inited_screen = False
     if session_name is None:
         inited_screen = True
         self._do_screen_init()
         session_name = self._get_session()
         if session_name is None:
             msg = "After initializing screen with session named [%s], no screen session with that name was found!" % (SESSION_NAME)
             raise excp.StartException(msg)
     runtrace.trace(SESSION_ID, session_name)
     if inited_screen or not sh.isfile(SCREEN_RC):
         rc_gen = ScreenRcGenerator(self)
         rc_contents = rc_gen.create(session_name, self._get_env())
         out_fn = sh.abspth(SCREEN_RC)
         LOG.info("Writing your created screen rc file to [%s]" % (out_fn))
         sh.write_file(out_fn, rc_contents)
     self._do_start(session_name, name, full_cmd)
     return tracefn
예제 #7
0
 def _write_rc_file(self, root_dir):
     writer = env_rc.RcWriter(self.cfg, self.pw_gen, root_dir)
     if not sh.isfile(settings.OSRC_FN):
         LOG.info("Generating a file at %r that will contain your environment settings.", settings.OSRC_FN)
         writer.write(settings.OSRC_FN)
     else:
         LOG.info("Updating a file at %r that contains your environment settings.", settings.OSRC_FN)
         am_upd = writer.update(settings.OSRC_FN)
         LOG.info("Updated %s settings in rc file %r", am_upd, settings.OSRC_FN)
예제 #8
0
 def _write_rc_file(self, root_dir):
     writer = env_rc.RcWriter(self.cfg, self.pw_gen, root_dir)
     if not sh.isfile(settings.OSRC_FN):
         LOG.info("Generating a file at [%s] that will contain your environment settings." % (settings.OSRC_FN))
         writer.write(settings.OSRC_FN)
     else:
         LOG.info("Updating a file at [%s] that contains your environment settings." % (settings.OSRC_FN))
         am_upd = writer.update(settings.OSRC_FN)
         LOG.info("Updated [%s] settings in rc file [%s]" % (am_upd, settings.OSRC_FN))
예제 #9
0
 def _clean_it(self):
     # These environment additions are important
     # in that they eventually affect how this script runs
     env = dict()
     env['ENABLED_SERVICES'] = ",".join(self.desired_subsystems)
     env['BIN_DIR'] = self.bin_dir
     env['VOLUME_NAME_PREFIX'] = self.cfg.getdefaulted('nova', 'volume_name_prefix', DEF_VOL_PREFIX)
     cleaner_fn = sh.joinpths(self.bin_dir, CLEANER_DATA_CONF)
     if sh.isfile(cleaner_fn):
         LOG.info("Cleaning up your system by running nova cleaner script [%s]." % (cleaner_fn))
         cmd = CLEANER_CMD_ROOT + [cleaner_fn]
         sh.execute(*cmd, run_as_root=True, env_overrides=env)
예제 #10
0
def parse_fn(fn):
    if not sh.isfile(fn):
        msg = "No trace found at filename %s" % (fn)
        raise excp.NoTraceException(msg)
    contents = sh.load_file(fn)
    lines = contents.splitlines()
    accum = list()
    for line in lines:
        ep = split_line(line)
        if ep is None:
            continue
        accum.append(tuple(ep))
    return accum
예제 #11
0
 def _parse(self):
     fn = self.trace_fn
     if not sh.isfile(fn):
         msg = "No trace found at filename %s" % (fn)
         raise excp.NoTraceException(msg)
     contents = sh.load_file(fn)
     lines = contents.splitlines()
     accum = list()
     for line in lines:
         ep = self._split_line(line)
         if ep is None:
             continue
         accum.append(tuple(ep))
     return accum
예제 #12
0
 def _clean_it(self):
     # These environment additions are important
     # in that they eventually affect how this script runs
     env = dict()
     env['ENABLED_SERVICES'] = ",".join(self.desired_subsystems)
     env['BIN_DIR'] = self.bin_dir
     env['VOLUME_NAME_PREFIX'] = self.cfg.getdefaulted(
         'nova', 'volume_name_prefix', DEF_VOL_PREFIX)
     cleaner_fn = sh.joinpths(self.bin_dir, CLEANER_DATA_CONF)
     if sh.isfile(cleaner_fn):
         LOG.info(
             "Cleaning up your system by running nova cleaner script %r" %
             (cleaner_fn))
         cmd = CLEANER_CMD_ROOT + [cleaner_fn]
         sh.execute(*cmd, run_as_root=True, env_overrides=env)
예제 #13
0
 def post_start(self):
     tgt_fn = sh.joinpths(self.bin_dir, MANAGE_DATA_CONF)
     if sh.isfile(tgt_fn):
         # If its still there, run it
         # these environment additions are important
         # in that they eventually affect how this script runs
         LOG.info("Waiting %s seconds so that keystone can start up before running first time init." % (self.wait_time))
         sh.sleep(self.wait_time)
         env = dict()
         env['ENABLED_SERVICES'] = ",".join(self.instances.keys())
         env['BIN_DIR'] = self.bin_dir
         setup_cmd = MANAGE_CMD_ROOT + [tgt_fn]
         LOG.info("Running (%s) command to initialize keystone." % (" ".join(setup_cmd)))
         sh.execute(*setup_cmd, env_overrides=env, run_as_root=False)
         LOG.debug("Removing (%s) file since we successfully initialized keystone." % (tgt_fn))
         sh.unlink(tgt_fn)
예제 #14
0
 def _do_upstart_configure(self, app_name, runtime_info):
     (app_pth, _, program_args) = runtime_info
     # TODO FIXME symlinks won't work. Need to copy the files there.
     # https://bugs.launchpad.net/upstart/+bug/665022
     cfg_fn = sh.joinpths(CONF_ROOT, app_name + CONF_EXT)
     if sh.isfile(cfg_fn):
         LOG.info("Upstart config file already exists: %s" % (cfg_fn))
         return
     LOG.debug("Loading upstart template to be used by: %s" % (cfg_fn))
     (_, contents) = utils.load_template('general', UPSTART_CONF_TMPL)
     params = self._get_upstart_conf_params(app_pth, app_name, *program_args)
     adjusted_contents = utils.param_replace(contents, params)
     LOG.debug("Generated up start config for %s: %s" % (app_name, adjusted_contents))
     with sh.Rooted(True):
         sh.write_file(cfg_fn, adjusted_contents)
         sh.chmod(cfg_fn, 0666)
예제 #15
0
 def _setup_network_init(self):
     tgt_fn = sh.joinpths(self.bindir, NET_INIT_CONF)
     if sh.isfile(tgt_fn):
         LOG.info("Creating your nova network to be used with instances.")
         #still there, run it
         #these environment additions are important
         #in that they eventually affect how this script runs
         if utils.service_enabled(settings.QUANTUM, self.instances, False):
             LOG.info("Waiting %s seconds so that quantum can start up before running first time init." % (WAIT_ONLINE_TO))
             time.sleep(WAIT_ONLINE_TO)
         env = dict()
         env['ENABLED_SERVICES'] = ",".join(self.instances.keys())
         setup_cmd = NET_INIT_CMD_ROOT + [tgt_fn]
         LOG.info("Running (%s) command to initialize nova's network." % (" ".join(setup_cmd)))
         sh.execute(*setup_cmd, env_overrides=env, run_as_root=False)
         LOG.debug("Removing (%s) file since we successfully initialized nova's network." % (tgt_fn))
         sh.unlink(tgt_fn)
예제 #16
0
 def _do_upstart_configure(self, app_name, runtime_info):
     (app_pth, _, program_args) = runtime_info
     # TODO FIXME symlinks won't work. Need to copy the files there.
     # https://bugs.launchpad.net/upstart/+bug/665022
     cfg_fn = sh.joinpths(CONF_ROOT, app_name + CONF_EXT)
     if sh.isfile(cfg_fn):
         LOG.debug("Upstart config file already exists: %s" % (cfg_fn))
         return
     LOG.debug("Loading upstart template to be used by: %s" % (cfg_fn))
     (_, contents) = utils.load_template('general', UPSTART_CONF_TMPL)
     params = self._get_upstart_conf_params(app_pth, app_name,
                                            *program_args)
     adjusted_contents = utils.param_replace(contents, params)
     LOG.debug("Generated up start config for %s: %s" %
               (app_name, adjusted_contents))
     with sh.Rooted(True):
         sh.write_file(cfg_fn, adjusted_contents)
         sh.chmod(cfg_fn, 0666)
예제 #17
0
 def post_start(self):
     tgt_fn = sh.joinpths(self.bin_dir, MANAGE_DATA_CONF)
     if sh.isfile(tgt_fn):
         # If its still there, run it
         # these environment additions are important
         # in that they eventually affect how this script runs
         LOG.info(
             "Waiting %s seconds so that keystone can start up before running first time init."
             % (self.wait_time))
         sh.sleep(self.wait_time)
         env = dict()
         env['ENABLED_SERVICES'] = ",".join(self.instances.keys())
         env['BIN_DIR'] = self.bin_dir
         setup_cmd = MANAGE_CMD_ROOT + [tgt_fn]
         LOG.info("Running (%s) command to initialize keystone." %
                  (" ".join(setup_cmd)))
         sh.execute(*setup_cmd, env_overrides=env, run_as_root=False)
         LOG.debug(
             "Removing (%s) file since we successfully initialized keystone."
             % (tgt_fn))
         sh.unlink(tgt_fn)
예제 #18
0
 def _setup_network_init(self):
     tgt_fn = sh.joinpths(self.bin_dir, NET_INIT_CONF)
     if sh.isfile(tgt_fn):
         LOG.info("Creating your nova network to be used with instances.")
         # If still there, run it
         # these environment additions are important
         # in that they eventually affect how this script runs
         if 'quantum' in self.options:
             LOG.info(
                 "Waiting %s seconds so that quantum can start up before running first time init."
                 % (self.wait_time))
             sh.sleep(self.wait_time)
         env = dict()
         env['ENABLED_SERVICES'] = ",".join(self.instances.keys())
         setup_cmd = NET_INIT_CMD_ROOT + [tgt_fn]
         LOG.info("Running (%s) command to initialize nova's network." %
                  (" ".join(setup_cmd)))
         sh.execute(*setup_cmd, env_overrides=env, run_as_root=False)
         LOG.debug(
             "Removing (%s) file since we successfully initialized nova's network."
             % (tgt_fn))
         sh.unlink(tgt_fn)