1
0
mirror of https://github.com/pi-hole/pi-hole synced 2024-12-22 14:58:08 +00:00

Merge pull request #1476 from pi-hole/fix/midnightflushing

Fix midnight logrotation
This commit is contained in:
DL6ER 2017-05-18 01:23:32 +02:00 committed by GitHub
commit 4015122d33
3 changed files with 38 additions and 16 deletions

View File

@ -8,17 +8,38 @@
# This file is copyright under the latest version of the EUPL. # This file is copyright under the latest version of the EUPL.
# Please see LICENSE file for your rights under this license. # Please see LICENSE file for your rights under this license.
echo -n "::: Flushing /var/log/pihole.log ..." if [[ "$@" != *"quiet"* ]]; then
# Test if logrotate is available on this system echo -n "::: Flushing /var/log/pihole.log ..."
if command -v /usr/sbin/logrotate >/dev/null; then fi
# Flush twice to move all data out of sight of FTL if [[ "$@" == *"once"* ]]; then
/usr/sbin/logrotate --force /etc/pihole/logrotate; sleep 3 # Nightly logrotation
/usr/sbin/logrotate --force /etc/pihole/logrotate if command -v /usr/sbin/logrotate >/dev/null; then
# Logrotate once
/usr/sbin/logrotate --force /etc/pihole/logrotate
else
# Copy pihole.log over to pihole.log.1
# and empty out pihole.log
# Note that moving the file is not an option, as
# dnsmasq would happily continue writing into the
# moved file (it will have the same file handler)
cp /var/log/pihole.log /var/log/pihole.log.1
echo " " > /var/log/pihole.log
fi
else else
# Flush both pihole.log and pihole.log.1 (if existing) # Manual flushing
echo " " > /var/log/pihole.log if command -v /usr/sbin/logrotate >/dev/null; then
if [ -f /var/log/pihole.log.1 ]; then # Logrotate twice to move all data out of sight of FTL
echo " " > /var/log/pihole.log.1 /usr/sbin/logrotate --force /etc/pihole/logrotate; sleep 3
/usr/sbin/logrotate --force /etc/pihole/logrotate
else
# Flush both pihole.log and pihole.log.1 (if existing)
echo " " > /var/log/pihole.log
if [ -f /var/log/pihole.log.1 ]; then
echo " " > /var/log/pihole.log.1
fi
fi fi
fi fi
echo "... done!"
if [[ "$@" != *"quiet"* ]]; then
echo "... done!"
fi

View File

@ -21,9 +21,10 @@
# Pi-hole: Update Pi-hole! Uncomment to enable auto update # Pi-hole: Update Pi-hole! Uncomment to enable auto update
#30 2 * * 7 root PATH="$PATH:/usr/local/bin/" pihole updatePihole #30 2 * * 7 root PATH="$PATH:/usr/local/bin/" pihole updatePihole
# Pi-hole: Flush the log daily at 00:00 so it doesn't get out of control # Pi-hole: Flush the log daily at 00:00
# Stats will be viewable in the Web interface thanks to the cron job above
# The flush script will use logrotate if available # The flush script will use logrotate if available
00 00 * * * root PATH="$PATH:/usr/local/bin/" pihole flush # parameter "once": logrotate only once (default is twice)
# parameter "quiet": don't print messages
00 00 * * * root PATH="$PATH:/usr/local/bin/" pihole flush once quiet
@reboot root /usr/sbin/logrotate /etc/pihole/logrotate @reboot root /usr/sbin/logrotate /etc/pihole/logrotate

4
pihole
View File

@ -61,7 +61,7 @@ debugFunc() {
} }
flushFunc() { flushFunc() {
"${PI_HOLE_SCRIPT_DIR}"/piholeLogFlush.sh "${PI_HOLE_SCRIPT_DIR}"/piholeLogFlush.sh "$@"
exit 0 exit 0
} }
@ -353,7 +353,7 @@ case "${1}" in
"-b" | "blacklist" ) blacklistFunc "$@";; "-b" | "blacklist" ) blacklistFunc "$@";;
"-wild" | "wildcard" ) wildcardFunc "$@";; "-wild" | "wildcard" ) wildcardFunc "$@";;
"-d" | "debug" ) debugFunc "$@";; "-d" | "debug" ) debugFunc "$@";;
"-f" | "flush" ) flushFunc;; "-f" | "flush" ) flushFunc "$@";;
"-up" | "updatePihole" ) updatePiholeFunc;; "-up" | "updatePihole" ) updatePiholeFunc;;
"-r" | "reconfigure" ) reconfigurePiholeFunc;; "-r" | "reconfigure" ) reconfigurePiholeFunc;;
"-g" | "updateGravity" ) updateGravityFunc "$@";; "-g" | "updateGravity" ) updateGravityFunc "$@";;