init: register SIGABRT and handle as per SIGUSR2

systemd supports a watchdog (via the WatchdogSec service file option)
which will send the program a SIGABRT when the timer expires, however
currently this causes offlineimap to be killed immediately.

This patch registers SIGABRT and handles it in the same manner as
SIGUSR2, so that the current synchronisation is completed before the
program exits safely.

This makes offlineimap more flexible and robust for persistent setups
that make use of holdconnectionopen and autorefresh options.

For example, it may be useful in assisting with the occasional
situation where offlineimap may not return successfully after a suspend
and resume.

To make use of this, users could add the following to the [Service]
section of their systemd offlineimap service file (restart every 5
minutes):

Restart=on-watchdog
WatchdogSec=300

Signed-off-by: Chris Smart <mail@csmart.io>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Chris Smart 2017-01-21 21:36:59 +11:00 committed by Nicolas Sebrecht
parent 11655cb613
commit eb2bd80851
1 changed files with 2 additions and 1 deletions

View File

@ -416,7 +416,7 @@ class OfflineImap(object):
if sig == signal.SIGUSR1:
# tell each account to stop sleeping
accounts.Account.set_abort_event(self.config, 1)
elif sig == signal.SIGUSR2:
elif sig in (signal.SIGUSR2, signal.SIGABRT):
# tell each account to stop looping
getglobalui().warn("Terminating after this sync...")
accounts.Account.set_abort_event(self.config, 2)
@ -442,6 +442,7 @@ class OfflineImap(object):
signal.signal(signal.SIGHUP, sig_handler)
signal.signal(signal.SIGUSR1, sig_handler)
signal.signal(signal.SIGUSR2, sig_handler)
signal.signal(signal.SIGABRT, sig_handler)
signal.signal(signal.SIGTERM, sig_handler)
signal.signal(signal.SIGINT, sig_handler)
signal.signal(signal.SIGQUIT, sig_handler)