Explorar el Código

修正gunicorn启动、停止问题

James Iter hace 8 años
padre
commit
d7d029ef9c
Se han modificado 4 ficheros con 43 adiciones y 32 borrados
  1. 1 0
      INSTALL.sh
  2. 37 30
      main.py
  3. 4 1
      models/event_processor.py
  4. 1 1
      shutdown.sh

+ 1 - 0
INSTALL.sh

@@ -252,6 +252,7 @@ function display_summary_information() {
     echo "=== Summary information"
     echo "RDB root password: [${RDB_ROOT_PSWD}]"
     echo "RDB jimv password: [${RDB_JIMV_PSWD}]"
+    echo "Redis port: [6379]"
     echo "Redis password: [${REDIS_PSWD}]"
     echo "======================="
     echo

+ 37 - 30
main.py

@@ -245,47 +245,54 @@ try:
 except:
     logger.error(traceback.format_exc())
 
+threads = []
+# noinspection PyBroadException
+try:
+    signal.signal(signal.SIGTERM, Utils.signal_handle)
+    signal.signal(signal.SIGINT, Utils.signal_handle)
 
-if __name__ == '__main__':
-    # noinspection PyBroadException
-    try:
-        signal.signal(signal.SIGTERM, Utils.signal_handle)
-        signal.signal(signal.SIGINT, Utils.signal_handle)
+    pid = os.fork()
+    if pid == 0:
+        ws_engine_for_vnc()
 
-        pid = os.fork()
-        if pid == 0:
-            ws_engine_for_vnc()
+    else:
+        # 父进程退出时,会清理所有提前退出的子进程的环境。所以这里无需对子进程做等待操作。
+        # 即:即使子进程提前退出,且因父进程没有做wait处理,使其变成了僵尸进程。但当父进程退出时,会对因其所产生的僵尸进程做统一清理操作。
 
-        else:
-            # 父进程退出时,会清理所有提前退出的子进程的环境。所以这里无需对子进程做等待操作。
-            # 即:即使子进程提前退出,且因父进程没有做wait处理,使其变成了僵尸进程。但当父进程退出时,会对因其所产生的僵尸进程做统一清理操作。
+        t_ = threading.Thread(target=EventProcessor.launch, args=())
+        threads.append(t_)
 
-            threads = []
-            t_ = threading.Thread(target=EventProcessor.launch, args=())
-            threads.append(t_)
+        t_ = threading.Thread(target=Init.pub_sub_ping_pong, args=())
+        threads.append(t_)
 
-            t_ = threading.Thread(target=Init.pub_sub_ping_pong, args=())
-            threads.append(t_)
+        t_ = threading.Thread(target=Init.clear_expire_monitor_log, args=())
+        threads.append(t_)
 
-            t_ = threading.Thread(target=Init.clear_expire_monitor_log, args=())
-            threads.append(t_)
+        for t in threads:
+            t.start()
 
-            for t in threads:
-                t.start()
+except:
+    logger.error(traceback.format_exc())
+    exit(-1)
+
+
+if __name__ == '__main__':
+    # noinspection PyBroadException
+    try:
 
-            app.run(host=app.config['listen'], port=app.config['port'], use_reloader=False, threaded=True)
+        app.run(host=app.config['listen'], port=app.config['port'], use_reloader=False, threaded=True)
 
-            while True:
-                if Utils.exit_flag:
-                    # 主线程即将结束
-                    break
-                time.sleep(1)
+        while True:
+            if Utils.exit_flag:
+                # 主线程即将结束
+                break
+            time.sleep(1)
 
-            # 等待子线程结束
-            for t in threads:
-                t.join()
+        # 等待子线程结束
+        for t in threads:
+            t.join()
 
-            print 'Main say bye-bye!'
+        print 'Main say bye-bye!'
 
     except:
         logger.error(traceback.format_exc())

+ 4 - 1
models/event_processor.py

@@ -2,6 +2,7 @@
 # -*- coding: utf-8 -*-
 
 
+import traceback
 import json
 import time
 from IPy import IP
@@ -323,6 +324,7 @@ class EventProcessor(object):
 
     @classmethod
     def launch(cls):
+        logger.info(msg='Thread EventProcessor is launched.')
         while True:
             if Utils.exit_flag:
                 msg = 'Thread EventProcessor say bye-bye'
@@ -362,5 +364,6 @@ class EventProcessor(object):
                     pass
 
             except Exception as e:
-                logger.error(e.message)
+                logger.error(traceback.format_exc())
+                exit(1)
 

+ 1 - 1
shutdown.sh

@@ -19,7 +19,7 @@ if [ -f '/run/jimv/jimvc.pid' ]; then
 
     if [ -f '/run/jimv/jimvc.pid' ]; then
 
-        kill -9 `cat /run/jimv/jimvc.pid`
+        killall -9 gunicorn
         rm -f /run/jimv/jimvc.pid
         echo 'JimV-C is forced to terminate.';
         exit 1