Beispiel #1
0
 def _config_adjust(self, contents, fn):
     lines = contents.splitlines()
     for line in lines:
         cleaned = line.strip()
         if(len(cleaned) == 0 or
             cleaned[0] == '#' or cleaned[0] == '['):
             #not useful to examine these
             continue
         pieces = cleaned.split("=", 1)
         if(len(pieces) != 2):
             continue
         key = pieces[0].strip()
         val = pieces[1].strip()
         if(len(key) == 0 or len(val) == 0):
             continue
         #now we take special actions
         if(key == 'log_file'):
             # Ensure that we can write to the log file
             dirname = os.path.dirname(val)
             if(len(dirname)):
                 dirsmade = mkdirslist(dirname)
                 # This trace is used to remove the dirs created
                 self.tracewriter.dir_made(*dirsmade)
             # Destroy then recreate it
             unlink(val)
             touch_file(val)
             self.tracewriter.file_touched(val)
     return contents
Beispiel #2
0
 def _config_adjust(self, contents, fn):
     lines = contents.splitlines()
     for line in lines:
         cleaned = line.strip()
         if (len(cleaned) == 0 or cleaned[0] == '#' or cleaned[0] == '['):
             #not useful to examine these
             continue
         pieces = cleaned.split("=", 1)
         if (len(pieces) != 2):
             continue
         key = pieces[0].strip()
         val = pieces[1].strip()
         if (len(key) == 0 or len(val) == 0):
             continue
         #now we take special actions
         if (key == 'log_file'):
             # Ensure that we can write to the log file
             dirname = os.path.dirname(val)
             if (len(dirname)):
                 dirsmade = mkdirslist(dirname)
                 # This trace is used to remove the dirs created
                 self.tracewriter.dir_made(*dirsmade)
             # Destroy then recreate it
             unlink(val)
             touch_file(val)
             self.tracewriter.file_touched(val)
     return contents
Beispiel #3
0
 def stop(self):
     #ensure it was installed
     if(not self._was_installed()):
         msg = "Can not stop %s since it was not installed" % (self.component_name)
         raise StopException(msg)
     #we can only stop what has a started trace
     start_traces = self.starttracereader.apps_started()
     killedam = 0
     for mp in start_traces:
         #extract the apps name and where its trace is
         fn = mp.get('trace_fn')
         name = mp.get('name')
         #missing some key info, skip it
         if(fn == None or name == None):
             continue
         #figure out which class will stop it
         contents = parse_fn(fn)
         killcls = None
         for (cmd, action) in contents:
             if(cmd == Runner.RUN_TYPE):
                 killcls = self._getstoppercls(action)
                 break
         #did we find a class that can do it?
         if(killcls):
             #we can try to stop it
             LOG.info("Stopping %s" % (name))
             #create an instance of the killer class and attempt to stop
             killer = killcls()
             killer.stop(name, trace_dir=self.tracedir)
             killedam += 1
     #if we got rid of them all get rid of the trace
     if(killedam == len(start_traces)):
         fn = self.starttracereader.trace_fn
         LOG.info("Deleting trace file %s" % (fn))
         unlink(fn)
Beispiel #4
0
 def _uninstall_touched_files(self):
     filestouched = self.tracereader.files_touched()
     if (len(filestouched)):
         LOG.info("Removing %s touched files" % (len(filestouched)))
         for fn in filestouched:
             if (len(fn)):
                 unlink(fn)
                 LOG.info("Removed %s" % (fn))
Beispiel #5
0
 def _unconfigure_files(self):
     cfgfiles = self.tracereader.files_configured()
     if (len(cfgfiles)):
         LOG.info("Removing %s configuration files" % (len(cfgfiles)))
         for fn in cfgfiles:
             if (len(fn)):
                 unlink(fn)
                 LOG.info("Removed %s" % (fn))
Beispiel #6
0
 def _uninstall_touched_files(self):
     filestouched = self.tracereader.files_touched()
     if(len(filestouched)):
         LOG.info("Removing %s touched files" % (len(filestouched)))
         for fn in filestouched:
             if(len(fn)):
                 unlink(fn)
                 LOG.info("Removed %s" % (fn))
Beispiel #7
0
 def _unconfigure_files(self):
     cfgfiles = self.tracereader.files_configured()
     if(len(cfgfiles)):
         LOG.info("Removing %s configuration files" % (len(cfgfiles)))
         for fn in cfgfiles:
             if(len(fn)):
                 unlink(fn)
                 LOG.info("Removed %s" % (fn))
