From 62e6febab88627cbedfc7b84fb0fd80e56bdc94a Mon Sep 17 00:00:00 2001 From: Averell7 Date: Mon, 7 Oct 2019 19:29:17 +0200 Subject: [PATCH 1/4] add postrotate to ramlog Improve armbian-ramlog. See discussion here : https://github.com/armbian/build/issues/1582 --- packages/bsp/common/usr/lib/armbian/armbian-ramlog | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/packages/bsp/common/usr/lib/armbian/armbian-ramlog b/packages/bsp/common/usr/lib/armbian/armbian-ramlog index 6bdb986243..27e98603cc 100755 --- a/packages/bsp/common/usr/lib/armbian/armbian-ramlog +++ b/packages/bsp/common/usr/lib/armbian/armbian-ramlog @@ -112,6 +112,14 @@ case "$1" in write) syncToDisk ;; + postrotate) + cd /var/log.hdd/ + find . -type f -print | grep -E -v "(\.gz|\.xz|\.[0-9]|armbian-ramlog)" | while IFS= read -r file + do + dest="/var/log/$file" + cat $file > $dest + done + ;; *) echo "Usage: ${0##*/} {start|stop|write}" >&2 exit 1 From 51ee63978fd73d3bd42b84e059529ad75ea90a60 Mon Sep 17 00:00:00 2001 From: Averell7 Date: Mon, 7 Oct 2019 19:44:18 +0200 Subject: [PATCH 2/4] Modify logrotate.service Create a modified logrotate.service to improve armbian-ramlog. See discussion here https://github.com/armbian/build/issues/1582 --- .../etc/systemd/system/logrotate.service | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 packages/bsp/common/etc/systemd/system/logrotate.service diff --git a/packages/bsp/common/etc/systemd/system/logrotate.service b/packages/bsp/common/etc/systemd/system/logrotate.service new file mode 100644 index 0000000000..0bb3bd6cdc --- /dev/null +++ b/packages/bsp/common/etc/systemd/system/logrotate.service @@ -0,0 +1,28 @@ +[Unit] +Description=Rotate log files +Documentation=man:logrotate(8) man:logrotate.conf(5) +ConditionACPower=true + +[Service] +Type=oneshot +ExecStartPre=/usr/lib/armbian/armbian-ramlog write +ExecStart=/usr/sbin/logrotate /etc/logrotate.conf +ExecStartPost=/usr/lib/armbian/armbian-ramlog postrotate + +# performance options +Nice=19 +IOSchedulingClass=best-effort +IOSchedulingPriority=7 + +# hardening options +# details: https://www.freedesktop.org/software/systemd/man/systemd.exec.html +# no ProtectHome for userdir logs +# no PrivateNetwork for mail deliviery +# no ProtectKernelTunables for working SELinux with systemd older than 235 +# no MemoryDenyWriteExecute for gzip on i686 +PrivateDevices=true +PrivateTmp=true +ProtectControlGroups=true +ProtectKernelModules=true +ProtectSystem=full +RestrictRealtime=true From d999875cb537fc90a9fe8e7714f6ee44c8308cab Mon Sep 17 00:00:00 2001 From: Averell7 Date: Tue, 8 Oct 2019 02:51:47 +0200 Subject: [PATCH 3/4] Remove --delete from syncToDisk --- packages/bsp/common/usr/lib/armbian/armbian-ramlog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bsp/common/usr/lib/armbian/armbian-ramlog b/packages/bsp/common/usr/lib/armbian/armbian-ramlog index 27e98603cc..97694f16c8 100755 --- a/packages/bsp/common/usr/lib/armbian/armbian-ramlog +++ b/packages/bsp/common/usr/lib/armbian/armbian-ramlog @@ -46,7 +46,7 @@ syncToDisk () { echo -e "\n\n$(date): Syncing logs to storage\n" | $LOG_OUTPUT if [ "$USE_RSYNC" = true ]; then - ${NoCache} rsync -aXWv --delete --exclude "lost+found" --exclude armbian-ramlog.log --links $RAM_LOG $HDD_LOG 2>&1 | $LOG_OUTPUT + ${NoCache} rsync -aXWv --exclude "lost+found" --exclude armbian-ramlog.log --links $RAM_LOG $HDD_LOG 2>&1 | $LOG_OUTPUT else ${NoCache} cp -rfup $RAM_LOG -T $HDD_LOG 2>&1 | $LOG_OUTPUT fi From 3e149d2fa9a3d3707a26e8af05499a88a12fec2b Mon Sep 17 00:00:00 2001 From: Bot Fap Date: Tue, 8 Oct 2019 13:09:10 +0100 Subject: [PATCH 4/4] Prevent rotated .xz logs from being loaded to ramlog --- packages/bsp/common/usr/lib/armbian/armbian-ramlog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/bsp/common/usr/lib/armbian/armbian-ramlog b/packages/bsp/common/usr/lib/armbian/armbian-ramlog index 97694f16c8..6853cb265f 100755 --- a/packages/bsp/common/usr/lib/armbian/armbian-ramlog +++ b/packages/bsp/common/usr/lib/armbian/armbian-ramlog @@ -60,7 +60,7 @@ syncFromDisk () { echo -e "\n\n$(date): Loading logs from storage\n" | $LOG_OUTPUT if [ "$USE_RSYNC" = true ]; then - ${NoCache} rsync -aXWv --delete --exclude "lost+found" --exclude armbian-ramlog.log --exclude *.gz --exclude='*.[0-9]' --links $HDD_LOG $RAM_LOG 2>&1 | $LOG_OUTPUT + ${NoCache} rsync -aXWv --delete --exclude "lost+found" --exclude armbian-ramlog.log --exclude *.gz --exclude *.xz --exclude='*.[0-9]' --links $HDD_LOG $RAM_LOG 2>&1 | $LOG_OUTPUT else ${NoCache} find $HDD_LOG* -maxdepth 1 -type f -not \( -name '*.[0-9]' -or -name '*.xz*' -or -name '*.gz' \) | xargs cp -ut $RAM_LOG fi