I have a script that sets some iptables rules (
I start it with systemd using this unit file
[Unit] Description=My Rules [Service] Type=oneshot ExecStart=/sbin/myrules start ExecStop=/sbin/myrules stop RemainAfterExit=no [Install] WantedBy=multi-user.target
I would like to let systemd know that, after the script is executed and exited, the service is "alive" (if iptables rules are correctly set).
My script is already able to check the status of my iptables rules. Running :
will return a 0 exit code if everything is OK. If there is something wrong, it will return 1.
Is it possible to make the
systemctl status myrule command call my specific script to check if status is OK and return a message accordingly ?
Edit: I need
systemctl status myrules to display something like
Active: active (whatever)
[Edit-2] But if anything modifies any of the
iptables rules, it should re-check if all rules are active and then display
Active: inactive (whatever)
This is possible only if it runs
myrules status to check service status.
PS: I don't need more information about iptables, I use the -C option to check