Beispiel #8
0
 def _config_adjust(self, contents, fn):
     lines = contents.splitlines()
     for line in lines:
         cleaned = line.strip()
         if (len(cleaned) == 0 or cleaned[0] == '#' or cleaned[0] == '['):
             #not useful to examine these
             continue
         pieces = cleaned.split("=", 1)
         if (len(pieces) != 2):
             continue
         key = pieces[0].strip()
         val = pieces[1].strip()
         if (len(key) == 0 or len(val) == 0):
             continue
         #now we take special actions
         if (key == 'filesystem_store_datadir'):
             #delete existing images
             deldir(val)
             #recreate the image directory
             dirsmade = mkdirslist(val)
             self.tracewriter.dir_made(*dirsmade)
         elif (key == 'log_file'):
             #ensure that we can write to the log file
             dirname = os.path.dirname(val)
             if (len(dirname)):
                 dirsmade = mkdirslist(dirname)
                 #this trace is used to remove the dirs created
                 self.tracewriter.dir_made(*dirsmade)
             #destroy then recreate it (the log file)
             unlink(val)
             touch_file(val)
             self.tracewriter.file_touched(val)
         elif (key == 'image_cache_datadir'):
             #destroy then recreate the image cache directory
             deldir(val)
             dirsmade = mkdirslist(val)
             #this trace is used to remove the dirs created
             self.tracewriter.dir_made(*dirsmade)
         elif (key == 'scrubber_datadir'):
             #destroy then recreate the scrubber data directory
             deldir(val)
             dirsmade = mkdirslist(val)
             #this trace is used to remove the dirs created
             self.tracewriter.dir_made(*dirsmade)
     return contents
Beispiel #9
0
 def _config_adjust(self, contents, fn):
     lines = contents.splitlines()
     for line in lines:
         cleaned = line.strip()
         if len(cleaned) == 0 or cleaned[0] == "#" or cleaned[0] == "[":
             # not useful to examine these
             continue
         pieces = cleaned.split("=", 1)
         if len(pieces) != 2:
             continue
         key = pieces[0].strip()
         val = pieces[1].strip()
         if len(key) == 0 or len(val) == 0:
             continue
         # now we take special actions
         if key == "filesystem_store_datadir":
             # delete existing images
             deldir(val)
             # recreate the image directory
             dirsmade = mkdirslist(val)
             self.tracewriter.dir_made(*dirsmade)
         elif key == "log_file":
             # ensure that we can write to the log file
             dirname = os.path.dirname(val)
             if len(dirname):
                 dirsmade = mkdirslist(dirname)
                 # this trace is used to remove the dirs created
                 self.tracewriter.dir_made(*dirsmade)
             # destroy then recreate it (the log file)
             unlink(val)
             touch_file(val)
             self.tracewriter.file_touched(val)
         elif key == "image_cache_datadir":
             # destroy then recreate the image cache directory
             deldir(val)
             dirsmade = mkdirslist(val)
             # this trace is used to remove the dirs created
             self.tracewriter.dir_made(*dirsmade)
         elif key == "scrubber_datadir":
             # destroy then recreate the scrubber data directory
             deldir(val)
             dirsmade = mkdirslist(val)
             # this trace is used to remove the dirs created
             self.tracewriter.dir_made(*dirsmade)
     return contents
Beispiel #10
0
 def stop(self):
     #ensure it was installed
     if (not self._was_installed()):
         msg = "Can not stop %s since it was not installed" % (
             self.component_name)
         raise StopException(msg)
     #we can only stop what has a started trace
     start_traces = self.starttracereader.apps_started()
     killedam = 0
     for mp in start_traces:
         #extract the apps name and where its trace is
         fn = mp.get('trace_fn')
         name = mp.get('name')
         #missing some key info, skip it
         if (fn == None or name == None):
             continue
         #figure out which class will stop it
         contents = parse_fn(fn)
         killcls = None
         for (cmd, action) in contents:
             if (cmd == Runner.RUN_TYPE):
                 killcls = self._getstoppercls(action)
                 break
         #did we find a class that can do it?
         if (killcls):
             #we can try to stop it
             LOG.info("Stopping %s" % (name))
             #create an instance of the killer class and attempt to stop
             killer = killcls()
             killer.stop(name, trace_dir=self.tracedir)
             killedam += 1
     #if we got rid of them all get rid of the trace
     if (killedam == len(start_traces)):
         fn = self.starttracereader.trace_fn
         LOG.info("Deleting trace file %s" % (fn))
         unlink(fn)
Beispiel #11
0
 def stop(self, name, *args, **kargs):
     rootdir = kargs.get("trace_dir")
     pidfile = joinpths(rootdir, name + ".pid")
     stderr = joinpths(rootdir, name + ".stderr")
     stdout = joinpths(rootdir, name + ".stdout")
     tfname = Trace.trace_fn(rootdir, name)
     if(isfile(pidfile) and isfile(tfname)):
         pid = int(load_file(pidfile).strip())
         killed = False
         lastmsg = ""
         attempts = 1
         for attempt in range(0, MAX_KILL_TRY):
             try:
                 os.kill(pid, signal.SIGKILL)
                 attempts += 1
             except OSError as (ec, msg):
                 if(ec == errno.ESRCH):
                     killed = True
                     break
                 else:
                     lastmsg = msg
                     time.sleep(SLEEP_TIME)
         #trash the files
         if(killed):
             LOG.info("Killed pid %s in %s attempts" % (str(pid), str(attempts)))
             LOG.info("Removing pid file %s" % (pidfile))
             unlink(pidfile)
             LOG.info("Removing stderr file %s" % (stderr))
             unlink(stderr)
             LOG.info("Removing stdout file %s" % (stdout))
             unlink(stdout)
             LOG.info("Removing %s trace file %s" % (name, tfname))
             unlink(tfname)
         else:
             msg = "Could not stop program named %s after %s attempts - [%s]" % (name, MAX_KILL_TRY, lastmsg)
             raise StopException(msg)