Added ability to specify PID file

This commit is contained in:
Steven Hiscocks
2013-02-17 22:14:01 +00:00
parent 8cf006827e
commit ce3ab34dd8
5 changed files with 36 additions and 14 deletions

View File

@@ -40,8 +40,6 @@ logSys = logging.getLogger("fail2ban.server")
class Server:
PID_FILE = "/var/run/fail2ban/fail2ban.pid"
def __init__(self, daemon = False):
self.__loggingLock = Lock()
self.__lock = RLock()
@@ -59,7 +57,7 @@ class Server:
logSys.debug("Caught signal %d. Exiting" % signum)
self.quit()
def start(self, sock, force = False):
def start(self, sock, pidfile, force = False):
logSys.info("Starting Fail2ban v" + version.version)
# Install signal handlers
@@ -79,8 +77,8 @@ class Server:
# Creates a PID file.
try:
logSys.debug("Creating PID file %s" % Server.PID_FILE)
pidFile = open(Server.PID_FILE, 'w')
logSys.debug("Creating PID file %s" % pidfile)
pidFile = open(pidfile, 'w')
pidFile.write("%s\n" % os.getpid())
pidFile.close()
except IOError, e:
@@ -94,8 +92,8 @@ class Server:
logSys.error("Could not start server: %s", e)
# Removes the PID file.
try:
logSys.debug("Remove PID file %s" % Server.PID_FILE)
os.remove(Server.PID_FILE)
logSys.debug("Remove PID file %s" % pidfile)
os.remove(pidfile)
except OSError, e:
logSys.error("Unable to remove PID file: %s" % e)
logSys.info("Exiting Fail2ban")