mirror of https://github.com/fail2ban/fail2ban
- Added new PID lock file management
- Fixed a bug with daemon mode and logging git-svn-id: https://fail2ban.svn.sourceforge.net/svnroot/fail2ban/branches/FAIL2BAN-0_5@171 a942ae1a-1317-0410-a47c-b1dcaea8d6050.5
parent
1fcf7612fd
commit
e93c0db20b
37
fail2ban.py
37
fail2ban.py
|
@ -32,12 +32,16 @@ from firewall.firewall import Firewall
|
||||||
from logreader.logreader import LogReader
|
from logreader.logreader import LogReader
|
||||||
from confreader.configreader import ConfigReader
|
from confreader.configreader import ConfigReader
|
||||||
from utils.mail import Mail
|
from utils.mail import Mail
|
||||||
|
from utils.pidlock import PIDLock
|
||||||
from utils.dns import *
|
from utils.dns import *
|
||||||
from utils.process import *
|
from utils.process import *
|
||||||
|
|
||||||
# Gets the instance of the logger.
|
# Get the instance of the logger.
|
||||||
logSys = logging.getLogger("fail2ban")
|
logSys = logging.getLogger("fail2ban")
|
||||||
|
|
||||||
|
# Get PID lock file instance
|
||||||
|
pidLock = PIDLock()
|
||||||
|
|
||||||
# Global variables
|
# Global variables
|
||||||
logFwList = list()
|
logFwList = list()
|
||||||
conf = dict()
|
conf = dict()
|
||||||
|
@ -101,7 +105,7 @@ def killApp():
|
||||||
# Execute global start command
|
# Execute global start command
|
||||||
executeCmd(conf["cmdend"], conf["debug"])
|
executeCmd(conf["cmdend"], conf["debug"])
|
||||||
# Remove the PID lock
|
# Remove the PID lock
|
||||||
removePID(conf["pidlock"])
|
pidLock.remove()
|
||||||
logSys.info("Exiting...")
|
logSys.info("Exiting...")
|
||||||
logging.shutdown()
|
logging.shutdown()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
@ -193,6 +197,14 @@ def main():
|
||||||
# Gets command line options
|
# Gets command line options
|
||||||
getCmdLineOptions(optList)
|
getCmdLineOptions(optList)
|
||||||
|
|
||||||
|
# Start Fail2Ban in daemon mode
|
||||||
|
if conf["background"]:
|
||||||
|
retCode = createDaemon()
|
||||||
|
signal.signal(signal.SIGTERM, sigTERMhandler)
|
||||||
|
if not retCode:
|
||||||
|
logSys.error("Unable to start daemon")
|
||||||
|
sys.exit(-1)
|
||||||
|
|
||||||
# Verbose level
|
# Verbose level
|
||||||
if conf["verbose"]:
|
if conf["verbose"]:
|
||||||
logSys.warn("Verbose level is "+`conf["verbose"]`)
|
logSys.warn("Verbose level is "+`conf["verbose"]`)
|
||||||
|
@ -232,13 +244,8 @@ def main():
|
||||||
hdlr.setFormatter(formatter)
|
hdlr.setFormatter(formatter)
|
||||||
logSys.addHandler(hdlr)
|
logSys.addHandler(hdlr)
|
||||||
|
|
||||||
# Start Fail2Ban in daemon mode
|
# PID lock
|
||||||
if conf["background"]:
|
pidLock.setPath(conf["pidlock"])
|
||||||
retCode = createDaemon()
|
|
||||||
signal.signal(signal.SIGTERM, sigTERMhandler)
|
|
||||||
if not retCode:
|
|
||||||
logSys.error("Unable to start daemon")
|
|
||||||
sys.exit(-1)
|
|
||||||
|
|
||||||
# Ignores IP list
|
# Ignores IP list
|
||||||
ignoreIPList = conf["ignoreip"].split(' ')
|
ignoreIPList = conf["ignoreip"].split(' ')
|
||||||
|
@ -257,16 +264,16 @@ def main():
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
||||||
# Checks that no instance of Fail2Ban is currently running.
|
# Checks that no instance of Fail2Ban is currently running.
|
||||||
pid = checkForPID(conf["pidlock"])
|
pid = pidLock.exists()
|
||||||
if pid:
|
if pid:
|
||||||
logSys.error("Fail2Ban already running with PID "+pid)
|
logSys.error("Fail2Ban already running with PID "+pid)
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
else:
|
else:
|
||||||
createPID(conf["pidlock"])
|
pidLock.create()
|
||||||
|
|
||||||
logSys.debug("ConfFile is "+conf["conffile"])
|
logSys.debug("ConfFile is " + conf["conffile"])
|
||||||
logSys.debug("BanTime is "+`conf["bantime"]`)
|
logSys.debug("BanTime is " + `conf["bantime"]`)
|
||||||
logSys.debug("retryAllowed is "+`conf["maxretry"]`)
|
logSys.debug("retryAllowed is " + `conf["maxretry"]`)
|
||||||
|
|
||||||
# Options
|
# Options
|
||||||
optionValues = (["bool", "enabled", False],
|
optionValues = (["bool", "enabled", False],
|
||||||
|
@ -333,7 +340,7 @@ def main():
|
||||||
for element in logFwList:
|
for element in logFwList:
|
||||||
element[1].addIgnoreIP(ip)
|
element[1].addIgnoreIP(ip)
|
||||||
|
|
||||||
logSys.info("Fail2Ban v"+version+" is running")
|
logSys.info("Fail2Ban v" + version + " is running")
|
||||||
# Execute global start command
|
# Execute global start command
|
||||||
executeCmd(conf["cmdstart"], conf["debug"])
|
executeCmd(conf["cmdstart"], conf["debug"])
|
||||||
# Execute start command of each section
|
# Execute start command of each section
|
||||||
|
|
Loading…
Reference in New Issue