I have made my own custom action for fail2ban. It is a script write in Python. I have created the following function according to the documentation:
- _init_
- start : When fail2ban start
- stop : When fail2ban stop
- ban : When fail2ban ban an ip
- unban : When fail2ban unban an ip
I use this action for many jails and it seems that for each jails fail2ban call the start function and in my case create a new rule iptables. So I have many duplicate iptables rules because fail2ban call several time the start function.
I have tried to put a condition. "If the rule doesn't exist I create it". But all jails seems to be started in thread. With this condition I can limited the duplicate rules to 2 or 3.
Is there a tricks or a permanent solution ? Maybe semaphore during the start function or lock a file or something else ?