コード例 #1
0
ファイル: launch.py プロジェクト: stutiredboy/scheduler
def stop_process(options):
    """Stop the synergy-data daemons"""
    import logging
    from supervisor import supervisor_helper as helper
    from model.box_configuration_entry import BoxConfigurationEntry

    if options.app is not None and options.app != process_context.PROCESS_SUPERVISOR:
        # mark individual process for termination
        # real work is performed by Supervisor
        if options.app not in PROCESSES_FOR_XXL:
            sys.stdout.write("ERROR: requested process must be withing allowed list of: %r \n" % PROCESSES_FOR_XXL)
            sys.exit(1)

        box_id = helper.get_box_id(logging)
        box_configuration = helper.retrieve_configuration(logging, box_id)
        box_configuration.set_process_state(options.app, BoxConfigurationEntry.STATE_OFF)
        helper.update_configuration(logging, box_configuration)
    else:
        # stop Supervisor
        try:
            pid = _get_supervisor_pid()
            if pid is None:
                message = "ERROR: Can not find Supervisor pidfile. Supervisor not running?\n"
                sys.stderr.write(message)
                sys.exit(1)

            # Try killing the daemon process
            sys.stdout.write("INFO: Killing %r \n" % process_context.PROCESS_SUPERVISOR)
            while 1:
                os.kill(pid, signal.SIGTERM)
                time.sleep(0.1)
            ProcessContext.remove_pid_file(process_context.PROCESS_SUPERVISOR)
        except Exception as e:
            sys.stderr.write("Exception on killing %s : %s \n" % (process_context.PROCESS_SUPERVISOR, str(e)))
            sys.exit(0)
コード例 #2
0
ファイル: process_helper.py プロジェクト: NMerch/scheduler
def kill_process(process_name):
    """ method is called to kill a running process """
    try:
        sys.stdout.write('killing: %s { \n' % process_name)
        pid = get_process_pid(process_name)
        if pid is not None and psutil.pid_exists(int(pid)):
            p = psutil.Process(pid)
            p.kill()
            p.wait()
            ProcessContext.remove_pid_file(process_name)
    except Exception as e:
        sys.stderr.write('Exception on killing %s : %s \n' % (process_name, str(e)))
    finally:
        sys.stdout.write('}')
コード例 #3
0
def kill_process(process_name):
    """ method is called to kill a running process """
    try:
        sys.stdout.write('killing: {0} {{ \n'.format(process_name))
        pid = get_process_pid(process_name)
        if pid is not None and psutil.pid_exists(int(pid)):
            p = psutil.Process(pid)
            p.kill()
            p.wait()
            ProcessContext.remove_pid_file(process_name)
    except Exception as e:
        sys.stderr.write('Exception on killing {0} : {1} \n'.format(
            process_name, e))
    finally:
        sys.stdout.write('}')
コード例 #4
0
 def _kill_process(self, box_config, process_name):
     """ method is called to kill a running process """
     try:
         self.logger.info('kill: %s {' % process_name)
         pid = box_config.get_process_pid(process_name)
         if pid is not None and psutil.pid_exists(int(pid)):
             p = psutil.Process(pid)
             p.kill()
             p.wait()
             box_config.set_process_pid(process_name, None)
             self.bc_dao.update(box_config)
             ProcessContext.remove_pid_file(process_name)
     except Exception:
         self.logger.error('Exception on killing: %s' % process_name, exc_info=True)
     finally:
         self.logger.info('}')
コード例 #5
0
 def __del__(self):
     """ removes PID file """
     ProcessContext.remove_pid_file(self.process_name, process_id=self.process_id)
     self.logger.info('Shutdown {0}'.format(self.process_name))
コード例 #6
0
 def __del__(self):
     """ removes PID file """
     ProcessContext.remove_pid_file(self.process_name)
     self.logger.info('Shutdown %s' % self.process_name)
コード例 #7
0
 def __del__(self):
     """ removes PID file """
     ProcessContext.remove_pid_file(self.process_name,
                                    process_id=self.process_id)
     self.logger.info('Shutdown {0}'.format(self.process_name))