add SIGTERM handler for exit gracefully 80/129280/1
authorDohyung Kim <dohyung2.kim@samsung.com>
Fri, 12 May 2017 02:17:27 +0000 (11:17 +0900)
committerDohyung Kim <dohyung2.kim@samsung.com>
Tue, 16 May 2017 02:45:15 +0000 (11:45 +0900)
mic exit abnormally when it get SIGTERM from kill command or jenkins cancel.
mouned directories reamin. it should be umount.

Signed-off-by: Dohyung Kim <dohyung2.kim@samsung.com>
Change-Id: I71d40bc409ffaed13f2c78ccfd6b03059a934a95

tools/mic

index 44df61e..8df3746 100755 (executable)
--- a/tools/mic
+++ b/tools/mic
@@ -27,6 +27,7 @@
  'create, chroot, convert' and also some parameters for command 'mic'.
 """
 import os
+import signal
 import sys
 import errno
 
@@ -198,6 +199,12 @@ def main(argv):
                         return True
                     return False
 
+    def sigterm_handler(signal, frame):
+        raise errors.Abort('\nSIGTERM catched, program aborted.')
+
+    # Add SIGTERM handler for exit gracefully
+    signal.signal(signal.SIGTERM, sigterm_handler)
+
     # Create top level parser
     epilog = "Try 'mic SUBCOMMAND --help' for help on a specific subcommand."
     description = "mic - the Image Creation tool"