#!/bin/bash

# Author: Adam H, Lewenberg (adamhl@stanford.edu)
# Restart either (or both) of bind9 and dnsmasq services.

VERBOSE=

# #### #### #### #### #### #### #### #### #### #### #### #### #### ###
progress() {
    if [ ! -z "$VERBOSE" ]; then
        msg="$1"
        echo "progress: $msg"
    fi
}

exit_with_error() {
    msg="$1"
    echo "error: $msg"
    exit 1
}
# #### #### #### #### #### #### #### #### #### #### #### #### #### ###

if systemctl is-active --quiet bind9; then
    progress "restarting bind9 service"
    systemctl restart bind9
else
    progress "bind9 service is not active or does not exist"
fi

if systemctl is-active --quiet dnsmasq; then
    progress "restarting dnsmasq service"
    systemctl restart dnsmasq
else
    progress "dnsmasq service is not active or does not exist"
fi

exit 0

# Documentation.  Use a hack to hide this from the shell.  Because of the
# above exec line, this should never be executed.
DOCS=<<__END_OF_DOCS__

=for stopwords
Lewenberg systemctl

=head1 NAME

restart-dns-cache - Restart dnsmasq and/or bind9 services

=head1 SYNOPSIS

restart-dns-cache

=head1 DESCRIPTION

B<restart-dns-cache> will restart the dnsmasq service (if running)
and the bind9 service (if running).

=head1 SEE ALSO

systemctl(1)

=head1 AUTHOR

Adam Lewenberg <adamhl@stanford.edu>

=cut

__END_OF_DOCS__
