From 0b146208eb3a6f3ceb04d59e9e89c1cc914854ea Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Sun, 15 Jul 2018 13:32:03 -0400 Subject: [PATCH] files/fail2ban-openrc.init: move pre-flight checks into start_pre(). Our OpenRC service script performs two tasks before starting the service: 1. It removes any stake sockets (from e.g. a system crash). 2. It ensures that the PID file directory exists. These have both been moved into the "start_pre" phase, which is designed to do such things (and will allow us to simplify the "start" phase in the future). The existing "mkdir -p" has also been converted into a "checkpath -d" command which is built-in to OpenRC. --- files/fail2ban-openrc.init | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/files/fail2ban-openrc.init b/files/fail2ban-openrc.init index 9969a3e0..e1cf5273 100755 --- a/files/fail2ban-openrc.init +++ b/files/fail2ban-openrc.init @@ -32,12 +32,16 @@ depend() { after iptables } +start_pre() { + checkpath -d "${pidfile%/*}" || return 1 + + # Remove stale socket after system crash, Gentoo bug 347477 + rm -f /var/run/fail2ban/fail2ban.sock || return 1 +} + start() { ebegin "Starting fail2ban" - mkdir -p /var/run/fail2ban || return 1 - # remove stalled sock file after system crash - # bug 347477 - rm -f /var/run/fail2ban/fail2ban.sock || return 1 + start-stop-daemon --start --pidfile "${pidfile}" \ -- ${command} ${command_args} start eend $? "Failed to start fail2ban"