1 From 11ec9629f460bbd6169e8f934d0194912ff257e0 Mon Sep 17 00:00:00 2001
2 From: Michael Tremer <michael.tremer@ipfire.org>
3 Date: Sat, 30 Mar 2013 12:21:29 +0000
4 Subject: [PATCH 09/19] daemon: Restart keepalive daemon after it has crashed.
7 python/pakfire/daemon.py | 27 +++++++++++++++++++++++++++
8 1 file changed, 27 insertions(+)
10 diff --git a/python/pakfire/daemon.py b/python/pakfire/daemon.py
11 index 8c453e0..267b330 100644
12 --- a/python/pakfire/daemon.py
13 +++ b/python/pakfire/daemon.py
14 @@ -73,6 +73,10 @@ class PakfireDaemon(object):
16 time_started = time.time()
18 + # Check if keepalive process is still alive.
19 + if not self.keepalive.is_alive():
20 + self.restart_keepalive(wait=10)
22 # Spawn a sufficient number of worker processes.
23 self.spawn_workers_if_needed()
25 @@ -96,6 +100,29 @@ class PakfireDaemon(object):
26 log.info(_("Shutting down..."))
27 self.__running = False
29 + def restart_keepalive(self, wait=None):
30 + log.critial(_("Restarting keepalive process"))
32 + # Send SIGTERM to really end the process.
33 + self.keepalive.terminate()
35 + # Wait for the process to terminate.
37 + self.keepalive.join(wait)
39 + # Remove the keepalive process from the process list.
41 + self.__workers.remove(self.keepalive)
45 + # Create a new process and start it.
46 + self.keepalive = PakfireDaemonKeepalive(self.config)
47 + self.keepalive.start()
49 + # Add the process to the process list.
50 + self.__workers.append(self.keepalive)
52 def spawn_workers_if_needed(self, *args, **kwargs):
54 Spawns more workers if needed.