Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 201288

Summary: net-analyzer/fail2ban init script does not detect stale socket
Product: Gentoo Linux Reporter: steveb <steeeeeveee>
Component: New packagesAssignee: Gentoo Linux bug wranglers <bug-wranglers>
Status: RESOLVED DUPLICATE    
Severity: enhancement    
Priority: High    
Version: unspecified   
Hardware: All   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description steveb 2007-12-04 22:30:09 UTC
fail2ban creates a socket (normally in /tmp/fail2ban.sock). If fail2ban crashes then it leaves a stale socket and restarting or starting fail2ban fails.

Adding something like that fixes this issue:
--- ./fail2ban  2007-12-04 23:23:51.907181347 +0100
+++ ./fail2ban.org        2007-12-04 23:28:19.145708460 +0100
@@ -29,7 +29,26 @@
        after iptables
 }

+del_stale_socket() {
+       if [ -f /etc/fail2ban/fail2ban.conf ]
+       then
+               local fail2ban_socket="$(sed -n "s:^[\t ]*socket[\t ]*=[\t ]*\([^\t ]*\).*:\1:Ip" /etc/fail2ban/fail2ban.conf)"
+               if [ "${fail2ban_socket}" != "" ]
+               then
+                       if [ -S "${fail2ban_socket}" ]
+                       then
+                               if ( ! lsof "${fail2ban_socket}" >/dev/null 2>&1 )
+                               then
+                                       einfo "Removing stale socket: ${fail2ban_socket}"
+                                       rm -f ${fail2ban_socket} >/dev/null 2>&1
+                               fi
+                       fi
+               fi
+       fi
+}
+
 start() {
+       del_stale_socket
        ebegin "Starting fail2ban"
        ${FAIL2BAN} start &> /dev/null
        eend $? "Failed to start fail2ban"

Reproducible: Always
Comment 1 Jakub Moc (RETIRED) gentoo-dev 2007-12-04 23:37:36 UTC

*** This bug has been marked as a duplicate of bug 168071 ***
Comment 2 steveb 2007-12-04 23:55:54 UTC
(In reply to comment #1)
> 
> *** This bug has been marked as a duplicate of bug 168071 ***
> 
Thanks