Parcourir la source

Passing the Unix SIGTERM signal through to child processes like Borg.

Dan il y a 7 ans
Parent
commit
27a6745743
4 fichiers modifiés avec 24 ajouts et 1 suppressions
  1. 4 0
      NEWS
  2. 2 0
      borgmatic/commands/borgmatic.py
  3. 17 0
      borgmatic/signals.py
  4. 1 1
      setup.py

+ 4 - 0
NEWS

@@ -1,3 +1,7 @@
+1.1.10.dev0
+ * Passing the Unix SIGTERM signal through to child processes like Borg. This means that Borg now
+   properly shuts down if borgmatic is terminated (e.g. due to a system suspend).
+
 1.1.9
  * #16, #38: Support for user-defined hooks before/after backup, or on error.
  * #33: Improve clarity of logging spew at high verbosity levels.

+ 2 - 0
borgmatic/commands/borgmatic.py

@@ -8,6 +8,7 @@ import sys
 from borgmatic.borg import check, create, prune
 from borgmatic.commands import hook
 from borgmatic.config import collect, convert, validate
+from borgmatic.signals import configure_signals
 from borgmatic.verbosity import VERBOSITY_SOME, VERBOSITY_LOTS, verbosity_to_log_level
 
 
@@ -120,6 +121,7 @@ def run_configuration(config_filename, args):  # pragma: no cover
 
 def main():  # pragma: no cover
     try:
+        configure_signals()
         args = parse_arguments(*sys.argv[1:])
         logging.basicConfig(level=verbosity_to_log_level(args.verbosity), format='%(message)s')
 

+ 17 - 0
borgmatic/signals.py

@@ -0,0 +1,17 @@
+import os
+import signal
+
+
+def _handle_signal(signal_number, frame):
+    '''
+    Send the signal to all processes in borgmatic's process group, which includes child process.
+    '''
+    os.killpg(os.getpgrp(), signal_number)
+
+
+def configure_signals():
+    '''
+    Configure borgmatic's signal handlers to pass relevant signals through to any child processes
+    like Borg.
+    '''
+    signal.signal(signal.SIGTERM, _handle_signal)

+ 1 - 1
setup.py

@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 
 
-VERSION = '1.1.9'
+VERSION = '1.1.10.dev0'
 
 
 setup(