2

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
  • Maybe rsyslogd is stopped before your script is run? You are usig syslogas your output/error facility. – ridgy Dec 10 '17 at 20:09
  • @XubuntuLover Can you please add that edit as an answer rather than just saying solved – user689314 Dec 14 '17 at 21:27
0

Change:

After=network.target network-online.target

to:

After=network.target network-online.target rsyslog.service

Now it should be logging!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.