diff --git a/iptables-helper.service b/iptables-helper.service index db5cf55..30472d2 100644 --- a/iptables-helper.service +++ b/iptables-helper.service @@ -4,9 +4,13 @@ After=network.target [Service] Environment="HOME=/root" -ExecStartPre=iptables-restore /etc/iptables.rule +WorkingDirectory=/opt/iptables-helper +ExecStartPre=sh -c "[ -f /etc/iptables.rule ] && iptables-restore /etc/iptables.rule || exit 0;" ExecStart=/opt/iptables-helper/iptables-helper +ExecStartPost=sh -c "iptables-save | tee /etc/iptables.rule > /dev/null" Restart=on-failure +KillMode=process +RestartSec=5s [Install] WantedBy=multi-user.target \ No newline at end of file diff --git a/pkg/utils/iptables/handler.go b/pkg/utils/iptables/handler.go index 9939c14..6316bdc 100644 --- a/pkg/utils/iptables/handler.go +++ b/pkg/utils/iptables/handler.go @@ -80,7 +80,7 @@ func DelRuleByCmd(cmd string) error { } func SaveRule() { - cmd := "sh -c \"iptables-save | tee /etc/iptables.rule\"" + cmd := "sh -c \"iptables-save | tee /etc/iptables.rule > /dev/null\"" commander := command.Commander{} commander.Execute("sudo " + cmd) }