Skip to content

Commit

Permalink
- Create a PID file in /var/run/fail2ban/. Thanks to Julien Perez.
Browse files Browse the repository at this point in the history
  • Loading branch information
lostcontrol committed Jan 20, 2008
1 parent 5e02f46 commit ae26b90
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG
Expand Up @@ -29,6 +29,8 @@ ver. 0.8.2 (2008/??/??) - stable
2.3.
- New log rotation detection algorithm.
- Print monitored files in status.
- Create a PID file in /var/run/fail2ban/. Thanks to Julien
Perez.

ver. 0.8.1 (2007/08/14) - stable
----------
Expand Down
17 changes: 17 additions & 0 deletions server/server.py
Expand Up @@ -36,6 +36,8 @@
logSys = logging.getLogger("fail2ban.server")

class Server:

PID_FILE = "/var/run/fail2ban/fail2ban.pid"

def __init__(self, daemon = False):
self.__loggingLock = Lock()
Expand All @@ -57,6 +59,15 @@ def __sigTERMhandler(self, signum, frame):
def start(self, sock, force = False):
logSys.info("Starting Fail2ban v" + version.version)

# Creates a PID file.
try:
logSys.debug("Creating PID file %s" % Server.PID_FILE)
pidFile = open(Server.PID_FILE, 'w')
pidFile.write("%s\n" % os.getpid())
pidFile.close()
except IOError, e:
logSys.error("Unable to create PID file: %s" % e)

# Install signal handlers
signal.signal(signal.SIGTERM, self.__sigTERMhandler)
signal.signal(signal.SIGINT, self.__sigTERMhandler)
Expand All @@ -76,6 +87,12 @@ def start(self, sock, force = False):
self.__asyncServer.start(sock, force)
except AsyncServerException, e:
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)
except OSError, e:
logSys.error("Unable to remove PID file: %s" % e)
logSys.info("Exiting Fail2ban")

def quit(self):
Expand Down

0 comments on commit ae26b90

Please sign in to comment.