"systemd Centos7 "how to run other command with "Servie iptables restart " after it .
Hello Folks ,
im running centos 7 .
i have iptables and fail2ban.
When i run :
service iptables restart
i see all the rules of fail2ban go and i need to make service fail2ban restart.
My question is how can i let the command
service iptables restart , to run service fail2ban restart too ?
cat /usr/lib/systemd/system/iptables.service
[Unit]
Description=IPv4 firewall with iptables
Before=network-pre.target
Wants=network-pre.target
Before=ip6tables.service
After=syslog.target
AssertPathExists=/etc/sysconfig/iptables
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/usr/libexec/iptables/iptables.init start
ExecReload=/usr/libexec/iptables/iptables.init reload
ExecStop=/usr/libexec/iptables/iptables.init stop
Environment=BOOTUP=serial
Environment=CONSOLETYPE=serial
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=basic.target
ALso :
cat /usr/lib/systemd/system/fail2ban.service
[Unit]
Description=Fail2Ban Service
Documentation=man:fail2ban(1)
After=network.target iptables.service firewalld.service ip6tables.service ipset.service nftables.service
PartOf=firewalld.service
[Service]
Type=simple
Environment="PYTHONNOUSERSITE=1"
ExecStartPre=/bin/mkdir -p /run/fail2ban
ExecStart=/usr/bin/fail2ban-server -xf start
# if should be logged in systemd journal, use following line or set logtarget to sysout in fail2ban.local
# ExecStart=/usr/bin/fail2ban-server -xf --logtarget=sysout start
ExecStop=/usr/bin/fail2ban-client stop
ExecReload=/usr/bin/fail2ban-client reload
PIDFile=/run/fail2ban/fail2ban.pid
Restart=on-failure
RestartPreventExitStatus=0 255
[Install]
WantedBy=multi-user.target
So i tried to add some command in the iptables file to be like :
[Unit]
Description=IPv4 firewall with iptables
Before=network-pre.target
Wants=network-pre.target
Before=ip6tables.service
After=syslog.target
AssertPathExists=/etc/sysconfig/iptables
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStartPre=/usr/bin/fail2ban-server -xf restart. ---->Added this line
ExecStart=/usr/libexec/iptables/iptables.init start
ExecReload=/usr/libexec/iptables/iptables.init reload
ExecStop=/usr/libexec/iptables/iptables.init stop
Environment=BOOTUP=serial
Environment=CONSOLETYPE=serial
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=basic.target
But i always get errors when i run :
service iptables restart.
Can I add && run parallel commands with the Systemd iptables file?
Regards
|