服务配置调整
启动服务时加载已保存的规则文件
This commit is contained in:
parent
dacee0f550
commit
56f99332d8
@ -4,9 +4,13 @@ After=network.target
|
|||||||
|
|
||||||
[Service]
|
[Service]
|
||||||
Environment="HOME=/root"
|
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
|
ExecStart=/opt/iptables-helper/iptables-helper
|
||||||
|
ExecStartPost=sh -c "iptables-save | tee /etc/iptables.rule > /dev/null"
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
|
KillMode=process
|
||||||
|
RestartSec=5s
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
@ -80,7 +80,7 @@ func DelRuleByCmd(cmd string) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func SaveRule() {
|
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 := command.Commander{}
|
||||||
commander.Execute("sudo " + cmd)
|
commander.Execute("sudo " + cmd)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user