From 4e2c6a7b8e6e5825f6e609daf0694b483e27f55c Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 17 May 2017 12:44:35 +0200 Subject: [PATCH 1/3] Fix logrotation: manual flushing should be done twice, but automated rotation at midnight should only be done *once*! --- advanced/Scripts/piholeLogFlush.sh | 34 ++++++++++++++++++++++-------- advanced/pihole.cron | 2 +- pihole | 4 ++-- 3 files changed, 28 insertions(+), 12 deletions(-) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 8e4c8266..0a4d12bc 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -9,16 +9,32 @@ # Please see LICENSE file for your rights under this license. echo -n "::: Flushing /var/log/pihole.log ..." -# Test if logrotate is available on this system -if command -v /usr/sbin/logrotate >/dev/null; then - # Flush twice to move all data out of sight of FTL - /usr/sbin/logrotate --force /etc/pihole/logrotate; sleep 3 - /usr/sbin/logrotate --force /etc/pihole/logrotate +if [[ "$@" == *"once"* ]]; then + # Nightly logrotation + 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 - # 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 + # Manual flushing + if command -v /usr/sbin/logrotate >/dev/null; then + # Logrotate twice to move all data out of sight of FTL + /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 echo "... done!" diff --git a/advanced/pihole.cron b/advanced/pihole.cron index c885b371..be35dc50 100644 --- a/advanced/pihole.cron +++ b/advanced/pihole.cron @@ -24,6 +24,6 @@ # Pi-hole: Flush the log daily at 00:00 so it doesn't get out of control # Stats will be viewable in the Web interface thanks to the cron job above # The flush script will use logrotate if available -00 00 * * * root PATH="$PATH:/usr/local/bin/" pihole flush +00 00 * * * root PATH="$PATH:/usr/local/bin/" pihole flush once @reboot root /usr/sbin/logrotate /etc/pihole/logrotate diff --git a/pihole b/pihole index feebbc1c..d116e248 100755 --- a/pihole +++ b/pihole @@ -61,7 +61,7 @@ debugFunc() { } flushFunc() { - "${PI_HOLE_SCRIPT_DIR}"/piholeLogFlush.sh + "${PI_HOLE_SCRIPT_DIR}"/piholeLogFlush.sh "$@" exit 0 } @@ -353,7 +353,7 @@ case "${1}" in "-b" | "blacklist" ) blacklistFunc "$@";; "-wild" | "wildcard" ) wildcardFunc "$@";; "-d" | "debug" ) debugFunc "$@";; - "-f" | "flush" ) flushFunc;; + "-f" | "flush" ) flushFunc "$@";; "-up" | "updatePihole" ) updatePiholeFunc;; "-r" | "reconfigure" ) reconfigurePiholeFunc;; "-g" | "updateGravity" ) updateGravityFunc "$@";; From c9042ffedd110485bd4e248fb2737a6c283fcc01 Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 17 May 2017 12:51:04 +0200 Subject: [PATCH 2/3] Print echos only when manual flushing is requested --- advanced/Scripts/piholeLogFlush.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 0a4d12bc..9801d8ac 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -8,7 +8,6 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. -echo -n "::: Flushing /var/log/pihole.log ..." if [[ "$@" == *"once"* ]]; then # Nightly logrotation if command -v /usr/sbin/logrotate >/dev/null; then @@ -25,6 +24,7 @@ if [[ "$@" == *"once"* ]]; then fi else # Manual flushing + echo -n "::: Flushing /var/log/pihole.log ..." if command -v /usr/sbin/logrotate >/dev/null; then # Logrotate twice to move all data out of sight of FTL /usr/sbin/logrotate --force /etc/pihole/logrotate; sleep 3 @@ -36,5 +36,5 @@ else echo " " > /var/log/pihole.log.1 fi fi + echo "... done!" fi -echo "... done!" From 42eb811910ddb2fcd4a39a1a49b922686126ebce Mon Sep 17 00:00:00 2001 From: DL6ER Date: Wed, 17 May 2017 12:54:43 +0200 Subject: [PATCH 3/3] Add "quiet" mode + update comments in the cron file --- advanced/Scripts/piholeLogFlush.sh | 7 ++++++- advanced/pihole.cron | 7 ++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/advanced/Scripts/piholeLogFlush.sh b/advanced/Scripts/piholeLogFlush.sh index 9801d8ac..cc553b32 100755 --- a/advanced/Scripts/piholeLogFlush.sh +++ b/advanced/Scripts/piholeLogFlush.sh @@ -8,6 +8,9 @@ # This file is copyright under the latest version of the EUPL. # Please see LICENSE file for your rights under this license. +if [[ "$@" != *"quiet"* ]]; then + echo -n "::: Flushing /var/log/pihole.log ..." +fi if [[ "$@" == *"once"* ]]; then # Nightly logrotation if command -v /usr/sbin/logrotate >/dev/null; then @@ -24,7 +27,6 @@ if [[ "$@" == *"once"* ]]; then fi else # Manual flushing - echo -n "::: Flushing /var/log/pihole.log ..." if command -v /usr/sbin/logrotate >/dev/null; then # Logrotate twice to move all data out of sight of FTL /usr/sbin/logrotate --force /etc/pihole/logrotate; sleep 3 @@ -36,5 +38,8 @@ else echo " " > /var/log/pihole.log.1 fi fi +fi + +if [[ "$@" != *"quiet"* ]]; then echo "... done!" fi diff --git a/advanced/pihole.cron b/advanced/pihole.cron index be35dc50..f1beb08c 100644 --- a/advanced/pihole.cron +++ b/advanced/pihole.cron @@ -21,9 +21,10 @@ # Pi-hole: Update Pi-hole! Uncomment to enable auto update #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 -# Stats will be viewable in the Web interface thanks to the cron job above +# Pi-hole: Flush the log daily at 00:00 # The flush script will use logrotate if available -00 00 * * * root PATH="$PATH:/usr/local/bin/" pihole flush once +# 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