From d2f3d1c263a6bc8f07229a5870fac3f5a51de1e6 Mon Sep 17 00:00:00 2001 From: Cyril Jaquier Date: Sat, 6 Aug 2005 18:44:06 +0000 Subject: [PATCH] - Fixed a bug with "-k" git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_5@177 a942ae1a-1317-0410-a47c-b1dcaea8d605 --- fail2ban.py | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/fail2ban.py b/fail2ban.py index 7e5bb516a..c7702790e 100755 --- a/fail2ban.py +++ b/fail2ban.py @@ -137,14 +137,7 @@ def getCmdLineOptions(optList): if opt[0] == "-p": conf["pidlock"] = opt[1] if opt[0] == "-k": - pid = checkForPID(conf["pidlock"]) - if pid: - killPID(int(pid)) - logSys.warn("Killed Fail2Ban with PID "+pid) - sys.exit(0) - else: - logSys.error("No running Fail2Ban found") - sys.exit(-1) + conf["kill"] = True def main(): """ Fail2Ban main function @@ -196,6 +189,23 @@ def main(): # Gets command line options getCmdLineOptions(optList) + + # PID lock + pidLock.setPath(conf["pidlock"]) + + # Now we can kill properly a running instance if needed + try: + conf["kill"] + pid = pidLock.exists() + if pid: + killPID(int(pid)) + logSys.warn("Killed Fail2Ban with PID "+pid) + sys.exit(0) + else: + logSys.error("No running Fail2Ban found") + sys.exit(-1) + except KeyError: + pass # Start Fail2Ban in daemon mode if conf["background"]: @@ -244,9 +254,6 @@ def main(): hdlr.setFormatter(formatter) logSys.addHandler(hdlr) - # PID lock - pidLock.setPath(conf["pidlock"]) - # Ignores IP list ignoreIPList = conf["ignoreip"].split(' ')