diff --git a/advanced/Scripts/utils.sh b/advanced/Scripts/utils.sh index 2fe419e8..67301394 100755 --- a/advanced/Scripts/utils.sh +++ b/advanced/Scripts/utils.sh @@ -81,25 +81,6 @@ removeKey() { sed -i "/^${key}/d" "${file}" } -####################### -# returns path of FTL's PID file -####################### -getFTLPIDFile() { - local FTLCONFFILE="/etc/pihole/pihole-FTL.conf" - local DEFAULT_PID_FILE="/run/pihole-FTL.pid" - local FTL_PID_FILE - - if [ -s "${FTLCONFFILE}" ]; then - # if PIDFILE is not set in pihole-FTL.conf, use the default path - FTL_PID_FILE="$({ grep '^PIDFILE=' "${FTLCONFFILE}" || echo "${DEFAULT_PID_FILE}"; } | cut -d'=' -f2-)" - else - # if there is no pihole-FTL.conf, use the default path - FTL_PID_FILE="${DEFAULT_PID_FILE}" - fi - - echo "${FTL_PID_FILE}" -} - ####################### # returns FTL's PID based on the content of the pihole-FTL.pid file # diff --git a/advanced/Templates/pihole-FTL-poststop.sh b/advanced/Templates/pihole-FTL-poststop.sh index ac3898d2..b5ddbc97 100755 --- a/advanced/Templates/pihole-FTL-poststop.sh +++ b/advanced/Templates/pihole-FTL-poststop.sh @@ -1,13 +1,13 @@ #!/usr/bin/env sh -# Source utils.sh for getFTLPIDFile() +# Source utils.sh for getFTLConfigValue() PI_HOLE_SCRIPT_DIR='/opt/pihole' utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh" # shellcheck disable=SC1090 . "${utilsfile}" # Get file paths -FTL_PID_FILE="$(getFTLPIDFile)" +FTL_PID_FILE="$(getFTLConfigValue files.pid)" # Cleanup rm -f /run/pihole/FTL.sock /dev/shm/FTL-* "${FTL_PID_FILE}" diff --git a/advanced/Templates/pihole-FTL-prestart.sh b/advanced/Templates/pihole-FTL-prestart.sh index c6817828..d807b81c 100755 --- a/advanced/Templates/pihole-FTL-prestart.sh +++ b/advanced/Templates/pihole-FTL-prestart.sh @@ -1,13 +1,13 @@ #!/usr/bin/env sh -# Source utils.sh for getFTLPIDFile() +# Source utils.sh for getFTLConfigValue() PI_HOLE_SCRIPT_DIR='/opt/pihole' utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh" # shellcheck disable=SC1090 . "${utilsfile}" # Get file paths -FTL_PID_FILE="$(getFTLPIDFile)" +FTL_PID_FILE="$(getFTLConfigValue files.pid)" # Ensure that permissions are set so that pihole-FTL can edit all necessary files # shellcheck disable=SC2174 diff --git a/advanced/Templates/pihole-FTL.service b/advanced/Templates/pihole-FTL.service index 009401fc..151d4f90 100644 --- a/advanced/Templates/pihole-FTL.service +++ b/advanced/Templates/pihole-FTL.service @@ -9,7 +9,7 @@ # Description: Enable service provided by pihole-FTL daemon ### END INIT INFO -# Source utils.sh for getFTLPIDFile(), getFTLPID() +# Source utils.sh for getFTLConfigValue(), getFTLPID() PI_HOLE_SCRIPT_DIR="/opt/pihole" utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh" # shellcheck disable=SC1090 @@ -98,7 +98,7 @@ status() { trap 'cleanup; exit 1' INT HUP TERM ABRT # Get FTL's PID file path -FTL_PID_FILE="$(getFTLPIDFile)" +FTL_PID_FILE="$(getFTLConfigValue files.pid)" # Get FTL's current PID FTL_PID="$(getFTLPID "${FTL_PID_FILE}")" diff --git a/pihole b/pihole index 08ff5b76..4bb7d5e5 100755 --- a/pihole +++ b/pihole @@ -152,7 +152,7 @@ restartDNS() { svcOption="${1:-restart}" # get the current path to the pihole-FTL.pid - FTL_PID_FILE="$(getFTLPIDFile)" + FTL_PID_FILE="$(getFTLConfigValue files.pid)" # Determine if we should reload or restart if [[ "${svcOption}" =~ "reload-lists" ]]; then @@ -337,7 +337,7 @@ statusFunc() { # Determine if there is pihole-FTL service is listening local pid port ftl_pid_file block_status - ftl_pid_file="$(getFTLPIDFile)" + ftl_pid_file="$(getFTLConfigValue files.pid)" pid="$(getFTLPID ${ftl_pid_file})" diff --git a/test/test_any_utils.py b/test/test_any_utils.py index 9eee6885..59745c48 100644 --- a/test/test_any_utils.py +++ b/test/test_any_utils.py @@ -82,18 +82,6 @@ def test_key_removal_works(host): assert expected_stdout == output.stdout -def test_getFTLPIDFile_default(host): - """Confirms getFTLPIDFile returns the default PID file path""" - output = host.run( - """ - source /opt/pihole/utils.sh - getFTLPIDFile - """ - ) - expected_stdout = "/run/pihole-FTL.pid\n" - assert expected_stdout == output.stdout - - def test_getFTLPID_default(host): """Confirms getFTLPID returns the default value if FTL is not running""" output = host.run( @@ -106,27 +94,7 @@ def test_getFTLPID_default(host): assert expected_stdout == output.stdout -def test_getFTLPIDFile_and_getFTLPID_custom(host): - """Confirms getFTLPIDFile returns a custom PID file path""" - host.run( - """ - tmpfile=$(mktemp) - echo "PIDFILE=${tmpfile}" > /etc/pihole/pihole-FTL.conf - echo "1234" > ${tmpfile} - """ - ) - output = host.run( - """ - source /opt/pihole/utils.sh - FTL_PID_FILE=$(getFTLPIDFile) - getFTLPID "${FTL_PID_FILE}" - """ - ) - expected_stdout = "1234\n" - assert expected_stdout == output.stdout - - -def test_getFTLConfigValue_getFTLConfigValue(host): +def test_setFTLConfigValue_getFTLConfigValue(host): """ Confirms getFTLConfigValue works (also assumes setFTLConfigValue works) Requires FTL to be installed, so we do that first