1
0
mirror of https://github.com/azlux/log2ram.git synced 2023-10-10 13:37:24 +02:00

Merge pull request #76 from StuartIanNaylor/no-journal

journal + mount tune
This commit is contained in:
azlux 2019-04-15 21:21:50 +02:00 committed by GitHub
commit 4f3cfacf08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 40 additions and 16 deletions

View File

@ -13,7 +13,7 @@ systemctl enable log2ram
# cron # cron
install -m 755 log2ram.hourly /etc/cron.hourly/log2ram 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 # Remove a previous log2ram version
rm -rf /var/log.hdd rm -rf /var/log.hdd

25
log2ram
View File

@ -52,8 +52,7 @@ wait_for () {
createZramLogDrive () { createZramLogDrive () {
# Check Zram Class created # Check Zram Class created
if [ ! -d "/sys/class/zram-control" ]; then if modprobe --first-time --verbose zram; then
modprobe zram
RAM_DEV='0' RAM_DEV='0'
else else
RAM_DEV=$(cat /sys/class/zram-control/hot_add) 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 ${COMP_ALG} > /sys/block/zram${RAM_DEV}/comp_algorithm
echo ${LOG_DISK_SIZE} > /sys/block/zram${RAM_DEV}/disksize echo ${LOG_DISK_SIZE} > /sys/block/zram${RAM_DEV}/disksize
echo ${SIZE} > /sys/block/zram${RAM_DEV}/mem_limit 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 case "$1" in
@ -72,7 +72,7 @@ case "$1" in
wait_for $HDD_LOG wait_for $HDD_LOG
if [ "$ZL2R" = true ]; then if [ "$ZL2R" = true ]; then
createZramLogDrive createZramLogDrive
mount -t ext4 -o nosuid,noexec,nodev,user=log2ram /dev/zram${RAM_DEV} ${RAM_LOG}/ mount -t ext4 -o nosuid,noexec,nodev,discard,user=log2ram /dev/zram${RAM_DEV} ${RAM_LOG}/
else else
mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size=${SIZE} log2ram $RAM_LOG/ mount -t tmpfs -o nosuid,noexec,nodev,mode=0755,size=${SIZE} log2ram $RAM_LOG/
fi fi
@ -82,12 +82,21 @@ case "$1" in
stop) stop)
syncToDisk syncToDisk
#ZRAM_LOG=$(awk '$2 == "/var/log" {print $1}' /proc/mounts) invoke-rc.d rsyslog stop
#ZRAM_LOG=$(echo ${ZRAM_LOG} | grep -o -E '[0-9]+') L2G_DEV=$(df /var/log | tail -1 | awk '{ print $1 }' | tr -dc '0-9')
umount -l $RAM_LOG/ umount -l $RAM_LOG/
umount -l $HDD_LOG/ umount -l $HDD_LOG/
# Unsure as even with Root permision denied if [ "$ZL2R" = true ]; then
#echo ${ZRAM_LOG} > /sys/class/zram-control/hot_remove 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) write)

View File

@ -29,5 +29,5 @@ COMP_ALG=lz4
# LOG_DISK_SIZE is expected compression ratio of alg chosen multiplied by log SIZE # 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 # 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 # 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

View File

@ -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 /var/log/log2ram.log
{ {
rotate 7 rotate 7
@ -7,4 +23,3 @@
delaycompress delaycompress
compress compress
} }

View File

@ -8,7 +8,7 @@ then
rm /usr/local/bin/log2ram rm /usr/local/bin/log2ram
rm /etc/log2ram.conf rm /etc/log2ram.conf
rm /etc/cron.hourly/log2ram rm /etc/cron.hourly/log2ram
rm /etc/logrotate.d/log2ram rm /etc/logrotate.d/00_log2ram
if [ -d /var/hdd.log ]; then if [ -d /var/hdd.log ]; then
rm -r /var/hdd.log rm -r /var/hdd.log