workaround for the restart command may fail in container (since fail2ban runs on the host)

This commit is contained in:
2025-02-27 14:03:08 +01:00
parent 9a66d2c87a
commit 8c84909c95
3 changed files with 27 additions and 29 deletions

View File

@@ -19,6 +19,7 @@ package fail2ban
import (
"errors"
"fmt"
"os"
"os/exec"
"strings"
"time"
@@ -152,6 +153,11 @@ func ReloadFail2ban() error {
// RestartFail2ban restarts the Fail2ban service.
func RestartFail2ban() error {
// Check if running inside a container.
if _, container := os.LookupEnv("CONTAINER"); container {
return fmt.Errorf("restart not supported inside container; please restart fail2ban on the host")
}
cmd := "systemctl restart fail2ban"
out, err := execCommand(cmd)
if err != nil {