From 56f99332d8d9d19e35b6865341ac2f9dda03d926 Mon Sep 17 00:00:00 2001 From: zxb <919411476@qq.com> Date: Fri, 3 Nov 2023 11:31:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E9=85=8D=E7=BD=AE=E8=B0=83?= =?UTF-8?q?=E6=95=B4=20=E5=90=AF=E5=8A=A8=E6=9C=8D=E5=8A=A1=E6=97=B6?= =?UTF-8?q?=E5=8A=A0=E8=BD=BD=E5=B7=B2=E4=BF=9D=E5=AD=98=E7=9A=84=E8=A7=84?= =?UTF-8?q?=E5=88=99=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- iptables-helper.service | 6 +++++- pkg/utils/iptables/handler.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) 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) }