def stop(self, app_name):
     trace_dir = self.runtime.get_option('trace_dir')
     if not sh.isdir(trace_dir):
         msg = "No trace directory found from which to stop: %s" % (app_name)
         raise excp.StopException(msg)
     with sh.Rooted(True):
         fn_name = FORK_TEMPL % (app_name)
         (pid_file, stderr_fn, stdout_fn) = self._form_file_names(fn_name)
         pid = self._extract_pid(pid_file)
         if not pid:
             msg = "Could not extract a valid pid from %s" % (pid_file)
             raise excp.StopException(msg)
         (killed, attempts) = sh.kill(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 %r" % (stderr_fn))
             sh.unlink(stderr_fn)
             LOG.debug("Removing stdout file %r" % (stdout_fn))
             sh.unlink(stdout_fn)
             trace_fn = tr.trace_fn(trace_dir, fn_name)
             if sh.isfile(trace_fn):
                 LOG.debug("Removing %r trace file %r" % (app_name, trace_fn))
                 sh.unlink(trace_fn)
         else:
             msg = "Could not stop %r after %s attempts" % (app_name, attempts)
             raise excp.StopException(msg)
 def stop(self, app_name):
     fn_name = UPSTART_TEMPL % (app_name)
     trace_fn = tr.trace_fn(self.runtime.get_option('trace_dir'), fn_name)
     # Emit the start, keep track and only do one per component name
     component_event = self.name + STOP_EVENT_SUFFIX
     if component_event in self.events:
         LOG.debug("Already emitted event: %r" % (component_event))
     else:
         LOG.debug("About to emit event: %r" % (component_event))
         cmd = EMIT_BASE_CMD + [component_event]
         sh.execute(*cmd, run_as_root=True)
         self.events.add(component_event)
     sh.unlink(trace_fn)
 def _start(self, app_name, program, program_args):
     run_trace = tr.TraceWriter(tr.trace_fn(self.runtime.get_option('trace_dir'), UPSTART_TEMPL % (app_name)))
     run_trace.trace(NAME, app_name)
     run_trace.trace(ARGS, json.dumps(program_args))
     # Emit the start, keep track and only do one per component name
     component_event = self.name + START_EVENT_SUFFIX
     if component_event in self.events:
         LOG.debug("Already emitted event: %r" % (component_event))
     else:
         LOG.debug("About to emit event: %r" % (component_event))
         cmd = EMIT_BASE_CMD + [component_event]
         sh.execute(*cmd, run_as_root=True)
         self.events.add(component_event)
     return run_trace.filename()
 def _begin_start(self, name, program, args):
     run_trace = tr.TraceWriter(tr.trace_fn(self.runtime.get_option('trace_dir'), SCREEN_TEMPL % (name)))
     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 %r, 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 %r" % (out_fn))
         sh.write_file(out_fn, rc_contents)
     self._do_start(session_name, name, full_cmd)
     return run_trace.filename()
 def _get_trace_files(self):
     trace_dir = self.get_option('trace_dir')
     return {
         'install': tr.trace_fn(trace_dir, "install"),
         'start': tr.trace_fn(trace_dir, "start"),
     }
 def _do_trace(self, fn, kvs):
     trace_dir = self.runtime.get_option('trace_dir')
     run_trace = tr.TraceWriter(tr.trace_fn(trace_dir, fn))
     for (k, v) in kvs.items():
         run_trace.trace(k, v)
     return run_trace.filename()
 def stop(self, app_name):
     trace_fn = tr.trace_fn(self.runtime.get_option('trace_dir'), SCREEN_TEMPL % (app_name))
     session_id = self._find_session(app_name, trace_fn)
     self._do_stop(app_name, session_id)
     sh.unlink(trace_fn)