Also use killproc.

Signed-off-by: DL6ER <dl6er@dl6er.de>
This commit is contained in:
DL6ER
2019-08-14 23:13:26 +02:00
parent cea9205136
commit eaaa0c1f7f

View File

@@ -10,17 +10,14 @@
### END INIT INFO
FTLUSER=pihole
BINARY="/usr/bin/pihole-FTL"
PIDFILE=/var/run/pihole-FTL.pid
. /lib/lsb/init-functions
get_pid() {
pidof "pihole-FTL"
}
# Start the service
start() {
if get_pid > /dev/null 2>&1; then
if pidofproc -p "${PIDFILE}" > /dev/null 2>&1; then
echo "pihole-FTL is already running"
else
# Touch files to ensure they exist (create if non-existing, preserve if existing)
@@ -40,10 +37,10 @@ start() {
chmod 0644 /var/log/pihole-FTL.log /run/pihole-FTL.pid /run/pihole-FTL.port /var/log/pihole.log
echo "nameserver 127.0.0.1" | /sbin/resolvconf -a lo.piholeFTL
if setcap CAP_NET_BIND_SERVICE,CAP_NET_RAW,CAP_NET_ADMIN+eip "$(which pihole-FTL)"; then
start_daemon -p "${PIDFILE}" /usr/bin/su -s /bin/sh -c "/usr/bin/pihole-FTL -f" "$FTLUSER" &
start_daemon -p "${PIDFILE}" /usr/bin/su -s /bin/sh -c "${BINARY} -f" "$FTLUSER" &
else
echo "Warning: Starting pihole-FTL as root because setting capabilities is not supported on this system"
start_daemon -p "${PIDFILE}" "/usr/bin/pihole-FTL" -f &
start_daemon -p "${PIDFILE}" "${BINARY}" -f &
fi
echo
fi
@@ -51,11 +48,11 @@ start() {
# Stop the service
stop() {
if get_pid > /dev/null 2>&1; then
if pidofproc -p "${PIDFILE}" > /dev/null 2>&1; then
/sbin/resolvconf -d lo.piholeFTL
kill "$(get_pid)"
killproc -p "${PIDFILE}" "${BINARY}"
for i in {1..5}; do
if ! get_pid > /dev/null 2>&1; then
if ! pidofproc -p "${PIDFILE}" > /dev/null 2>&1; then
break
fi
@@ -64,9 +61,9 @@ stop() {
done
echo
if get_pid > /dev/null 2>&1; then
if pidofproc -p "${PIDFILE}" > /dev/null 2>&1; then
echo "Not stopped; may still be shutting down or shutdown may have failed, killing now"
kill -9 "$(get_pid)"
killproc -p "${PIDFILE}" "${BINARY}" 9
exit 1
else
echo "Stopped"
@@ -79,7 +76,7 @@ stop() {
# Indicate the service status
status() {
if get_pid > /dev/null 2>&1; then
if pidofproc -p "${PIDFILE}" > /dev/null 2>&1; then
echo "[ ok ] pihole-FTL is running"
exit 0
else