In another blog post I wrote that I’m using make to restart BIND and showed the following example:

root@dns:/etc/bind# cat Makefile
all:
        /usr/sbin/named-checkconf -z
        /usr/sbin/rndc reload

The all in the above Makefile is the default target used when calling make without options. The second line (Note that there is a TAB) runs a bind tool called named-checkconf with the option -z to check the BIND configuration and zones. If that works the third line is executed and BIND is restarted. If named-checkconf fails because you have a bad configuration the third line will not be executed.

To run this just type make in the directory with the Makefile:

root@dns:/etc/bind# make
/usr/sbin/named-checkconf -z
zone localhost/IN: loaded serial 2
...
/usr/sbin/rndc reload
server reload successful

You still need to look for error messages and need to fix them, but this will avoid restarting a service with a faulty configuration.

You can use this for all kinds of things. I’m using similar Makefiles for restarting Apache, NGINX, Caddy, ICINGA2, … You may even add a git commit at the end to commit your changes when they are successful.