From 9c2a0cb40395e6d860867cbb23fbbab14cbde2b9 Mon Sep 17 00:00:00 2001 From: Cameron Norman Date: Sun, 20 Apr 2014 11:37:07 -0700 Subject: [PATCH 1/4] Added foreground and background options to fail2ban-client --- bin/fail2ban-client | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/bin/fail2ban-client b/bin/fail2ban-client index 8737c49d..8d757cfe 100755 --- a/bin/fail2ban-client +++ b/bin/fail2ban-client @@ -51,6 +51,7 @@ class Fail2banClient: self.__conf["conf"] = "/etc/fail2ban" self.__conf["dump"] = False self.__conf["force"] = False + self.__conf["background"] = True self.__conf["verbose"] = 1 self.__conf["interactive"] = False self.__conf["socket"] = None @@ -83,6 +84,8 @@ class Fail2banClient: print " -v increase verbosity" print " -q decrease verbosity" 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 " -V, --version print the version" print @@ -125,6 +128,10 @@ class Fail2banClient: self.__conf["force"] = True elif opt[0] == "-i": 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"]: self.dispUsage() sys.exit(0) @@ -194,7 +201,8 @@ class Fail2banClient: # Start the server self.__startServerAsync(self.__conf["socket"], self.__conf["pidfile"], - self.__conf["force"]) + self.__conf["force"], + self.__conf["background"]) try: # Wait for the server to start self.__waitOnServer() @@ -242,14 +250,12 @@ class Fail2banClient: # # 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. pid = os.fork() if pid == 0: args = list() args.append(self.SERVER) - # Start in background mode. - args.append("-b") # Set the socket path. args.append("-s") args.append(socket) @@ -259,6 +265,12 @@ class Fail2banClient: # Force the execution if needed. if force: args.append("-x") + # Start in foreground mode if requested. + if background: + args.append("-b") + else: + args.append("-f") + try: # Use the current directory. exe = os.path.abspath(os.path.join(sys.path[0], self.SERVER)) From 1f53eb2d28ee48f4a0eb0b77f027cdebcb8a8b6e Mon Sep 17 00:00:00 2001 From: Cameron Norman Date: Sun, 20 Apr 2014 11:39:04 -0700 Subject: [PATCH 2/4] Updated man page for new options --- man/fail2ban-client.1 | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/man/fail2ban-client.1 b/man/fail2ban-client.1 index ec79d725..32580e20 100644 --- a/man/fail2ban-client.1 +++ b/man/fail2ban-client.1 @@ -34,6 +34,12 @@ decrease verbosity \fB\-x\fR force execution of the server (remove socket file) .TP +\fB\-b\fR +start the server in background mode (default) +.TP +\fB\-f\fR +start the server in foreground mode (note that the client forks once itself) +.TP \fB\-h\fR, \fB\-\-help\fR display this help message .TP From 7818b0cb2ab6122c72ba1f9206b6e543c3860eaf Mon Sep 17 00:00:00 2001 From: Cameron Norman Date: Sun, 20 Apr 2014 16:03:04 -0700 Subject: [PATCH 3/4] Added f and b to cmdOpts. f = start server in foreground; b = start server in background (default). --- bin/fail2ban-client | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/fail2ban-client b/bin/fail2ban-client index 8d757cfe..1acb3842 100755 --- a/bin/fail2ban-client +++ b/bin/fail2ban-client @@ -324,7 +324,7 @@ class Fail2banClient: # Reads the command line options. try: - cmdOpts = 'hc:s:p:xdviqV' + cmdOpts = 'hc:s:p:xfbdviqV' cmdLongOpts = ['help', 'version'] optList, args = getopt.getopt(self.__argv[1:], cmdOpts, cmdLongOpts) except getopt.GetoptError: From 73cb3e3eec59b8be1a6781454bbe7be940603066 Mon Sep 17 00:00:00 2001 From: Cameron Norman Date: Tue, 22 Apr 2014 20:20:07 -0700 Subject: [PATCH 4/4] Added more specific help message to fail2ban-client with -f option --- bin/fail2ban-client | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/fail2ban-client b/bin/fail2ban-client index 1acb3842..289d7b39 100755 --- a/bin/fail2ban-client +++ b/bin/fail2ban-client @@ -85,7 +85,7 @@ class Fail2banClient: print " -q decrease verbosity" print " -x force execution of the server (remove socket file)" print " -b start server in background (default)" - print " -f start server in foreground" + print " -f start server in foreground (note that the client forks once itself)" print " -h, --help display this help message" print " -V, --version print the version" print