Use service wrappers in all scripts

Signed-off-by: Christian König <github@yubiuser.dev>
This commit is contained in:
Christian König 2025-05-27 21:23:56 +02:00
parent b707890f10
commit 137338e6a8
No known key found for this signature in database
3 changed files with 24 additions and 9 deletions

View File

@ -20,6 +20,13 @@ utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
# shellcheck source=./advanced/Scripts/utils.sh # shellcheck source=./advanced/Scripts/utils.sh
source "${utilsfile}" source "${utilsfile}"
readonly PI_HOLE_FILES_DIR="/etc/.pihole"
SKIP_INSTALL="true"
# shellcheck source="./automated install/basic-install.sh"
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
# stop_service() is defined in basic-install.sh
# restart_service() is defined in basic-install.sh
# Determine database location # Determine database location
DBFILE=$(getFTLConfigValue "files.database") DBFILE=$(getFTLConfigValue "files.database")
if [ -z "$DBFILE" ]; then if [ -z "$DBFILE" ]; then
@ -33,7 +40,7 @@ flushARP(){
fi fi
# Stop FTL to prevent database access # Stop FTL to prevent database access
if ! output=$(service pihole-FTL stop 2>&1); then if ! output=$(stop_service pihole-FTL 2>&1); then
echo -e "${OVER} ${CROSS} Failed to stop FTL" echo -e "${OVER} ${CROSS} Failed to stop FTL"
echo " Output: ${output}" echo " Output: ${output}"
return 1 return 1
@ -65,7 +72,7 @@ flushARP(){
fi fi
# Start FTL again # Start FTL again
if ! output=$(service pihole-FTL restart 2>&1); then if ! output=$(restart_service pihole-FTL 2>&1); then
echo -e "${OVER} ${CROSS} Failed to restart FTL" echo -e "${OVER} ${CROSS} Failed to restart FTL"
echo " Output: ${output}" echo " Output: ${output}"
return 1 return 1

View File

@ -17,6 +17,12 @@ utilsfile="${PI_HOLE_SCRIPT_DIR}/utils.sh"
# shellcheck source="./advanced/Scripts/utils.sh" # shellcheck source="./advanced/Scripts/utils.sh"
source "${utilsfile}" source "${utilsfile}"
SKIP_INSTALL="true"
# shellcheck source="./automated install/basic-install.sh"
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
# stop_service() is defined in basic-install.sh
# restart_service() is defined in basic-install.sh
# In case we're running at the same time as a system logrotate, use a # In case we're running at the same time as a system logrotate, use a
# separate logrotate state file to prevent stepping on each other's # separate logrotate state file to prevent stepping on each other's
# toes. # toes.
@ -104,13 +110,14 @@ else
fi fi
# Stop FTL to make sure it doesn't write to the database while we're deleting data # Stop FTL to make sure it doesn't write to the database while we're deleting data
service pihole-FTL stop stop_service pihole-FTL >/dev/null
# Delete most recent 24 hours from FTL's database, leave even older data intact (don't wipe out all history) # Delete most recent 24 hours from FTL's database, leave even older data intact (don't wipe out all history)
deleted=$(pihole-FTL sqlite3 -ni "${DBFILE}" "DELETE FROM query_storage WHERE timestamp >= strftime('%s','now')-86400; select changes() from query_storage limit 1") deleted=$(pihole-FTL sqlite3 -ni "${DBFILE}" "DELETE FROM query_storage WHERE timestamp >= strftime('%s','now')-86400; select changes() from query_storage limit 1")
# Restart FTL # Restart FTL
service pihole-FTL restart restart_service pihole-FTL >/dev/null
if [[ "$*" != *"quiet"* ]]; then if [[ "$*" != *"quiet"* ]]; then
echo -e "${OVER} ${TICK} Deleted ${deleted} queries from long-term query database" echo -e "${OVER} ${TICK} Deleted ${deleted} queries from long-term query database"
fi fi

View File

@ -13,6 +13,11 @@ source "/opt/pihole/COL_TABLE"
# shellcheck source="./advanced/Scripts/utils.sh" # shellcheck source="./advanced/Scripts/utils.sh"
source "/opt/pihole/utils.sh" source "/opt/pihole/utils.sh"
SKIP_INSTALL="true"
# shellcheck source="./automated install/basic-install.sh"
source "${PI_HOLE_FILES_DIR}/automated install/basic-install.sh"
# stop_service() is defined in basic-install.sh
ADMIN_INTERFACE_DIR=$(getFTLConfigValue "webserver.paths.webroot")$(getFTLConfigValue "webserver.paths.webhome") ADMIN_INTERFACE_DIR=$(getFTLConfigValue "webserver.paths.webroot")$(getFTLConfigValue "webserver.paths.webhome")
readonly ADMIN_INTERFACE_DIR readonly ADMIN_INTERFACE_DIR
@ -102,11 +107,7 @@ removePiholeFiles() {
# Remove FTL # Remove FTL
if command -v pihole-FTL &> /dev/null; then if command -v pihole-FTL &> /dev/null; then
echo -ne " ${INFO} Removing pihole-FTL..." echo -ne " ${INFO} Removing pihole-FTL..."
if [[ -x "$(command -v systemctl)" ]]; then stop_service pihole-FTL
systemctl stop pihole-FTL
else
service pihole-FTL stop
fi
${SUDO} rm -f /etc/systemd/system/pihole-FTL.service ${SUDO} rm -f /etc/systemd/system/pihole-FTL.service
if [[ -d '/etc/systemd/system/pihole-FTL.service.d' ]]; then if [[ -d '/etc/systemd/system/pihole-FTL.service.d' ]]; then
read -rp " ${QST} FTL service override directory /etc/systemd/system/pihole-FTL.service.d detected. Do you wish to remove this from your system? [y/N] " answer read -rp " ${QST} FTL service override directory /etc/systemd/system/pihole-FTL.service.d detected. Do you wish to remove this from your system? [y/N] " answer