def start(name, prio, path, args): prio_map = {'sys_high': 99, 'sys_medium': 93, 'sys_low': 92, 'app': 91} prio = prio_map[prio] if args: path += ' ' + args if validate(name): print green('note:') + ' %s is already running' % name else: print 'starting', blue(name), '...', ps = subprocess.Popen(path.split(' '), shell = False, stdout = subprocess.PIPE, stderr = subprocess.PIPE) ps.stdout.close() ps.stderr.close() ps.wait() prio_fail = False if ps.returncode != 0: print red('[ERROR: service quit with code ' + str(ps.returncode) + ']') else: time.sleep(5) pid = validate(name) if not pid: raise Exception('process terminated') try: sched_set_prio(pid, prio) except: print red('warning:') + ' could not set process priority' print green('[OK]')
def start(name, prio, path, args): prio_map = {'sys_high': 99, 'sys_medium': 50, 'sys_low': 30, 'app': 0} prio = prio_map[prio] if args: path += ' ' + args if validate(name): print green('note:') + ' %s is already running' % name else: print 'starting', blue(name), '...', ps = subprocess.Popen(path.split(' '), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) ps.stdout.close() ps.stderr.close() ps.wait() prio_fail = False if ps.returncode != 0: print red('[ERROR: service quit with code ' + str(ps.returncode) + ']') else: for _ in range(30): time.sleep(0.1) try: pid = validate(name) except: pass if not pid: raise Exception('process terminated') try: sched_set_prio(pid, prio) except: print red('warning:') + ' could not set process priority' print green('[OK]')
def stop(name): print 'stopping', blue(name), '...', pid = validate(name) if pid: kill(pid) while validate(name): time.sleep(1.0) print green('[OK]') else: print red('[ERROR: no such process]')
def start(name, path, args): if args: path += ' ' + args if validate(name): print green('note:') + ' %s is already running' % name else: print 'starting', blue(name), '...', try: print path, ps = subprocess.Popen(path.split(' '), shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) ps.stdout.close() ps.stderr.close() ps.wait() if ps.returncode != 0: print red('[ERROR: service quit with code ' + str(ps.returncode) + ']') else: print green('[OK]') except Exception as e: print red('[ERROR]: ' + str(e))
import argparse from processes import start, stop, validate args = parse_args() config = read_config() if args == 'show': # show list and status of services max_name_len = 0 for name in config: name_len = len(name) if name_len > max_name_len: max_name_len = name_len for name, (path, _, _) in config.items(): skip = ' ' * (max_name_len - len(name)) pid = validate(name) if pid: ex_str = green('running [%d]' % pid) else: ex_str = red('not running') try: if len(config[name][1]) > 0: ex_str += '\t(deps: ' + ', '.join(config[name][1]) + ')' except: pass print '%s:%s %s' % (blue(name), skip, ex_str) elif args[0] in ['start', 'stop']: try: name = args[1] data = config[name] if args[0] == 'start': names = start_order(name)