示例#1
0
def stop(process_name=None):
    if process_name and __get_process(process_name) is not None:
        process = __get_process(process_name)
        pids = find_pid(process.get('token'))
        if not pids:
            ApiLogging.warning(process_name + ' is not running!', True)
        else:
            for pid in pids:
                ApiLogging.info(process_name + ' stopped successful!', True)
                proc = psutil.Process(pid)
                if proc.is_running():
                    proc.kill()
    else:
        for process in constants.APP_PROCESSES:
            pids = find_pid(process.get('token'))
            if not pids:
                ApiLogging.warning(
                    process.get('name') + ' is not running!', True)
            else:
                for pid in pids:
                    ApiLogging.info(
                        process.get('name') + ' stopped successful!', True)
                    proc = psutil.Process(pid)
                    if proc.is_running():
                        proc.kill()
    try:
        __cleanup()
    except Exception as e:
        # print("cleanup exception: ", e)
        pass
示例#2
0
def __cleanup():
    # terminate all xvfb process
    pids = find_pid('Xvfb')
    for pid in pids:
        proc = psutil.Process(pid)
        if proc.is_running():
            proc.kill()
示例#3
0
def status():
    for process in constants.APP_PROCESSES:
        pids = find_pid(process.get('token'))
        if not pids:
            ApiLogging.error([process.get('name'), pids], True)
        else:
            ApiLogging.info([process.get('name'), pids], True)
示例#4
0
def start(process_name=None):
    requirements = check_requirements()
    if requirements is not True:
        for requirement in requirements:
            ApiLogging.critical(requirement, True)
        return
    if process_name and __get_process(process_name) is not None:
        process = __get_process(process_name)
        pids = find_pid(process.get('token'))
        if pids:
            ApiLogging.warning(str(len(pids)) + ' instance(s) of this process already running!', True)
        else:
            __run(process_name, 'start')
    else:
        for process in constants.APP_PROCESSES:
            if find_pid(process.get('token')):
                ApiLogging.warning(process.get('name') + ' is already running!', True)
            else:
                __run(process.get('name'), 'start')
示例#5
0
 def send_signal():
     pids = []
     for process_name in constants.APP_PROCESSES:
         if process_name.get('name') == 'process_sync.py':
             pids = find_pid(process_name.get('token'))
     if len(pids) > 1:
         ApiLogging.warning('Too many sync process running')
     elif len(pids) == 1:
         p = psutil.Process(pids[0])
         p.send_signal(signal.SIGUSR1)
示例#6
0
 def send_signal(process_names):
     try:
         for name in process_names:
             pids = []
             for process_name in constants.APP_PROCESSES:
                 if process_name.get('name') == name:
                     pids = find_pid(process_name.get('token'))
             if len(pids) > 1:
                 ApiLogging.warning('Too many ' + str(name) +
                                    ' process running')
             elif len(pids) == 1:
                 p = psutil.Process(pids[0])
                 ApiLogging.info('process name: ' + str(pids[0]))
                 p.send_signal(signal.SIGUSR1)
     except Exception as e:
         ApiLogging.critical('broadcast signal exception: ' + str(e))
示例#7
0
def check_requirements():
    error_message = []
    postgres = find_pid('postgresql')
    if not postgres:
        error_message.append('postgresql service required, but not running!')
    return True if not error_message else error_message
示例#8
0
from components.utils import find_pid

find_pid('xvfb')