summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2018-07-25 15:01:55 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2018-07-25 15:01:55 +0200
commit9c7cdbcabd8997504d6a3b876e91ea34ddb7c266 (patch)
tree8a6d73aa9cffc1eb90a7b933099669b544824947
parenta1c700d53d8a9b0405f7bc28f835ab5142d0f72d (diff)
downloadpykolab-9c7cdbcabd8997504d6a3b876e91ea34ddb7c266.tar.gz
Let a single worker process timeout itself
-rw-r--r--wallace/__init__.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/wallace/__init__.py b/wallace/__init__.py
index 1e050ef..f3450dc 100644
--- a/wallace/__init__.py
+++ b/wallace/__init__.py
@@ -23,8 +23,10 @@ import grp
import multiprocessing
import os
import pwd
+import random
import traceback
from smtpd import SMTPChannel
+import signal
import socket
import struct
import sys
@@ -97,7 +99,18 @@ def modules_heartbeat(wallace_modules):
break
def worker_process(*args, **kw):
- log.debug(_("Worker process %s initializing") % (multiprocessing.current_process().name), level=1)
+ seed = random.randint(0, 6)
+ alarm_after = (seed * 10) + 60
+
+ signal.alarm(alarm_after)
+
+ log.debug(
+ _("Worker process %s initializing (lasts <= %d seconds)") % (
+ multiprocessing.current_process().name,
+ alarm_after
+ ),
+ level=1
+ )
class WallaceDaemon(object):
def __init__(self):
@@ -480,10 +493,13 @@ class WallaceDaemon(object):
sys.exit(exitcode)
def set_signal_handlers(self):
- import signal
signal.signal(signal.SIGHUP, self.reload_config)
+ signal.signal(signal.SIGINT, self.terminate)
signal.signal(signal.SIGTERM, self.remove_pid)
+ def terminate(self, *args, **kw):
+ sys.exit(0)
+
def write_pid(self):
pid = os.getpid()
if os.access(os.path.dirname(conf.pidfile), os.W_OK):