Beispiel #1
0
 def run(self, file, default_size, remove_lines):
     size = default_size * 1000
     if os.path.isfile(file):
         if os.path.getsize(file) >= size:
             with open(file, 'r') as f:
                 lines = f.readlines()
             if len(lines) < remove_lines:
                 ApiLogging.critical(
                     "the specific number of lines is greater than number of desired {0} file lines".format(file))
             with open(file, 'w') as f:
                 f.writelines(lines[remove_lines:])
     else:
         ApiLogging.critical("the {0} is not existed".format(file))
Beispiel #2
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))
Beispiel #3
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')
Beispiel #4
0
        size = default_size * 1000
        if os.path.isfile(file):
            if os.path.getsize(file) >= size:
                with open(file, 'r') as f:
                    lines = f.readlines()
                if len(lines) < remove_lines:
                    ApiLogging.critical(
                        "the specific number of lines is greater than number of desired {0} file lines".format(file))
                with open(file, 'w') as f:
                    f.writelines(lines[remove_lines:])
        else:
            ApiLogging.critical("the {0} is not existed".format(file))


if __name__ == '__main__':
    if sys.argv.pop(-1) != "0X105070":
        try:
            ApiLogging.info(type(sys.argv.pop(-1)))
        except IndexError:
            ApiLogging.critical('missing token parameter')
            sys.exit(0)
        ApiLogging.critical('wrong token parameter')
        sys.exit(0)
    # app = QCoreApplication(sys.argv)
    while True:
        time.sleep(30)
        for file in os.listdir(BASE_APP_PATH + '/logs'):
            p = ProcessLog()
            p.run(BASE_APP_PATH + '/logs/' + file, default_size=DEFAULT_SIZE_LOG, remove_lines=REMOVE_LINES_LOG)
    # sys.exit(app.exec_())
Beispiel #5
0
    f.write('debug_mode = ' + str(debug_mode))


if not os.path.exists(BASE_APP_PATH + '/logs'):
    os.mkdir(BASE_APP_PATH + '/logs')
args = vars(arg.parse_args())

action = args.get('action')
p = args.get('process_name', None)
set_mode(debug_mode)

if action == 'status':
    status()
elif action == 'start':
    if p:
        start(p)
    else:
        start()
elif action == 'stop':
    if p:
        stop(p)
    else:
        stop()
elif action == 'restart':
    stop()
    ApiLogging.critical('Start all process after one second...')
    sleep(3)
    start()
else:
    # print('action is not found!')
    pass