Example #1
0
 def start(self):
     """ reading box configurations and starting timers to start/monitor/kill processes """
     try:
         box_configuration = helper.retrieve_configuration(self.logger, self.box_id)
         process_list = box_configuration.get_process_list()
         for process in process_list:
             params = [process]
             handler = RepeatTimer(INTERVAL, self.manage_process, args=params)
             self.thread_handlers[process] = handler
             handler.start()
             self.logger.info('Started Supervisor for %s, triggering every %d seconds' % (process, INTERVAL))
     except LookupError as e:
         self.logger.error('Supervisor failed to start because of: %r' % e)
Example #2
0
    def manage_process(self, *args):
        """ reads box configuration and start/kill processes. performs process monitoring """
        process_name = args[0]
        try:
            self.lock.acquire()

            box_configuration = helper.retrieve_configuration(self.logger, self.box_id)
            state = box_configuration.get_process_state(process_name)
            pid = box_configuration.get_process_pid(process_name)
            if state == BoxConfigurationEntry.STATE_OFF:
                if pid is not None:
                    self._kill_process(box_configuration, process_name)
                return

            if pid is None or not psutil.pid_exists(int(pid)):
                self._start_process(box_configuration, process_name)
            elif pid is not None and psutil.pid_exists(int(pid)):
                self._poll_process(box_configuration, process_name)
        except Exception as e:
            self.logger.error('Exception: %s' % str(e), exc_info=True)
        finally:
            self.lock.release()