bind: update init script
authorDavid Härdeman <[email protected]>
Sun, 27 Jul 2025 01:47:56 +0000 (03:47 +0200)
committerNoah Meyerhans <[email protected]>
Sat, 13 Sep 2025 20:36:41 +0000 (13:36 -0700)
Simplify the init script, removing some unnecessary subshells and make sure
that the end result is shellcheck clean.

Signed-off-by: David Härdeman <[email protected]>
net/bind/files/named.init

index f8405076ba10c5fe21736fddc8d69c8875e3f815..aa57e09e2dcfaa8f40804b7780b6c82ceac18c63 100644 (file)
@@ -3,66 +3,53 @@
 # Licensed under the terms of the GNU General Public License version 2
 # or (at your discretion) any later later version
 
+# shellcheck disable=SC2034
 USE_PROCD=1
-
 START=22
 
-config_file=/etc/bind/named.conf
-config_dir=$(dirname $config_file)
-pid_file=/var/run/named/named.pid
-
-rundir=$(dirname $pid_file)
-logdir=/var/log/named/
-cachedir=/var/cache/bind
-libdir=/var/lib/bind
-dyndir=/tmp/bind
-
-conf_local_file=$dyndir/named.conf.local
+config_dir=/etc/bind
+run_dir=/var/run/named
+log_dir=/var/log/named
+cache_dir=/var/cache/bind
+lib_dir=/var/lib/bind
+dyn_dir=/tmp/bind
 
-fix_perms() {
-    for dir in $rundir $libdir $logdir $cachedir $dyndir; do
-       test -e "$dir" || {
-            mkdir -p "$dir"
-            chgrp bind "$dir"
-            chmod g+w "$dir"
-       }
-    done
-}
-
-no_ipv6() {
-    [ -z "$(ip -6 -o route show default)" ]
-}
+config_file=$config_dir/named.conf
+config_local_file=$dyn_dir/named.conf.local
 
 reload_service() {
-    rndc -q reload
+       rndc -q reload
 }
 
 start_service() {
-    user_exists bind 57 || user_add bind 57
-    group_exists bind 57 || group_add bind 57
-    fix_perms
-
-    local runnamed=$(dirname $pid_file)
-    # with dropped privileges, we need this created for us
-    [ -d $runnamed ] || {
-       mkdir -m 0755 $runnamed
-       chown bind.bind $runnamed
-    }
-
-    if [ ! -s /etc/bind/rndc.key ] && [ ! -s /etc/bind/rndc.conf ]; then
-        rndc-confgen -a
-    fi
-
-    touch $conf_local_file
-
-    local args=
-    no_ipv6 && args="-4"
-
-    procd_open_instance
-    procd_set_param command /usr/sbin/named -u bind -f $args -c $config_file
-    procd_set_param file $config_file \
-                        $conf_local_file \
-                        $config_dir/db.*
-    procd_set_param respawn
-    procd_close_instance
+       user_exists bind 57 || user_add bind 57
+       group_exists bind 57 || group_add bind 57
+
+       for dir in $run_dir $log_dir $cache_dir $lib_dir $dyn_dir; do
+               if [ ! -e "$dir" ]; then
+                       mkdir -p "$dir"
+               fi
+               chown bind:bind "$dir"
+               chmod 0775 "$dir"
+       done
+
+       if [ ! -s /etc/bind/rndc.key ] && [ ! -s /etc/bind/rndc.conf ]; then
+               rndc-confgen -a
+               chown bind:bind /etc/bind/rndc.key
+               chmod 0640 /etc/bind/rndc.key
+       fi
+
+       touch $config_local_file
+
+       if [ -z "$(ip -6 -o route show default)" ]; then
+               args="-4"
+       else
+               args=""
+       fi
+
+       procd_open_instance
+       procd_set_param command /usr/sbin/named -u bind -f $args -c $config_file
+       procd_set_param file $config_file $config_local_file $config_dir/db.*
+       procd_set_param respawn
+       procd_close_instance
 }