From 7cf617c3fc73ed8ccfc5c4e94f5221c8bb26a4f9 Mon Sep 17 00:00:00 2001 From: ibuler Date: Tue, 22 Oct 2019 16:09:21 +0800 Subject: [PATCH] =?UTF-8?q?[Update]=20=E4=BF=AE=E6=94=B9jms=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E8=84=9A=E6=9C=AC=EF=BC=8Cstop=E6=97=B6=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0=E8=B6=85=E6=97=B6=E6=A3=80=E6=B5=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jms | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/jms b/jms index 1affac1d2..6331227fa 100755 --- a/jms +++ b/jms @@ -65,6 +65,7 @@ logging.basicConfig( EXIT_EVENT = threading.Event() LOCK = threading.Lock() files_preserve = [] +STOP_TIMEOUT = 10 logger = logging.getLogger() @@ -120,7 +121,7 @@ def check_pid(pid): 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): @@ -433,9 +434,19 @@ def stop_service(srv, sig=15): if not is_running(s): show_service_status(s) continue - logging.info("Stop service: {}".format(s)) + print("Stop service: {}".format(s), end='') pid = get_pid(s) 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: processes.pop(s, None) @@ -472,9 +483,9 @@ def show_service_status(s): for ns in services_set: if is_running(ns): pid = get_pid(ns) - logging.info("{} is running: {}".format(ns, pid)) + print("{} is running: {}".format(ns, pid)) else: - logging.info("{} is stopped".format(ns)) + print("{} is stopped".format(ns)) if __name__ == '__main__': @@ -499,6 +510,7 @@ if __name__ == '__main__': ) parser.add_argument('-d', '--daemon', nargs="?", const=1) parser.add_argument('-w', '--worker', type=int, nargs="?", const=4) + parser.add_argument('-f', '--force', nargs="?", const=1) args = parser.parse_args() if args.daemon: DAEMON = True @@ -513,7 +525,10 @@ if __name__ == '__main__': start_services_and_watch(srv) os._exit(0) elif action == "stop": - stop_service(srv) + if args.force: + stop_service_force(srv) + else: + stop_service(srv) elif action == "restart": DAEMON = True stop_service(srv)