mirror of https://github.com/fail2ban/fail2ban
better handling by start/stop of server in foreground mode;
don't call logging.shutdown because part of exit in fail2bancmdline.pull/1970/head
parent
f31195a4fc
commit
af0f7e93ce
|
@ -151,24 +151,13 @@ class Server:
|
||||||
self.__asyncServer.start(sock, force)
|
self.__asyncServer.start(sock, force)
|
||||||
except AsyncServerException as e:
|
except AsyncServerException as e:
|
||||||
logSys.error("Could not start server: %s", e)
|
logSys.error("Could not start server: %s", e)
|
||||||
# Removes the PID file.
|
|
||||||
try:
|
logSys.info("Shutdown in progress...")
|
||||||
logSys.debug("Remove PID file %s", pidfile)
|
|
||||||
os.remove(pidfile)
|
# Restore default signal handlers:
|
||||||
except (OSError, IOError) as e: # pragma: no cover
|
if _thread_name() == '_MainThread':
|
||||||
logSys.error("Unable to remove PID file: %s", e)
|
for s, sh in self.__prev_signals.iteritems():
|
||||||
logSys.info("Exiting Fail2ban")
|
signal.signal(s, sh)
|
||||||
|
|
||||||
def quit(self):
|
|
||||||
# Stop communication first because if jail's unban action
|
|
||||||
# tries to communicate via fail2ban-client we get a lockup
|
|
||||||
# among threads. So the simplest resolution is to stop all
|
|
||||||
# communications first (which should be ok anyways since we
|
|
||||||
# are exiting)
|
|
||||||
# See https://github.com/fail2ban/fail2ban/issues/7
|
|
||||||
if self.__asyncServer is not None:
|
|
||||||
self.__asyncServer.stop()
|
|
||||||
self.__asyncServer = None
|
|
||||||
|
|
||||||
# Now stop all the jails
|
# Now stop all the jails
|
||||||
self.stopAllJail()
|
self.stopAllJail()
|
||||||
|
@ -179,18 +168,26 @@ class Server:
|
||||||
self.__db.close()
|
self.__db.close()
|
||||||
self.__db = None
|
self.__db = None
|
||||||
|
|
||||||
# Only now shutdown the logging.
|
# Removes the PID file.
|
||||||
if self.__logTarget is not None:
|
try:
|
||||||
with self.__loggingLock:
|
logSys.debug("Remove PID file %s", pidfile)
|
||||||
logging.shutdown()
|
os.remove(pidfile)
|
||||||
|
except (OSError, IOError) as e: # pragma: no cover
|
||||||
# Restore default signal handlers:
|
logSys.error("Unable to remove PID file: %s", e)
|
||||||
if _thread_name() == '_MainThread':
|
logSys.info("Exiting Fail2ban")
|
||||||
for s, sh in self.__prev_signals.iteritems():
|
|
||||||
signal.signal(s, sh)
|
|
||||||
|
|
||||||
|
def quit(self):
|
||||||
# Prevent to call quit twice:
|
# Prevent to call quit twice:
|
||||||
self.quit = lambda: False
|
self.quit = lambda: False
|
||||||
|
# Stop communication first because if jail's unban action
|
||||||
|
# tries to communicate via fail2ban-client we get a lockup
|
||||||
|
# among threads. So the simplest resolution is to stop all
|
||||||
|
# communications first (which should be ok anyways since we
|
||||||
|
# are exiting)
|
||||||
|
# See https://github.com/fail2ban/fail2ban/issues/7
|
||||||
|
if self.__asyncServer is not None:
|
||||||
|
self.__asyncServer.stop()
|
||||||
|
self.__asyncServer = None
|
||||||
|
|
||||||
def addJail(self, name, backend):
|
def addJail(self, name, backend):
|
||||||
addflg = True
|
addflg = True
|
||||||
|
|
Loading…
Reference in New Issue