Esempio n. 1
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
 def _install_python_setups(self):
     pydirs = self._get_python_directories()
     if pydirs:
         LOG.info("Setting up %s python directories (%s)" % (len(pydirs), pydirs))
         for (name, wkdir) in pydirs.items():
             working_dir = wkdir or self.appdir
             self.tracewriter.make_dir(working_dir)
             record_fn = tr.touch_trace(self.tracedir, self._format_trace_name(name))
             #do this before write just incase it craps out half way through
             self.tracewriter.file_touched(record_fn)
             self.tracewriter.py_install(name, record_fn, working_dir)
             #now actually do it
             (stdout, stderr) = sh.execute(*PY_INSTALL, cwd=working_dir, run_as_root=True)
             sh.write_file(record_fn, self._format_stderr_out(stderr, stdout))
Esempio n. 3
0
 def start(self, name, program, *args, **kargs):
     tracedir = kargs.get("trace_dir")
     appdir = kargs.get("app_dir")
     fn_name = FORK_TEMPL % (name)
     (pidfile, stderrfn, stdoutfn) = self._form_file_names(tracedir, fn_name)
     tracefn = tr.touch_trace(tracedir, fn_name)
     runtrace = tr.Trace(tracefn)
     runtrace.trace(TYPE, RUN_TYPE)
     runtrace.trace(PID_FN, pidfile)
     runtrace.trace(STDERR_FN, stderrfn)
     runtrace.trace(STDOUT_FN, stdoutfn)
     runtrace.trace(ARGS, json.dumps(args))
     LOG.info("Forking [%s] by running command [%s]" % (name, program))
     self._fork_start(program, appdir, pidfile, stdoutfn, stderrfn, *args)
     return tracefn
Esempio n. 4
0
 def _start(self, app_name, program, program_args):
     fn_name = UPSTART_TEMPL % (app_name)
     tracefn = tr.touch_trace(self.trace_dir, fn_name)
     runtrace = tr.Trace(tracefn)
     runtrace.trace(TYPE, RUN_TYPE)
     runtrace.trace(NAME, app_name)
     runtrace.trace(ARGS, json.dumps(program_args))
     # Emit the start, keep track and only do one per component name
     component_event = self.component_name + START_EVENT_SUFFIX
     if component_event in self.events:
         LOG.debug("Already emitted event: %s" % (component_event))
     else:
         LOG.info("About to emit event: %s" % (component_event))
         cmd = EMIT_BASE_CMD + [component_event]
         sh.execute(*cmd, run_as_root=True)
         self.events.add(component_event)
     return tracefn
Esempio n. 5
0
 def _install_python_setups(self):
     #setup any python directories
     pydirs = self._get_python_directories()
     if pydirs:
         actual_dirs = list()
         for pydir_info in pydirs:
             working_dir = pydir_info.get('work_dir', self.appdir)
             actual_dirs.append(working_dir)
         LOG.info("Setting up %s python directories (%s)" % (len(pydirs), ", ".join(actual_dirs)))
         self.tracewriter.make_dir(self.tracedir)
         for pydir_info in pydirs:
             name = pydir_info.get("name")
             if not name:
                 #TODO should we raise an exception here?
                 continue
             working_dir = pydir_info.get('work_dir', self.appdir)
             record_fn = tr.touch_trace(self.tracedir, self._format_trace_name(name))
             self.tracewriter.file_touched(record_fn)
             (stdout, stderr) = sh.execute(*PY_INSTALL, cwd=working_dir, run_as_root=True)
             sh.write_file(record_fn, self._format_stderr_out(stderr, stdout))
             self.tracewriter.py_install(name, record_fn, working_dir)
Esempio n. 6
0
 def _do_trace(self, fn, kvs):
     tracefn = tr.touch_trace(self.trace_dir, fn)
     runtrace = tr.Trace(tracefn)
     for (k, v) in kvs.items():
         runtrace.trace(k, v)
     return tracefn