Browse Source

bug #1819: Add boss nokill flag (-i/--no-kill-i)

Mukund Sivaraman 13 years ago
parent
commit
774554f46b
1 changed files with 26 additions and 19 deletions
  1. 26 19
      src/bin/bind10/bind10_src.py.in

+ 26 - 19
src/bin/bind10/bind10_src.py.in

@@ -685,6 +685,7 @@ class BoB:
 
 
     def shutdown(self):
     def shutdown(self):
         """Stop the BoB instance."""
         """Stop the BoB instance."""
+        global options
         logger.info(BIND10_SHUTDOWN)
         logger.info(BIND10_SHUTDOWN)
         # If ccsession is still there, inform rest of the system this module
         # If ccsession is still there, inform rest of the system this module
         # is stopping. Since everything will be stopped shortly, this is not
         # is stopping. Since everything will be stopped shortly, this is not
@@ -702,32 +703,36 @@ class BoB:
         # still not enough.
         # still not enough.
         time.sleep(1)
         time.sleep(1)
         self.reap_children()
         self.reap_children()
-        # next try sending a SIGTERM
-        components_to_stop = list(self.components.values())
-        for component in components_to_stop:
-            logger.info(BIND10_SEND_SIGTERM, component.name(), component.pid())
-            try:
-                component.kill()
-            except OSError:
-                # ignore these (usually ESRCH because the child
-                # finally exited)
-                pass
-        # finally, send SIGKILL (unmaskable termination) until everybody dies
-        while self.components:
-            # XXX: some delay probably useful... how much is uncertain
-            time.sleep(0.1)  
-            self.reap_children()
+
+        # Send TERM and KILL signals to modules if we're not prevented
+        # from doing so
+        if not options.nokill:
+            # next try sending a SIGTERM
             components_to_stop = list(self.components.values())
             components_to_stop = list(self.components.values())
             for component in components_to_stop:
             for component in components_to_stop:
-                logger.info(BIND10_SEND_SIGKILL, component.name(),
-                            component.pid())
+                logger.info(BIND10_SEND_SIGTERM, component.name(), component.pid())
                 try:
                 try:
-                    component.kill(True)
+                    component.kill()
                 except OSError:
                 except OSError:
                     # ignore these (usually ESRCH because the child
                     # ignore these (usually ESRCH because the child
                     # finally exited)
                     # finally exited)
                     pass
                     pass
-        logger.info(BIND10_SHUTDOWN_COMPLETE)
+            # finally, send SIGKILL (unmaskable termination) until everybody dies
+            while self.components:
+                # XXX: some delay probably useful... how much is uncertain
+                time.sleep(0.1)
+                self.reap_children()
+                components_to_stop = list(self.components.values())
+                for component in components_to_stop:
+                    logger.info(BIND10_SEND_SIGKILL, component.name(),
+                                component.pid())
+                    try:
+                        component.kill(True)
+                    except OSError:
+                        # ignore these (usually ESRCH because the child
+                        # finally exited)
+                        pass
+            logger.info(BIND10_SHUTDOWN_COMPLETE)
 
 
     def _get_process_exit_status(self):
     def _get_process_exit_status(self):
         return os.waitpid(-1, os.WNOHANG)
         return os.waitpid(-1, os.WNOHANG)
@@ -1043,6 +1048,8 @@ def parse_args(args=sys.argv[1:], Parser=OptionParser):
                       help="UNIX domain socket file the b10-msgq daemon will use")
                       help="UNIX domain socket file the b10-msgq daemon will use")
     parser.add_option("-n", "--no-cache", action="store_true", dest="nocache",
     parser.add_option("-n", "--no-cache", action="store_true", dest="nocache",
                       default=False, help="disable hot-spot cache in authoritative DNS server")
                       default=False, help="disable hot-spot cache in authoritative DNS server")
+    parser.add_option("-i", "--no-kill-i", action="store_true", dest="nokill",
+                      default=False, help="do not send SIGTERM or SIGKILL signals to modules")
     parser.add_option("-u", "--user", dest="user", type="string", default=None,
     parser.add_option("-u", "--user", dest="user", type="string", default=None,
                       help="Change user after startup (must run as root)")
                       help="Change user after startup (must run as root)")
     parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
     parser.add_option("-v", "--verbose", dest="verbose", action="store_true",