Browse Source

[213] Propagate exit code, use component_shutdown

Components use component_shutdown, as boss already had a shutdown
function, used for different purpose.

The exit code from there is propagated.
Michal 'vorner' Vaner 13 years ago
parent
commit
b8031ec747

+ 18 - 2
src/bin/bind10/bind10_src.py.in

@@ -262,6 +262,9 @@ class BoB:
                 'priority': 198
             }
         }
+        self.__started = False
+        self.__stopping = False
+        self.exitcode = 0
 
     def config_handler(self, new_config):
         # If this is initial update, don't do anything now, leave it to startup
@@ -588,6 +591,7 @@ class BoB:
 
         # Started successfully
         self.runnable = True
+        self.__started = True
         return None
 
     def stop_all_processes(self):
@@ -604,11 +608,23 @@ class BoB:
         self.cc_session.group_sendmsg({'command': ['shutdown']}, recipient,
             recipient)
 
-    def shutdown(self, exitcode=0):
+    def component_shutdown(self, exitcode=0):
+        """
+        Stop the Boss instance from a components' request. The exitcode
+        indicates the desired exit code.
+        """
+        if self.__stopping:
+            return
+        self.exitcode = exitcode
+        if not self.__started:
+            raise Exception("Component failed during startup");
+        else:
+            self.shutdown()
 
     def shutdown(self):
         """Stop the BoB instance."""
         logger.info(BIND10_SHUTDOWN)
+        self.__stopping = True
         # first try using the BIND 10 request to stop
         try:
             self.stop_all_processes()
@@ -925,7 +941,7 @@ def main():
     signal.signal(signal.SIGCHLD, signal.SIG_DFL)
     boss_of_bind.shutdown()
     unlink_pid_file(options.pid_file)
-    sys.exit(0)
+    sys.exit(boss_of_bind.exitcode)
 
 if __name__ == "__main__":
     main()

+ 1 - 1
src/lib/python/isc/bind10/component.py

@@ -141,7 +141,7 @@ class Component:
         if self.__kind == 'core' or \
             (self.__kind == 'needed' and time.time() - 10 < self.__start_time):
             self.__dead = True
-            self._boss.shutdown(1)
+            self._boss.component_shutdown(1)
         # This means we want to restart
         else:
             self.start()

+ 3 - 1
src/lib/python/isc/bind10/tests/component_test.py

@@ -51,7 +51,7 @@ class BossUtils:
         # Return the original time function
         isc.bind10.component.time.time = self.__orig_time
 
-    def shutdown(self, exitcode=0):
+    def component_shutdown(self, exitcode=0):
         """
         Mock function to shut down. We just note we were asked to do so.
         """
@@ -243,11 +243,13 @@ class ComponentTests(BossUtils, unittest.TestCase):
         A start-stop test for core component. See do_start_stop.
         """
         self.__do_start_stop('core')
+
     def test_start_stop_needed(self):
         """
         A start-stop test for needed component. See do_start_stop.
         """
         self.__do_start_stop('needed')
+
     def test_start_stop_dispensable(self):
         """
         A start-stop test for dispensable component. See do_start_stop.