mirror of https://github.com/fail2ban/fail2ban
Added foreground and background options to fail2ban-client
parent
0c38e09d3d
commit
9c2a0cb403
|
@ -51,6 +51,7 @@ class Fail2banClient:
|
||||||
self.__conf["conf"] = "/etc/fail2ban"
|
self.__conf["conf"] = "/etc/fail2ban"
|
||||||
self.__conf["dump"] = False
|
self.__conf["dump"] = False
|
||||||
self.__conf["force"] = False
|
self.__conf["force"] = False
|
||||||
|
self.__conf["background"] = True
|
||||||
self.__conf["verbose"] = 1
|
self.__conf["verbose"] = 1
|
||||||
self.__conf["interactive"] = False
|
self.__conf["interactive"] = False
|
||||||
self.__conf["socket"] = None
|
self.__conf["socket"] = None
|
||||||
|
@ -83,6 +84,8 @@ class Fail2banClient:
|
||||||
print " -v increase verbosity"
|
print " -v increase verbosity"
|
||||||
print " -q decrease verbosity"
|
print " -q decrease verbosity"
|
||||||
print " -x force execution of the server (remove socket file)"
|
print " -x force execution of the server (remove socket file)"
|
||||||
|
print " -b start server in background (default)"
|
||||||
|
print " -f start server in foreground"
|
||||||
print " -h, --help display this help message"
|
print " -h, --help display this help message"
|
||||||
print " -V, --version print the version"
|
print " -V, --version print the version"
|
||||||
print
|
print
|
||||||
|
@ -125,6 +128,10 @@ class Fail2banClient:
|
||||||
self.__conf["force"] = True
|
self.__conf["force"] = True
|
||||||
elif opt[0] == "-i":
|
elif opt[0] == "-i":
|
||||||
self.__conf["interactive"] = True
|
self.__conf["interactive"] = True
|
||||||
|
elif opt[0] == "-b":
|
||||||
|
self.__conf["background"] = True
|
||||||
|
elif opt[0] == "-f":
|
||||||
|
self.__conf["background"] = False
|
||||||
elif opt[0] in ["-h", "--help"]:
|
elif opt[0] in ["-h", "--help"]:
|
||||||
self.dispUsage()
|
self.dispUsage()
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
@ -194,7 +201,8 @@ class Fail2banClient:
|
||||||
# Start the server
|
# Start the server
|
||||||
self.__startServerAsync(self.__conf["socket"],
|
self.__startServerAsync(self.__conf["socket"],
|
||||||
self.__conf["pidfile"],
|
self.__conf["pidfile"],
|
||||||
self.__conf["force"])
|
self.__conf["force"],
|
||||||
|
self.__conf["background"])
|
||||||
try:
|
try:
|
||||||
# Wait for the server to start
|
# Wait for the server to start
|
||||||
self.__waitOnServer()
|
self.__waitOnServer()
|
||||||
|
@ -242,14 +250,12 @@ class Fail2banClient:
|
||||||
#
|
#
|
||||||
# Start the Fail2ban server in daemon mode.
|
# Start the Fail2ban server in daemon mode.
|
||||||
|
|
||||||
def __startServerAsync(self, socket, pidfile, force = False):
|
def __startServerAsync(self, socket, pidfile, force = False, background = True):
|
||||||
# Forks the current process.
|
# Forks the current process.
|
||||||
pid = os.fork()
|
pid = os.fork()
|
||||||
if pid == 0:
|
if pid == 0:
|
||||||
args = list()
|
args = list()
|
||||||
args.append(self.SERVER)
|
args.append(self.SERVER)
|
||||||
# Start in background mode.
|
|
||||||
args.append("-b")
|
|
||||||
# Set the socket path.
|
# Set the socket path.
|
||||||
args.append("-s")
|
args.append("-s")
|
||||||
args.append(socket)
|
args.append(socket)
|
||||||
|
@ -259,6 +265,12 @@ class Fail2banClient:
|
||||||
# Force the execution if needed.
|
# Force the execution if needed.
|
||||||
if force:
|
if force:
|
||||||
args.append("-x")
|
args.append("-x")
|
||||||
|
# Start in foreground mode if requested.
|
||||||
|
if background:
|
||||||
|
args.append("-b")
|
||||||
|
else:
|
||||||
|
args.append("-f")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Use the current directory.
|
# Use the current directory.
|
||||||
exe = os.path.abspath(os.path.join(sys.path[0], self.SERVER))
|
exe = os.path.abspath(os.path.join(sys.path[0], self.SERVER))
|
||||||
|
|
Loading…
Reference in New Issue