1
0
mirror of https://github.com/certbot/certbot.git synced 2026-01-21 19:01:07 +03:00

Started crash recovery mechanism

This commit is contained in:
Brad Warren
2015-09-10 22:35:44 -04:00
parent 05d5d4ad96
commit 1bb62eed4d
2 changed files with 57 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
"""Registers and calls cleanup functions in case of an error."""
import os
import signal
_SIGNALS = [signal.SIGTERM] if os.name == "nt" else
[signal.SIGTERM, signal.SIGHUP, signal.SIGQUIT,
signal.SIGXCPU, signal.SIGXFSZ, signal.SIGPWR,]
class ErrorHandler():
"""Registers and calls cleanup functions in case of an error."""
def __init__(self, func=None):
self.funcs = []
if func:
self.funcs.append(func)
def __enter__(self):
self.set_signal_handlers()
def __exit__(self, exec_type, exec_value, traceback):
if exec_value is not None:
self.cleanup()
self.reset_signal_handlers()
def register(self, func):
"""Registers func to be called if an error occurs."""
self.funcs.append(func)
def cleanup(self):
"""Calls all registered functions."""
while self.funcs:
self.funcs.pop()()
def set_signal_handlers(self):
for signal_type in _SIGNALS:
signal.signal(signal_type, self._signal_handler)
def reset_signal_handlers(self):
for signal_type in _SIGNALS:
signal.signal(signal_type, signal.SIG_DFL)
def _signal_handler(self, signum, frame):
self.cleanup()
signal.signal(signal_type, signal.SIG_DFL)
os.kill(os.getpid(), signum)

View File

@@ -322,6 +322,17 @@ class IInstaller(IPlugin):
"""
def recovery_routine(self):
"""Revert configuration to most recent finalized checkpoint.
Remove all changes (temporary and permanent) that have not been
finalized. This is useful to protect against crashes and other
execution interruptions.
:raises .errors.PluginError: If unable to recover the configuration
"""
def view_config_changes():
"""Display all of the LE config changes.