diff --git a/install.sh b/install.sh index 62e8742..cc1e24d 100755 --- a/install.sh +++ b/install.sh @@ -13,7 +13,7 @@ systemctl enable log2ram # cron install -m 755 log2ram.hourly /etc/cron.hourly/log2ram -install -m 644 log2ram.logrotate /etc/logrotate.d/log2ram +install -m 644 log2ram.logrotate /etc/logrotate.d/00_log2ram # Remove a previous log2ram version rm -rf /var/log.hdd diff --git a/log2ram b/log2ram index 1f60ef3..344f4b2 100755 --- a/log2ram +++ b/log2ram @@ -52,8 +52,7 @@ wait_for () { createZramLogDrive () { # Check Zram Class created - if [ ! -d "/sys/class/zram-control" ]; then - modprobe zram + if modprobe --first-time --verbose zram; then RAM_DEV='0' else RAM_DEV=$(cat /sys/class/zram-control/hot_add) @@ -61,7 +60,8 @@ createZramLogDrive () { echo ${COMP_ALG} > /sys/block/zram${RAM_DEV}/comp_algorithm echo ${LOG_DISK_SIZE} > /sys/block/zram${RAM_DEV}/disksize echo ${SIZE} > /sys/block/zram${RAM_DEV}/mem_limit - mke2fs -t ext4 /dev/zram${RAM_DEV} + mke2fs -v -t ext4 -O ^has_journal -s 1024 -L log2ram$RAM_DEV /dev/zram${RAM_DEV} + tune2fs -o journal_data_writeback /dev/zram${RAM_DEV} } case "$1" in @@ -70,25 +70,34 @@ case "$1" in mount --bind $RAM_LOG/ $HDD_LOG/ mount --make-private $HDD_LOG/ wait_for $HDD_LOG - if [ "$ZL2R" = true ]; then + if [ "$ZL2R" = true ]; then createZramLogDrive - mount -t ext4 -o nosuid,noexec,nodev,user=log2ram /dev/zram${RAM_DEV} ${RAM_LOG}/ - else + mount -t ext4 -o nosuid,noexec,nodev,discard,user=log2ram /dev/zram${RAM_DEV} ${RAM_LOG}/ + else mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size=${SIZE} log2ram $RAM_LOG/ - fi + fi wait_for $RAM_LOG syncFromDisk ;; stop) syncToDisk - #ZRAM_LOG=$(awk '$2 == "/var/log" {print $1}' /proc/mounts) - #ZRAM_LOG=$(echo ${ZRAM_LOG} | grep -o -E '[0-9]+') + invoke-rc.d rsyslog stop + L2G_DEV=$(df /var/log | tail -1 | awk '{ print $1 }' | tr -dc '0-9') umount -l $RAM_LOG/ umount -l $HDD_LOG/ - # Unsure as even with Root permision denied - #echo ${ZRAM_LOG} > /sys/class/zram-control/hot_remove - ;; + if [ "$ZL2R" = true ]; then + RAM_DEV=$(cat /sys/class/zram-control/hot_add) + if [ "$RAM_DEV" -eq "1" ];then + echo "$L2G_DEV" > /sys/class/zram-control/hot_remove + rmod zram + else + echo "$L2G_DEV" > /sys/class/zram-control/hot_remove + fi + fi + invoke-rc.d rsyslog restart + journalctl --flush + ;; write) syncToDisk diff --git a/log2ram.conf b/log2ram.conf index d5fbd2c..198c517 100644 --- a/log2ram.conf +++ b/log2ram.conf @@ -29,5 +29,5 @@ COMP_ALG=lz4 # LOG_DISK_SIZE is expected compression ratio of alg chosen multiplied by log SIZE # lzo/lz4=2.1:1 compression ratio zlib=2.7:1 zstandard=2.9:1 # Really a guestimate of a bit bigger than compression ratio whilst minimising 0.1% mem usage of disk size -LOG_DISK_SIZE=100M +LOG_DISK_SIZE=60M diff --git a/log2ram.logrotate b/log2ram.logrotate index dbe9914..3425f4d 100644 --- a/log2ram.logrotate +++ b/log2ram.logrotate @@ -1,3 +1,19 @@ +# These settings will save the rotated logfiles to a seperate location. +# This file needs to be located in /etc/logrotate.d. +# The "00" prefix in the file name is required to ensure this file is +# loaded before any program specific logrotate settings are loaded as +# contents of /etc/logrotate.d are read in alphabetical order. + +# The path & name for rotated logfiles folder. +olddir /var/log.old + +# Create the path if it doesn't exist +createolddir 755 root root + +# To allow the files to be "moved" (ie copied and original deleted) +# to another device/partition (eg out of RAM) +renamecopy + /var/log/log2ram.log { rotate 7 @@ -7,4 +23,3 @@ delaycompress compress } - diff --git a/uninstall.sh b/uninstall.sh index 7a82692..f21169e 100755 --- a/uninstall.sh +++ b/uninstall.sh @@ -8,7 +8,7 @@ then rm /usr/local/bin/log2ram rm /etc/log2ram.conf rm /etc/cron.hourly/log2ram - rm /etc/logrotate.d/log2ram + rm /etc/logrotate.d/00_log2ram if [ -d /var/hdd.log ]; then rm -r /var/hdd.log