服务配置调整

启动服务时加载已保存的规则文件
This commit is contained in:
zxb 2023-11-03 11:31:10 +08:00
parent dacee0f550
commit 56f99332d8
2 changed files with 6 additions and 2 deletions

View File

@ -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

View File

@ -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)
}