1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-12-22 14:58:08 +00:00

Add dnsmasq "force-reload" option

* Made use of $PI_HOLE_SCRIPT_DIR
* Fix #1610 & #1624
* Add "$2" to restartDNS options

Signed-off-by: WaLLy3K <wally3k@pi-hole.net>
This commit is contained in:
WaLLy3K 2017-07-24 21:25:04 +10:00 committed by GitHub
parent 6830b08723
commit a2825be819

56
pihole
View File

@ -8,12 +8,12 @@
# This file is copyright under the latest version of the EUPL. # This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
colfile="/opt/pihole/COL_TABLE"
source ${colfile}
readonly PI_HOLE_SCRIPT_DIR="/opt/pihole" readonly PI_HOLE_SCRIPT_DIR="/opt/pihole"
readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf" readonly wildcardlist="/etc/dnsmasq.d/03-pihole-wildcard.conf"
colfile="${PI_HOLE_SCRIPT_DIR}/COL_TABLE"
source "${colfile}"
# Must be root to use this tool # Must be root to use this tool
if [[ ! $EUID -eq 0 ]];then if [[ ! $EUID -eq 0 ]];then
if [[ -x "$(command -v sudo)" ]]; then if [[ -x "$(command -v sudo)" ]]; then
@ -26,7 +26,7 @@ if [[ ! $EUID -eq 0 ]];then
fi fi
webpageFunc() { webpageFunc() {
source /opt/pihole/webpage.sh source "${PI_HOLE_SCRIPT_DIR}/webpage.sh"
main "$@" main "$@"
exit 0 exit 0
} }
@ -340,34 +340,34 @@ versionFunc() {
} }
restartDNS() { restartDNS() {
dnsmasqPid=$(pidof dnsmasq) local svcOption str output status over
local str="Restarting DNS service"
echo -ne " ${INFO} ${str}" # Force-reload is used for "/etc/pihole/*.list" files
if [[ "${dnsmasqPid}" ]]; then # Restart is needed for "/etc/dnsmasq.d/*.conf" files
# Service already running - reload config svcOption="${1:-}"
if [[ -x "$(command -v systemctl)" ]]; then
output=$( { systemctl restart dnsmasq; } 2>&1 ) if [[ -z "${svcOption}" ]]; then
# Get PID of dnsmasq to determine if it needs to start or restart
if pidof dnsmasq &> /dev/null; then
svcOption="restart"
else else
output=$( { service dnsmasq restart; } 2>&1 ) svcOption="start"
fi fi
if [[ -z "${output}" ]]; then fi
echo -e "${OVER} ${TICK} ${str}"
# Only print output to Terminal, not Web Admin
str="${svcOption^}ing DNS service"
[[ -t 1 ]] && echo -ne " ${INFO} ${str}..."
output=$( { service dnsmasq "${svcOption}"; } 2>&1 )
status="$?"
if [[ "$?" -eq 0 ]]; then
[[ -t 1 ]] && echo -e "${OVER} ${TICK} ${str}"
else else
[[ ! -t 1 ]] && OVER=""
echo -e "${OVER} ${CROSS} ${output}" echo -e "${OVER} ${CROSS} ${output}"
fi fi
else
# Service not running, start it up
if [[ -x "$(command -v systemctl)" ]]; then
output=$( { systemctl start dnsmasq; } 2>&1 )
else
output=$( { service dnsmasq start; } 2>&1 )
fi
if [[ -z "${output}" ]]; then
echo -e "${OVER} ${TICK} ${str}"
else
echo -e "${OVER} ${CROSS} ${output}"
fi
fi
} }
piholeEnable() { piholeEnable() {
@ -645,7 +645,7 @@ case "${1}" in
"enable" ) piholeEnable 1;; "enable" ) piholeEnable 1;;
"disable" ) piholeEnable 0 "$2";; "disable" ) piholeEnable 0 "$2";;
"status" ) piholeStatus "$2";; "status" ) piholeStatus "$2";;
"restartdns" ) restartDNS;; "restartdns" ) restartDNS "$2";;
"-a" | "admin" ) webpageFunc "$@";; "-a" | "admin" ) webpageFunc "$@";;
"-t" | "tail" ) tailFunc;; "-t" | "tail" ) tailFunc;;
"checkout" ) piholeCheckoutFunc "$@";; "checkout" ) piholeCheckoutFunc "$@";;