Background
NetworkManager doesn't run dispatcher.d/pre-down.d scripts, so I have created a systemd-service script. It is working well during startup and shutdown, but during shutdown it doesn't write to syslog. The file /etc/iptables.rules is updated during shutdown, but nothing is logged to /var/log/syslog.
From the terminal running ...
systemctl restart network-down
... writes information to syslog. But not during system reboot.
Question
Is there something missing in my service-script?
Script: /etc/systemd/system/network-down.service:
[Unit]
Description=Firewall Iptables Save
Wants=network-online.target
After=network.target network-online.target
[Service]
Type=oneshot
ExecStart=/bin/true
ExecStop=/bin/bash /etc/NetworkManager/dispatcher.d/pre-down.d/01-firewall-pre-down network pre-down
RemainAfterExit=yes
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=Firewall Iptables Save
[Install]
WantedBy=multi-user.target
Script: 01-firewall-pre-down:
if [ -x /usr/bin/logger ]; then
LOGGER="/usr/bin/logger -s -p daemon.info -t FirewallHandler[PREDOWN]"
else
LOGGER=echo
fi
case "$2" in
pre-up)
if [ ! -r /etc/iptables.rules ]; then
${LOGGER} "No iptables rules exist to restore."
return
fi
if [ ! -x /sbin/iptables-restore ]; then
${LOGGER} "No program exists to restore iptables rules."
return
fi
${LOGGER} "Restoring iptables rules (pre-up)"
/sbin/iptables-restore -c < /etc/iptables.rules
;;
pre-down)
if [ ! -x /sbin/iptables-save ]; then
${LOGGER} "No program exists to save iptables rules."
return
fi
${LOGGER} "Saving iptables rules. (pre-down)"
/sbin/iptables-save -c > /etc/iptables.rules
;;
*)
${LOGGER} "Nothing to do for case: ($2)"
;;
esac
rsyslogd
is stopped before your script is run? You are usigsyslog
as your output/error facility.