From 06cde54d914ff4d025d012980fa003fe318cf990 Mon Sep 17 00:00:00 2001 From: Sebastian Wagner Date: Wed, 16 Nov 2016 12:10:22 +0100 Subject: [PATCH] ENH: ctl handle enabled flag fixes certtools/intelmq#704 Signed-off-by: Sebastian Wagner --- intelmq/bin/intelmqctl.py | 45 ++++++++++++++++++++++----------------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/intelmq/bin/intelmqctl.py b/intelmq/bin/intelmqctl.py index 7c135c260..c4ed59912 100755 --- a/intelmq/bin/intelmqctl.py +++ b/intelmq/bin/intelmqctl.py @@ -31,6 +31,7 @@ class Parameters(object): } MESSAGES = { + 'disabled': '{} is disabled.', 'starting': 'Starting {}...', 'running': '{} is running.', 'stopped': '{} is stopped.', @@ -382,8 +383,12 @@ def bot_start(self, bot_id): def bot_stop(self, bot_id): pid = read_pidfile(bot_id) if not pid: - log_bot_error('stopped', bot_id) - return 'stopped' + if self.runtime_configuration[bot_id].get('enabled', True): + log_bot_error('stopped', bot_id) + return 'stopped' + else: + log_bot_message('disabled', bot_id) + return 'disabled' if not status_process(pid): remove_pidfile(bot_id) log_bot_error('stopped', bot_id) @@ -402,8 +407,12 @@ def bot_stop(self, bot_id): def bot_reload(self, bot_id): pid = read_pidfile(bot_id) if not pid: - log_bot_error('stopped', bot_id) - return 'stopped' + if self.runtime_configuration[bot_id].get('enabled', True): + log_bot_error('stopped', bot_id) + return 'stopped' + else: + log_bot_message('disabled', bot_id) + return 'disabled' if not status_process(pid): remove_pidfile(bot_id) log_bot_error('stopped', bot_id) @@ -432,14 +441,21 @@ def bot_status(self, bot_id): log_bot_error('notfound', bot_id) return 'error' - log_bot_message('stopped', bot_id) - return 'stopped' + if self.runtime_configuration[bot_id].get('enabled', True): + log_bot_message('stopped', bot_id) + return 'stopped' + else: + log_bot_message('disabled', bot_id) + return 'disabled' def botnet_start(self): botnet_status = {} - log_botnet_message('starting') for bot_id in sorted(self.runtime_configuration.keys()): - botnet_status[bot_id] = self.bot_start(bot_id) + if self.runtime_configuration[bot_id].get('enabled', True): + botnet_status[bot_id] = self.bot_start(bot_id) + else: + log_bot_message('disabled', bot_id) + botnet_status[bot_id] = 'disabled' log_botnet_message('running') return botnet_status @@ -460,17 +476,8 @@ def botnet_reload(self): return botnet_status def botnet_restart(self): - botnet_status = {} - log_botnet_message('stopping') - for bot_id in sorted(self.runtime_configuration.keys()): - botnet_status[bot_id] = tuple(self.bot_stop(bot_id)) - time.sleep(3) - log_botnet_message('stopped') - log_botnet_message('starting') - for bot_id in sorted(self.runtime_configuration.keys()): - botnet_status[bot_id] += tuple(self.bot_start(bot_id)) - log_botnet_message('running') - return botnet_status + self.botnet_stop() + return self.botnet_start() def botnet_status(self): botnet_status = {}