- Test to see if dnsmasq service is enabled before stopping and disabling it.

- Some formatting tweaks to the `start_service` `stop_`service` `disable_service` and `enable_service` commands

Signed-off-by: Adam Warner <adamw@rner.email>
This commit is contained in:
Adam Warner 2018-03-07 23:31:28 +00:00
parent 7193f40b87
commit 84bd86f1ee
No known key found for this signature in database
GPG key ID: F5410858022DA5EB

View file

@ -1113,7 +1113,6 @@ stop_service() {
# Stop service passed in as argument.
# Can softfail, as process may not be installed when this is called
local str="Stopping ${1} service"
echo ""
echo -ne " ${INFO} ${str}..."
if command -v systemctl &> /dev/null; then
systemctl stop "${1}" &> /dev/null || true
@ -1127,7 +1126,6 @@ stop_service() {
start_service() {
# Local, named variables
local str="Starting ${1} service"
echo ""
echo -ne " ${INFO} ${str}..."
# If systemctl exists,
if command -v systemctl &> /dev/null; then
@ -1145,7 +1143,6 @@ start_service() {
enable_service() {
# Local, named variables
local str="Enabling ${1} service to start on reboot"
echo ""
echo -ne " ${INFO} ${str}..."
# If systemctl exists,
if command -v systemctl &> /dev/null; then
@ -1163,7 +1160,6 @@ enable_service() {
disable_service() {
# Local, named variables
local str="Disabling ${1} service"
echo ""
echo -ne " ${INFO} ${str}..."
# If systemctl exists,
if command -v systemctl &> /dev/null; then
@ -1177,6 +1173,26 @@ disable_service() {
echo -e "${OVER} ${TICK} ${str}"
}
check_service_active() {
# If systemctl exists,
if command -v systemctl &> /dev/null; then
# use that to disable the service
if systemctl status "${1}" | grep -q "Active: active" > /dev/null; then
return 0
else
return 1
fi
# Othwerwise,
else
# fall back to service command
if service "${1}" status | grep "Active: active" > /dev/null; then
return 0
else
return 1
fi
fi
}
update_package_cache() {
# Running apt-get update/upgrade with minimal output can cause some issues with
# requiring user input (e.g password for phpmyadmin see #218)
@ -1798,23 +1814,6 @@ FTLinstall() {
# get sha1 of the binary we just downloaded for verification.
curl -sSL --fail "${url}/${binary}.sha1" -o "${binary}.sha1"
# Make the tempory binary executable so that we can test the --resolver flag
chmod +x "${binary}"
# If the --resolver flag returns True (exit code 0), then we can safely stop & disable dnsmasq
if ./"${binary}" --resolver > /dev/null; then
if [[ $(which dnsmasq 2>/dev/null) ]]; then
stop_service dnsmasq
disable_service dnsmasq
#ensure /etc/dnsmasq.conf contains `conf-dir=/etc/dnsmasq.d`
confdir="conf-dir=/etc/dnsmasq.d"
conffile="/etc/dnsmasq.conf"
if ! grep -q "$confdir" "$conffile"; then
echo "$confdir" >> "$conffile"
fi
fi
fi
# If we downloaded binary file (as opposed to text),
if sha1sum --status --quiet -c "${binary}".sha1; then
echo -n "transferred... "
@ -1826,6 +1825,23 @@ FTLinstall() {
popd > /dev/null || { echo "Unable to return to original directory after FTL binary download."; return 1; }
# Install the FTL service
echo -e "${OVER} ${TICK} ${str}"
# If the --resolver flag returns True (exit code 0), then we can safely stop & disable dnsmasq
if pihole-FTL --resolver > /dev/null; then
if [[ $(which dnsmasq 2>/dev/null) ]]; then
if check_service_active "dnsmasq";then
echo " ${INFO} FTL can now resolve DNS Queries without dnsmasq running separately"
stop_service dnsmasq
disable_service dnsmasq
fi
fi
#ensure /etc/dnsmasq.conf contains `conf-dir=/etc/dnsmasq.d`
confdir="conf-dir=/etc/dnsmasq.d"
conffile="/etc/dnsmasq.conf"
if ! grep -q "$confdir" "$conffile"; then
echo "$confdir" >> "$conffile"
fi
fi
return 0
# Otherise,
else
@ -1959,6 +1975,7 @@ FTLdetect() {
FTLinstall "${binary}" || return 1
fi
fi
echo ""
}
make_temporary_log() {