Systemd with bash script

To load my firewall rules I have always used a init script containing all my iptables rules.
However with the switch to systemd in Debian Jessie things have changed a bit.

create a service file in /etc/systemd/system. In my case this is /etc/systemd/system/firewall.service

[Unit]
Description=Firewall

[Service]
Type=oneshot
ExecStart=/bin/sh /scripts/firewall.sh start
ExecStop=/bin/sh /scripts/firewall.sh stop
ExecReload=/bin/sh /scripts/firewall.sh restart
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target

Important here are the Type and RemainAfterExit parameters. Also don’t forget /bin/sh or /bin/bash if you are executing a script !

Next enable and start the service

systemctl enable firewall.service
service firewall start

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.