Compare commits

...

8 Commits

Author SHA1 Message Date
Christian König
49c0287d4e Do not exit 1 if pkill killed Pi-hole. Killing is not an error
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-04-14 23:25:32 +02:00
Christian König
c65c22d60d Do not create pid and port file during service startup. The files are created by FTL itself
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-04-14 19:47:37 +02:00
Christian König
c942e99941 Guard if no pihole-FTL.conf is present
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-04-13 21:45:11 +02:00
Christian König
6532f3665e Respect custom PID file location
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-04-13 21:31:29 +02:00
Christian König
e79ae76866 Unset the right variable
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-04-04 21:51:32 +02:00
Christian König
dd27e0f157 Use pid file variable also when starting
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-04-04 10:06:52 +02:00
Christian König
c293af7a5a Do not confuse echo and return
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-04-04 10:02:03 +02:00
Christian König
6b5e02fc7d Use pid file in pihole-FTL.service
Signed-off-by: Christian König <ckoenig@posteo.de>
2022-04-04 09:41:56 +02:00

View File

@@ -9,8 +9,39 @@
# Description: Enable service provided by pihole-FTL daemon # Description: Enable service provided by pihole-FTL daemon
### END INIT INFO ### END INIT INFO
# Get PID of main pihole-FTL process
FTLCONFFILE="/etc/pihole/pihole-FTL.conf"
DEFAULT_PID_FILE="/run/pihole-FTL.pid"
getFTLPID() {
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
if [ -s "${FTL_PID_FILE}" ]; then
# -s: FILE exists and has a size greater than zero
FTL_PID="$(cat "$FTL_PID_FILE")"
# Exploit prevention: unset the variable if there is malicious content
# Verify that the value read from the file is numeric
expr "$FTL_PID" : "[^[:digit:]]" > /dev/null && unset FTL_PID
fi
# If FTL is not running, or the PID file contains malicious stuff, substitute
# negative PID to signal this to the caller
echo "${FTL_PID:=-1}"
}
is_running() { is_running() {
pgrep -xo "pihole-FTL" > /dev/null FTL_PID="$(getFTLPID)"
if [ "$FTL_PID" -eq "-1" ]; then
return 1
else
echo 0
fi
} }
@@ -21,8 +52,6 @@ start() {
else else
# Touch files to ensure they exist (create if non-existing, preserve if existing) # Touch files to ensure they exist (create if non-existing, preserve if existing)
mkdir -pm 0755 /run/pihole mkdir -pm 0755 /run/pihole
[ ! -f /run/pihole-FTL.pid ] && install -m 644 -o pihole -g pihole /dev/null /run/pihole-FTL.pid
[ ! -f /run/pihole-FTL.port ] && install -m 644 -o pihole -g pihole /dev/null /run/pihole-FTL.port
[ ! -f /var/log/pihole-FTL.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole-FTL.log [ ! -f /var/log/pihole-FTL.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole-FTL.log
[ ! -f /var/log/pihole.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole.log [ ! -f /var/log/pihole.log ] && install -m 644 -o pihole -g pihole /dev/null /var/log/pihole.log
[ ! -f /etc/pihole/dhcp.leases ] && install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases [ ! -f /etc/pihole/dhcp.leases ] && install -m 644 -o pihole -g pihole /dev/null /etc/pihole/dhcp.leases
@@ -47,7 +76,7 @@ start() {
# Stop the service # Stop the service
stop() { stop() {
if is_running; then if is_running; then
pkill -xo "pihole-FTL" pkill -F "${FTL_PID_FILE}"
for i in 1 2 3 4 5; do for i in 1 2 3 4 5; do
if ! is_running; then if ! is_running; then
break break
@@ -60,8 +89,8 @@ stop() {
if is_running; then if is_running; then
echo "Not stopped; may still be shutting down or shutdown may have failed, killing now" echo "Not stopped; may still be shutting down or shutdown may have failed, killing now"
pkill -xo -9 "pihole-FTL" pkill -9 -F "${FTL_PID_FILE}"
exit 1 exit 0
else else
echo "Stopped" echo "Stopped"
fi fi
@@ -69,7 +98,7 @@ stop() {
echo "Not running" echo "Not running"
fi fi
# Cleanup # Cleanup
rm -f /run/pihole/FTL.sock /dev/shm/FTL-* rm -f /run/pihole/FTL.sock /dev/shm/FTL-* "${FTL_PID_FILE}"
echo echo
} }