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

Added awareness of systemd-journald (#200)

* Reformatted and refactored some files

* Added awareness of systemd-journald
- Added dependency for bash in debian control file, because this implementation uses bash arrays
- Changed in all shell scripts the interpreter to bash
- Replaced "service log2ram stop" with "systemctl stop log2ram"
- Replaced "-a" with "] && ["
- Increased SIZE and LOG_DISK_SIZE to 128M and 256M because journald can use a lot of space
- Introduced a new switch JOURNALD_AWARE
This commit is contained in:
HyP3r 2022-12-13 15:11:13 +01:00 committed by GitHub
parent 553ebb0cb3
commit bf8f16bba6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 42 additions and 13 deletions

View File

@ -73,7 +73,7 @@ If you do not get any line as response of these commands, something is not worki
## Upgrading ## Upgrading
You need to stop Log2Ram (`service log2ram stop`) and execute the [installation](#installation) process. If you used APT, this will be done automatically. You need to stop Log2Ram (`systemctl stop log2ram`) and execute the [installation](#installation) process. If you used APT, this will be done automatically.
## Customization ## Customization

1
debian/control vendored
View File

@ -1,5 +1,6 @@
Package: log2ram Package: log2ram
Version: VERSION-TO-REPLACE Version: VERSION-TO-REPLACE
Depends: bash (>= 4.3)
Section: net Section: net
Priority: optional Priority: optional
Architecture: all Architecture: all

3
debian/preinst vendored
View File

@ -1,5 +1,4 @@
#!/bin/bash #!/usr/bin/env bash
systemctl -q is-active log2ram.service && systemctl stop log2ram.service systemctl -q is-active log2ram.service && systemctl stop log2ram.service
systemctl -q is-active log2ram-daily.timer && systemctl stop log2ram-daily.timer systemctl -q is-active log2ram-daily.timer && systemctl stop log2ram-daily.timer
rm -rf /var/hdd.log rm -rf /var/hdd.log

View File

@ -1,7 +1,7 @@
#!/usr/bin/env sh #!/usr/bin/env bash
systemctl -q is-active log2ram && { systemctl -q is-active log2ram && {
echo "ERROR: log2ram service is still running. Please run \"sudo service log2ram stop\" to stop it." echo "ERROR: log2ram service is still running. Please run \"sudo systemctl stop log2ram\" to stop it."
exit 1 exit 1
} }
[ "$(id -u)" -eq 0 ] || { [ "$(id -u)" -eq 0 ] || {

31
log2ram
View File

@ -1,4 +1,4 @@
#!/usr/bin/env sh #!/usr/bin/env bash
. /etc/log2ram.conf . /etc/log2ram.conf
@ -16,13 +16,36 @@ is_safe() {
[ -d "$HDD_LOG" ] || exit 1 [ -d "$HDD_LOG" ] || exit 1
} }
## @fn journald_logrotate()
## @brief Logrotate the journal if the current RAM_LOG path is part of the journald directory
journald_logrotate() {
if ! [ -x "$(command -v journalctl)" ] || ! [ "$JOURNALD_AWARE" = true ]; then
return 1
fi
if journalctl --header | grep "File path" | grep "$RAM_LOG" >/dev/null 2>&1; then
journalctl --rotate
return 0
else
return 1
fi
}
## @fn sync_to_disk() ## @fn sync_to_disk()
## @brief Sync memory back to hard disk ## @brief Sync memory back to hard disk
sync_to_disk() { sync_to_disk() {
is_safe is_safe
if [ -z "${NO_RSYNC}" -a -x "$(command -v rsync)" ]; then optional_params=()
rsync -aXv --inplace --no-whole-file --delete-after "$RAM_LOG"/ "$HDD_LOG"/ 2>&1 | tee -a "$LOG2RAM_LOG"
if journald_logrotate; then
optional_params+=("--include=journal/*/*@*.journal")
optional_params+=("--exclude=journal/*/*")
fi
if [ -z "${NO_RSYNC}" ] && [ -x "$(command -v rsync)" ]; then
rsync -aXv --inplace --no-whole-file --delete-after "${optional_params[@]}" "$RAM_LOG"/ "$HDD_LOG"/ 2>&1 |
tee -a "$LOG2RAM_LOG"
else else
cp -rfup "$RAM_LOG"/ -T "$HDD_LOG"/ 2>&1 | tee -a "$LOG2RAM_LOG" cp -rfup "$RAM_LOG"/ -T "$HDD_LOG"/ 2>&1 | tee -a "$LOG2RAM_LOG"
fi fi
@ -48,7 +71,7 @@ sync_from_disk() {
exit 1 exit 1
fi fi
if [ -z "${NO_RSYNC}" -a -x "$(command -v rsync)" ]; then if [ -z "${NO_RSYNC}" ] && [ -x "$(command -v rsync)" ]; then
rsync -aXv --inplace --no-whole-file --delete-after "$HDD_LOG"/ "$RAM_LOG"/ 2>&1 | tee -a "$LOG2RAM_LOG" rsync -aXv --inplace --no-whole-file --delete-after "$HDD_LOG"/ "$RAM_LOG"/ 2>&1 | tee -a "$LOG2RAM_LOG"
else else
cp -rfup "$HDD_LOG"/ -T "$RAM_LOG"/ 2>&1 | tee -a "$LOG2RAM_LOG" cp -rfup "$HDD_LOG"/ -T "$RAM_LOG"/ 2>&1 | tee -a "$LOG2RAM_LOG"

View File

@ -5,7 +5,7 @@
# If it's not enough, log2ram will not be able to use ram. Check you /var/log size folder. # If it's not enough, log2ram will not be able to use ram. Check you /var/log size folder.
# The default is 40M and is basically enough for a lot of applications. # The default is 40M and is basically enough for a lot of applications.
# You will need to increase it if you have a server and a lot of log for example. # You will need to increase it if you have a server and a lot of log for example.
SIZE=40M SIZE=128M
# Select the log syncing method between the log directory on disk and in the RAM. # Select the log syncing method between the log directory on disk and in the RAM.
# The variable may be uncommented out, setting it to false, if "cp" is preferred over "rsync". # The variable may be uncommented out, setting it to false, if "cp" is preferred over "rsync".
@ -18,10 +18,16 @@ SIZE=40M
# Change it to false and you will have only a log if there is no place on RAM anymore. # Change it to false and you will have only a log if there is no place on RAM anymore.
MAIL=true MAIL=true
# Variable for folders to put in RAM. You need to specify the real folder `/path/folder` , the `/path/hdd.folder` will be automatically created. Multiple path can be separeted by `;`. Do not add the final `/` ! # Variable for folders to put in RAM. You need to specify the real folder `/path/folder` , the `/path/hdd.folder` will
# be automatically created. Multiple path can be separeted by `;`. Do not add the final `/` !
# example : PATH_DISK="/var/log;/home/test/FolderInRam" # example : PATH_DISK="/var/log;/home/test/FolderInRam"
PATH_DISK="/var/log" PATH_DISK="/var/log"
# Should log2ram consider journald and do a log rotate before copying the log files back? Please note that for this
# rsync is mandatory. Also make sure that you have configured SystemMaxUse in journald.conf, because the size of this
# ram folder is will probably not be as large as journald will use by default
JOURNALD_AWARE=true
# **************** Zram backing conf ************************************************* # **************** Zram backing conf *************************************************
# ZL2R Zram Log 2 Ram enables a zram drive when ZL2R=true ZL2R=false is mem only tmpfs # ZL2R Zram Log 2 Ram enables a zram drive when ZL2R=true ZL2R=false is mem only tmpfs
@ -35,4 +41,4 @@ 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=256M

View File

@ -1,4 +1,4 @@
#!/usr/bin/env sh #!/usr/bin/env bash
if dpkg -l log2ram 2>/dev/null; then if dpkg -l log2ram 2>/dev/null; then
echo "Please run : apt remove log2ram" echo "Please run : apt remove log2ram"