Browse Source

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

master
Dan 1 year ago
parent
commit
27a6745743
4 changed files with 24 additions and 1 deletions
  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 View File

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

+ 2
- 0
borgmatic/commands/borgmatic.py View File

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

+ 17
- 0
borgmatic/signals.py View File

@@ -0,0 +1,17 @@
1
+import os
2
+import signal
3
+
4
+
5
+def _handle_signal(signal_number, frame):
6
+    '''
7
+    Send the signal to all processes in borgmatic's process group, which includes child process.
8
+    '''
9
+    os.killpg(os.getpgrp(), signal_number)
10
+
11
+
12
+def configure_signals():
13
+    '''
14
+    Configure borgmatic's signal handlers to pass relevant signals through to any child processes
15
+    like Borg.
16
+    '''
17
+    signal.signal(signal.SIGTERM, _handle_signal)

+ 1
- 1
setup.py View File

@@ -1,7 +1,7 @@
1 1
 from setuptools import setup, find_packages
2 2
 
3 3
 
4
-VERSION = '1.1.9'
4
+VERSION = '1.1.10.dev0'
5 5
 
6 6
 
7 7
 setup(

Loading…
Cancel
Save