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

This commit is contained in:
Dan 2017-10-31 21:58:35 -07:00
parent 95be0c8e46
commit 27a6745743
4 changed files with 24 additions and 1 deletions

4
NEWS
View file

@ -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.

View file

@ -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
borgmatic/signals.py Normal file
View file

@ -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)

View file

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