From c399b4039e1694983ffedd1f8c81e4a760f4c06d Mon Sep 17 00:00:00 2001 From: Samuel FORESTIER Date: Thu, 2 Jul 2020 11:49:15 +0200 Subject: [PATCH 1/3] Replaces CRON usages by a proper systemd timer > Closes #84 > Closes #77 --- README.md | 8 +++++++- build-packages.sh | 5 +++-- debian/postinst | 2 +- debian/preinst | 3 ++- debian/prerm | 6 +++--- install.sh | 7 ++++--- log2ram-daily.service | 6 ++++++ log2ram-daily.timer | 9 +++++++++ log2ram.cron | 3 --- uninstall.sh | 7 +++---- 10 files changed, 38 insertions(+), 18 deletions(-) create mode 100644 log2ram-daily.service create mode 100644 log2ram-daily.timer delete mode 100644 log2ram.cron diff --git a/README.md b/README.md index b389ec2..9db0514 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,13 @@ In the file `/etc/log2ram.conf`, there are three variables: - `ZL2R`: Enable zram compatibility (`false` by default). Check the comment on the config file. See https://github.com/StuartIanNaylor/zram-swap-config to configure a zram space on your raspberry before enable this option. #### refresh time: -By default Log2Ram writes to the HardDisk every day. If you think this is too much, you can move `/etc/cron.daily/log2ram` in an other cron folder, or remove it if you prefer writing logs only at stop/reboot. +By default Log2Ram writes to disk every day. If you think this is too much, you can run `systemctl edit log2ram-daily.timer` and add: + +```ini +[Timer] +OnCalendar=weekly +``` +... or even disable it with `systemctl disable log2ram-daily.timer`, if you prefer writing logs only at stop/reboot. ### It is working? You can now check the mount folder in ram with (You will see lines with log2ram if working) diff --git a/build-packages.sh b/build-packages.sh index ca16e4f..c449e57 100755 --- a/build-packages.sh +++ b/build-packages.sh @@ -23,12 +23,13 @@ rm -rf "$DESTDIR" "$OUTDIR" ## log2ram # Create directory install -Dm 644 "$STARTDIR/log2ram.service" "$DESTDIR/etc/systemd/system/log2ram.service" +install -Dm 644 "$STARTDIR/log2ram-daily.service" "$DESTDIR/etc/systemd/system/log2ram-daily.service" +install -Dm 644 "$STARTDIR/log2ram-daily.timer" "$DESTDIR/etc/systemd/system/log2ram-daily.timer" install -Dm 755 "$STARTDIR/log2ram" "$DESTDIR/usr/local/bin/log2ram" install -Dm 644 "$STARTDIR/log2ram.conf" "$DESTDIR/etc/log2ram.conf" install -Dm 644 "$STARTDIR/uninstall.sh" "$DESTDIR/usr/local/bin/uninstall-log2ram.sh" -# cron -install -Dm 755 "$STARTDIR/log2ram.cron" "$DESTDIR/etc/cron.daily/log2ram" +# logrotate install -Dm 644 "$STARTDIR/log2ram.logrotate" "$DESTDIR/etc/logrotate.d/log2ram" # Build .deb diff --git a/debian/postinst b/debian/postinst index e02a1b0..a5875a5 100755 --- a/debian/postinst +++ b/debian/postinst @@ -2,7 +2,7 @@ set -euo pipefail systemctl daemon-reload -systemctl enable log2ram +systemctl enable log2ram.service log2ram-daily.timer if [ "$1" == "configure" ]; then echo "##### Reboot to activate log2ram #####" diff --git a/debian/preinst b/debian/preinst index 1be8859..986b7d0 100755 --- a/debian/preinst +++ b/debian/preinst @@ -1,6 +1,7 @@ #!/bin/bash -systemctl -q is-active log2ram && systemctl stop log2ram +systemctl -q is-active log2ram.service && systemctl stop log2ram.service +systemctl -q is-active log2ram-daily.timer && systemctl stop log2ram-daily.timer rm -rf /var/hdd.log exit 0 diff --git a/debian/prerm b/debian/prerm index 364a442..c5258d2 100755 --- a/debian/prerm +++ b/debian/prerm @@ -1,12 +1,12 @@ #!/usr/bin/env bash case "$1" in upgrade) - [ -d /run/systemd/system/ ] && systemctl stop log2ram + [ -d /run/systemd/system/ ] && systemctl stop log2ram.service log2ram-daily.timer exit 0 ;; *) - [ -d /run/systemd/system/ ] && systemctl stop log2ram - [ -d /run/systemd/system/ ] && systemctl disable log2ram + [ -d /run/systemd/system/ ] && systemctl stop log2ram.service log2ram-daily.timer + [ -d /run/systemd/system/ ] && systemctl disable log2ram.service log2ram-daily.timer exit 0 ;; esac diff --git a/install.sh b/install.sh index 065ee0e..d6e2abd 100755 --- a/install.sh +++ b/install.sh @@ -6,13 +6,14 @@ systemctl -q is-active log2ram && { echo "ERROR: log2ram service is still runni # log2ram mkdir -p /usr/local/bin/ install -m 644 log2ram.service /etc/systemd/system/log2ram.service +install -m 644 log2ram-daily.service /etc/systemd/system/log2ram-daily.service +install -m 644 log2ram-daily.timer /etc/systemd/system/log2ram-daily.timer install -m 755 log2ram /usr/local/bin/log2ram install -m 644 log2ram.conf /etc/log2ram.conf install -m 644 uninstall.sh /usr/local/bin/uninstall-log2ram.sh -systemctl enable log2ram +systemctl enable log2ram.service log2ram-daily.timer -# cron -install -m 755 log2ram.cron /etc/cron.daily/log2ram +# logrotate install -m 644 log2ram.logrotate /etc/logrotate.d/log2ram # Remove a previous log2ram version diff --git a/log2ram-daily.service b/log2ram-daily.service new file mode 100644 index 0000000..2de88f6 --- /dev/null +++ b/log2ram-daily.service @@ -0,0 +1,6 @@ +[Unit] +Description=Daily Log2Ram writing activities +After=log2ram.service + +[Service] +ExecStart=/usr/bin/systemctl reload log2ram.service diff --git a/log2ram-daily.timer b/log2ram-daily.timer new file mode 100644 index 0000000..b7bdb7f --- /dev/null +++ b/log2ram-daily.timer @@ -0,0 +1,9 @@ +[Unit] +Description=Daily Log2Ram writing activities + +[Timer] +OnCalendar=daily +Persistent=true + +[Install] +WantedBy=timers.target diff --git a/log2ram.cron b/log2ram.cron deleted file mode 100644 index 3c266c1..0000000 --- a/log2ram.cron +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh - -systemctl reload log2ram diff --git a/uninstall.sh b/uninstall.sh index 38bc2a0..675d003 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -2,12 +2,11 @@ if [ "$(id -u)" -eq 0 ] then - service log2ram stop - systemctl disable log2ram - rm /etc/systemd/system/log2ram.service + systemctl stop log2ram.service log2ram-daily.timer + systemctl disable log2ram.service log2ram-daily.timer + rm -rf /etc/systemd/system/log2ram* rm /usr/local/bin/log2ram rm /etc/log2ram.conf - rm /etc/cron.daily/log2ram rm /etc/logrotate.d/log2ram if [ -d /var/hdd.log ]; then From 0fdf8827e57f830ef0884821e75342d5e4fa2e94 Mon Sep 17 00:00:00 2001 From: Samuel FORESTIER Date: Wed, 22 Jul 2020 20:40:02 +0000 Subject: [PATCH 2/3] Silence errors when logrotate is not installed Co-authored-by: emwe1 --- install.sh | 7 ++++++- uninstall.sh | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/install.sh b/install.sh index d6e2abd..52316e0 100755 --- a/install.sh +++ b/install.sh @@ -14,7 +14,12 @@ install -m 644 uninstall.sh /usr/local/bin/uninstall-log2ram.sh systemctl enable log2ram.service log2ram-daily.timer # logrotate -install -m 644 log2ram.logrotate /etc/logrotate.d/log2ram +if [ -d /etc/logrotate.d ]; then + install -m 644 log2ram.logrotate /etc/logrotate.d/log2ram +else + echo "##### Directory /etc/logrotate.d does not exist. #####" + echo "##### Skipping log2ram.logrotate installation. #####" +fi # Remove a previous log2ram version rm -rf /var/log.hdd diff --git a/uninstall.sh b/uninstall.sh index 9b42052..dd243fc 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -13,7 +13,7 @@ then rm -rf /etc/systemd/system/log2ram* rm /usr/local/bin/log2ram rm /etc/log2ram.conf - rm /etc/logrotate.d/log2ram + rm -f /etc/logrotate.d/log2ram if [ -d /var/hdd.log ]; then rm -r /var/hdd.log From 6185780cf779ed46766d01b2f8bfa46869bad0cb Mon Sep 17 00:00:00 2001 From: Samuel FORESTIER Date: Wed, 22 Jul 2020 20:41:51 +0000 Subject: [PATCH 3/3] Hide error if not installed as a package or if `dpkg` is not available --- uninstall.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uninstall.sh b/uninstall.sh index dd243fc..561b838 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -1,6 +1,6 @@ #!/usr/bin/env sh -if dpkg -l log2ram ; then +if dpkg -l log2ram 2> /dev/null; then echo "Please run : apt remove log2ram" exit 1 fi