[Update] 修改jms启动脚本,stop时增加超时检测

pull/3366/head
ibuler 5 years ago
parent 87deb18791
commit 7cf617c3fc

23
jms

@ -65,6 +65,7 @@ logging.basicConfig(
EXIT_EVENT = threading.Event() EXIT_EVENT = threading.Event()
LOCK = threading.Lock() LOCK = threading.Lock()
files_preserve = [] files_preserve = []
STOP_TIMEOUT = 10
logger = logging.getLogger() logger = logging.getLogger()
@ -120,7 +121,7 @@ def check_pid(pid):
def get_pid_file_path(s): def get_pid_file_path(s):
return os.path.join('/tmp', '{}.pid'.format(s)) return os.path.join(TMP_DIR, '{}.pid'.format(s))
def get_log_file_path(s): def get_log_file_path(s):
@ -433,9 +434,19 @@ def stop_service(srv, sig=15):
if not is_running(s): if not is_running(s):
show_service_status(s) show_service_status(s)
continue continue
logging.info("Stop service: {}".format(s)) print("Stop service: {}".format(s), end='')
pid = get_pid(s) pid = get_pid(s)
os.kill(pid, sig) os.kill(pid, sig)
for i in range(STOP_TIMEOUT):
if i == STOP_TIMEOUT - 1:
print("\033[31m Error\033[0m")
if not is_running(s):
print("\033[32m Ok\033[0m")
break
else:
time.sleep(1)
continue
with LOCK: with LOCK:
processes.pop(s, None) processes.pop(s, None)
@ -472,9 +483,9 @@ def show_service_status(s):
for ns in services_set: for ns in services_set:
if is_running(ns): if is_running(ns):
pid = get_pid(ns) pid = get_pid(ns)
logging.info("{} is running: {}".format(ns, pid)) print("{} is running: {}".format(ns, pid))
else: else:
logging.info("{} is stopped".format(ns)) print("{} is stopped".format(ns))
if __name__ == '__main__': if __name__ == '__main__':
@ -499,6 +510,7 @@ if __name__ == '__main__':
) )
parser.add_argument('-d', '--daemon', nargs="?", const=1) parser.add_argument('-d', '--daemon', nargs="?", const=1)
parser.add_argument('-w', '--worker', type=int, nargs="?", const=4) parser.add_argument('-w', '--worker', type=int, nargs="?", const=4)
parser.add_argument('-f', '--force', nargs="?", const=1)
args = parser.parse_args() args = parser.parse_args()
if args.daemon: if args.daemon:
DAEMON = True DAEMON = True
@ -513,6 +525,9 @@ if __name__ == '__main__':
start_services_and_watch(srv) start_services_and_watch(srv)
os._exit(0) os._exit(0)
elif action == "stop": elif action == "stop":
if args.force:
stop_service_force(srv)
else:
stop_service(srv) stop_service(srv)
elif action == "restart": elif action == "restart":
DAEMON = True DAEMON = True

Loading…
Cancel
Save