pax_global_header00006660000000000000000000000064146323744600014523gustar00rootroot0000000000000052 comment=f171449530f8984374c8f69fff3c92af813a694b log2ram-1.7.2/000077500000000000000000000000001463237446000130755ustar00rootroot00000000000000log2ram-1.7.2/LICENSE000066400000000000000000000021101463237446000140740ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) 2016-2023, Azlux Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. log2ram-1.7.2/README.md000066400000000000000000000154011463237446000143550ustar00rootroot00000000000000# Log2Ram Log2Ram works just like ramlog for systemd (on Debian 8 Jessie for example). Useful for **RaspberryPi** for not writing on the SD card all the time. You need it because your SD card doesn't want to suffer anymore! Explanations: The script creates a `/var/log` mount point in RAM. So any writing of the log to the `/var/log` folder will not actually be written to disk (in this case to the SD card on a Raspberry Pi) but directly to RAM. By default, every day the CRON will synchronize the contents in RAM with the folder located on the physical disk. The script will also make this copy of RAM to disk in case of machine shutdowns (but, of course, it still won't do it in case of power failures). This way you can avoid excessive writing on the SD card and extend its life. [Log2Ram](https://github.com/azlux/log2ram)'s script works on every Linux system. If you don't have Systemd, you can still use Log2Ram with your own daemon manager. Log2Ram is based on transient /var/log for Systemd. For more information, check [here](https://www.debian-administration.org/article/661/A_transient_/var/log). _____ ## Table of Contents 1. [Installation](#installation) 2. [Is it working?](#is-it-working) 3. [Upgrading](#upgrading) 4. [Customization](#customization) 5. [Troubleshooting](#troubleshooting) 6. [Uninstallation](#uninstallation-) ## Installation ### Via APT (recommended) ```bash echo "deb [signed-by=/usr/share/keyrings/azlux-archive-keyring.gpg] http://packages.azlux.fr/debian/ bookworm main" | sudo tee /etc/apt/sources.list.d/azlux.list sudo wget -O /usr/share/keyrings/azlux-archive-keyring.gpg https://azlux.fr/repo.gpg sudo apt update sudo apt install log2ram ``` ### Manually ```bash curl -L https://github.com/azlux/log2ram/archive/master.tar.gz | tar zxf - cd log2ram-master chmod +x install.sh && sudo ./install.sh cd .. rm -r log2ram-master ``` For better performances, `RSYNC` is a recommended package. **REBOOT** before installing anything else (for example `apache2`) ## Is it working? After installing and rebooting, use systemctl to check if Log2Ram started successfully: ```bash systemctl status log2ram ``` This will show a color-coded status (green: active/red: failed), as well as the last few log lines. To show the full log (scrolled to the end), run: ```bash journalctl -u log2ram -e ``` The log is also written to `/var/log/log2ram.log`. You can also inspect the mount folder in RAM with: ```bash df -hT | grep log2ram | awk '{print " Name: " $1 "\nMount: " $7 "\n Type: " $2 "\nUsage: " $6 "\n Size: " $3 "\n Used: " $4 "\n Free: " $5}' ``` Returns: ```bash Name: log2ram Mount: /var/log Type: tmpfs Usage: 72% Size: 128M Used: 93M Free: 36M ``` Or also: ```bash mount | grep log2ram | awk -F'[ ()]+' '{print " Name: " $1 "\n Mount: " $3 "\n Type: " $5 "\nOptions: " $6}' ``` Returns: ```bash Name: log2ram Mount: /var/log Type: tmpfs Options: rw,nosuid,nodev,noexec,noatime,size=131072k,mode=755,uid=100000,gid=100000,inode64 ``` If you do not get any line as response of these commands, something is not working. Refer to [this section](#is-it-working). ## Upgrading You need to stop Log2Ram (`systemctl stop log2ram`) and execute the [installation](#installation) process. If you used APT, this will be done automatically. ## Customization #### Variables In the file `/etc/log2ram.conf`, there are five variables: - `SIZE`: defines the size the log folder will reserve into the RAM (default is 40M). - `USE_RSYNC`: (commented out by default = `true`) use `cp` instead of `rsync` (if set to `false`). - `MAIL`: disables the error system mail if there is not enough place on RAM (if set to `false`). - `PATH_DISK`: activate log2ram for other path than default one. Paths should be separated with a `;`. - `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 disk every day. If you think this is too much, you can run `systemctl edit log2ram-daily.timer` and for example add: ```ini [Timer] OnCalendar= OnCalendar=Mon *-*-* 23:55:00 ``` Note: The ``OnCalendar=`` is important because it disables all existing times (e.g. the default one) for log2ram. ... Or even disable it altogether with `systemctl disable log2ram-daily.timer`, if you instead prefer Log2Ram to be writing logs only on system stops/reboots. #### Compressor Compressor for ZRAM. Useful for the `COMP_ALG` of ZRAM on the config file. | Compressor name | Ratio | Compression | Decompress. | |------------------------|----------|-------------|-------------| |zstd 1.3.4 -1 | 2.877 | 470 MB/s | 1380 MB/s | |zlib 1.2.11 -1 | 2.743 | 110 MB/s | 400 MB/s | |brotli 1.0.2 -0 | 2.701 | 410 MB/s | 430 MB/s | |quicklz 1.5.0 -1 | 2.238 | 550 MB/s | 710 MB/s | |lzo1x 2.09 -1 | 2.108 | 650 MB/s | 830 MB/s | |lz4 1.8.1 | 2.101 | 750 MB/s | 3700 MB/s | |snappy 1.1.4 | 2.091 | 530 MB/s | 1800 MB/s | |lzf 3.6 -1 | 2.077 | 400 MB/s | 860 MB/s | ###### Now, muffins for everyone! ## Troubleshooting ### Existing content in `/var/log` too large for RAM One thing that stops Log2Ram from functioning is if `/var/log` is too large before starting Log2Ram the first time. This can happen if logs had been collected for a long time before installing Log2Ram itself. Find the largest directories in `/var/log` (this example command only shows the 3 largest): ```bash sudo du -hs /var/log/* | sort -h | tail -n 3 ``` If the `/var/log/journal` is very large, then there are a lot of system logs. Deletion of old "archived" logs can be fixed by adjusting a setting. Edit the `/etc/systemd/journald.conf` file and add the following option: ```bash SystemMaxUse=20M ``` **Or** the more radical version of directly flushing the journal to a size that matches log2ram size imediately _(Be aware that this flish flush the systemd journal logs imediately to the given size!)_ ```bash journalctl --vacuum-size=32M ``` This should be set to a value smaller than the size of the RAM volume; for example, half of it could be fine. Then, apply the new setting: ```bash sudo systemctl restart systemd-journald ``` This should shrink the size of "archived" logs to be below the newly imposed limit. Reboot and check that Log2Ram now works properly: ```bash sudo reboot ``` Wait until system reboots... ```bash systemctl status log2ram ``` ## Uninstallation :( (Because sometimes we need it) ### Via APT ```bash sudo apt remove log2ram ``` You can add the `--purge` argument to remove Log2Ram config files as well. ### Manually ```bash chmod +x /usr/local/bin/uninstall-log2ram.sh && sudo /usr/local/bin/uninstall-log2ram.sh ``` log2ram-1.7.2/ansible_playbook/000077500000000000000000000000001463237446000164125ustar00rootroot00000000000000log2ram-1.7.2/ansible_playbook/install_log2ram.yml000066400000000000000000000050511463237446000222270ustar00rootroot00000000000000#!/usr/bin/env ansible-playbook --- # Configure Raspberry Pi to log to RAM, with occasional SD card sync # to reduce SD card writes # Usage: ansible-playbook -e 'log2ram_size=80M' install_log2ram.yml - hosts: all gather_facts: true gather_subset: min become: true vars: log2ram_repo_url: http://packages.azlux.fr log2ram_gpg: https://azlux.fr/repo.gpg log2ram_keyring: /usr/share/keyrings/azlux-archive-keyring.gpg log2ram_apt_repository: "deb [signed-by={{ log2ram_keyring }}] {{ log2ram_repo_url }}/{{ ansible_distribution | lower }} {{ ansible_distribution_release }} main" log2ram_size: 128M log2ram_use_rsync: true log2ram_notification: true log2ram_notification_command: 'mail -s "Log2Ram Error on $HOSTNAME"' log2ram_path_disk: /var/log log2ram_use_z2lr: false log2ram_comp_alg: lz4 log2ram_log_disk_size: 256M tasks: - name: Add rsync as pre-requisite apt: name: rsync when: log2ram_use_rsync - name: Install GnuPG apt: name: gnupg - name: Add gpg key shell: cmd: > curl -fsSL {{ log2ram_gpg }} | gpg --dearmor --yes -o {{ log2ram_keyring }} creates: "{{ log2ram_keyring }}" - name: Add apt repository apt_repository: repo: "{{ log2ram_apt_repository }}" filename: log2ram register: log2ram_apt_repo - name: Update apt cache apt: update_cache: true when: log2ram_apt_repo is changed - name: Install log2ram apt: name: log2ram notify: Restart log2ram - name: Set config options lineinfile: path: /etc/log2ram.conf regexp: "{{ item.regexp }}" line: "{{ item.line }}" backrefs: true loop: - {regexp: '^SIZE=(.*)$', line: 'SIZE={{ log2ram_size }}'} - {regexp: 'USE_RSYNC=(.*)$', line: 'USE_RSYNC={{ log2ram_use_rsync }}'} - {regexp: '^NOTIFICATION=(.*)$', line: 'NOTIFICATION={{ log2ram_notification }}'} - {regexp: '^NOTIFICATION_COMMAND=(.*)$', line: 'NOTIFICATION_COMMAND={{ log2ram_notification_command }}'} - {regexp: '^PATH_DISK=(.*)$', line: 'PATH_DISK="{{ log2ram_path_disk }}"'} - {regexp: '^ZL2R=(.*)$', line: 'ZL2R={{ log2ram_use_z2lr|lower }}'} - {regexp: '^COMP_ALG=(.*)$', line: 'COMP_ALG={{ log2ram_comp_alg }}'} - {regexp: '^LOG_DISK_SIZE=(.*)$', line: 'LOG_DISK_SIZE={{ log2ram_log_disk_size }}'} notify: Restart log2ram handlers: - name: Restart log2ram systemd: name: log2ram state: restarted log2ram-1.7.2/build-packages.sh000077500000000000000000000025061463237446000163120ustar00rootroot00000000000000#!/usr/bin/env bash # Exit the script if any of the commands fail set -e set -u set -o pipefail # Set working directory to the location of this script cd "$(dirname "${BASH_SOURCE[0]}")" STARTDIR="$(pwd)" DESTDIR="$STARTDIR/pkg" OUTDIR="$STARTDIR/deb" # get version repo="azlux/log2ram" api=$(curl --silent "https://api.github.com/repos/$repo/releases" | jq ".[0]") new=$(echo $api | grep -Po '"tag_name": "\K.*?(?=")') # Remove potential leftovers from a previous build 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" # logrotate install -Dm 644 "$STARTDIR/log2ram.logrotate" "$DESTDIR/etc/logrotate.d/log2ram" # Build .deb mkdir "$DESTDIR/DEBIAN" "$OUTDIR" cp "$STARTDIR/debian/"* "$DESTDIR/DEBIAN/" # Set version sed -i "s/VERSION-TO-REPLACE/$new/" "$DESTDIR/DEBIAN/control" dpkg-deb --build "$DESTDIR" "$OUTDIR" log2ram-1.7.2/debian/000077500000000000000000000000001463237446000143175ustar00rootroot00000000000000log2ram-1.7.2/debian/conffiles000066400000000000000000000000221463237446000162040ustar00rootroot00000000000000/etc/log2ram.conf log2ram-1.7.2/debian/control000077500000000000000000000005061463237446000157260ustar00rootroot00000000000000Package: log2ram Version: VERSION-TO-REPLACE Depends: bash (>= 4.3) Section: net Priority: optional Architecture: all Maintainer: Azlux Description: ramlog like for systemd (Put log into a ram folder) Homepage: https://github.com/azlux/log2ram Bugs: https://github.com/azlux/log2ram/issues Recommends: rsync log2ram-1.7.2/debian/postinst000077500000000000000000000005361463237446000161340ustar00rootroot00000000000000#!/usr/bin/env bash set -euo pipefail systemctl daemon-reload systemctl enable log2ram.service log2ram-daily.timer rm -f /etc/cron.daily/log2ram rm -f /etc/cron.hourly/log2ram if [ "$1" == "configure" ]; then echo "##### Reboot to activate log2ram #####" echo "##### edit /etc/log2ram.conf to configure options ####" fi exit 0 log2ram-1.7.2/debian/preinst000077500000000000000000000003141463237446000157270ustar00rootroot00000000000000#!/usr/bin/env bash 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 log2ram-1.7.2/debian/prerm000077500000000000000000000006021463237446000153700ustar00rootroot00000000000000#!/usr/bin/env bash case "$1" in upgrade) [ -d /run/systemd/system/ ] && systemctl stop log2ram.service log2ram-daily.timer exit 0 ;; *) [ -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 log2ram-1.7.2/install.sh000077500000000000000000000023451463237446000151060ustar00rootroot00000000000000#!/usr/bin/env bash systemctl -q is-active log2ram && { echo "ERROR: log2ram service is still running. Please run \"sudo systemctl stop log2ram\" to stop it." exit 1 } [ "$(id -u)" -eq 0 ] || { echo "You need to be ROOT (sudo can be used)" exit 1 } # 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 if [ ! -f /etc/log2ram.conf ]; then install -m 644 log2ram.conf /etc/log2ram.conf fi install -m 644 uninstall.sh /usr/local/bin/uninstall-log2ram.sh systemctl enable log2ram.service log2ram-daily.timer # logrotate 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 # Make sure we start clean rm -rf /var/hdd.log echo "##### Reboot to activate log2ram #####" echo "##### edit /etc/log2ram.conf to configure options ####" log2ram-1.7.2/log2ram000077500000000000000000000120701463237446000143660ustar00rootroot00000000000000#!/usr/bin/env bash . /etc/log2ram.conf if [ -z "$PATH_DISK" ]; then PATH_DISK='/var/log' fi LOG_NAME='log2ram.log' NO_RSYNC=${USE_RSYNC#true} NOTIFICATION_COMMAND=${NOTIFICATION_COMMAND:=mail -s "Log2Ram Error on $HOSTNAME" root} NOTIFICATION=${NOTIFICATION:=true} ## @fn is_safe() ## @brief Check if hdd log exists is_safe() { [ -d "$HDD_LOG" ] || echo "ERROR: $HDD_LOG/ doesn't exist! Can't sync." [ -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() ## @brief Sync memory back to hard disk sync_to_disk() { is_safe optional_params=() 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 --sparse --inplace --no-whole-file --delete-after "${optional_params[@]}" "$RAM_LOG"/ "$HDD_LOG"/ 2>&1 | tee -a "$LOG2RAM_LOG" else cp -rfup --sparse=always "$RAM_LOG"/ -T "$HDD_LOG"/ 2>&1 | tee -a "$LOG2RAM_LOG" fi } ## @fn sync_from_disk() ## @brief Sync hard disk to memory sync_from_disk() { is_safe TP_SIZE=$SIZE if [ "$ZL2R" = true ]; then TP_SIZE=$LOG_DISK_SIZE fi if [ -n "$(du -sh -t "$TP_SIZE" "$HDD_LOG"/ | cut -f1)" ]; then echo "ERROR: RAM disk for \"$HDD_LOG/\" too small. Can't sync." echo -e "File(s) causing issues\n: $(du -sh -t "$TP_SIZE" "$HDD_LOG"/*)" umount -l "$RAM_LOG"/ umount -l "$HDD_LOG"/ if [ "$NOTIFICATION" = true ]; then echo "LOG2RAM : No place on RAM for \"$HDD_LOG/\" anymore, fallback on the disk" | $NOTIFICATION_COMMAND fi exit 1 fi if [ -z "${NO_RSYNC}" ] && [ -x "$(command -v rsync)" ]; then rsync -aXv --sparse --inplace --no-whole-file --delete-after "$HDD_LOG"/ "$RAM_LOG"/ 2>&1 | tee -a "$LOG2RAM_LOG" else cp -rfup --sparse=always "$HDD_LOG"/ -T "$RAM_LOG"/ 2>&1 | tee -a "$LOG2RAM_LOG" fi } ## @fn wait_for() ## @brief Wait for directory and create test file to make sure the directory exists ## @param param1 path to the directory wait_for() { WAIT_PATH="$1" while ! findmnt "$WAIT_PATH" >/dev/null; do sleep 0.1 done while [ ! -f "$WAIT_PATH/log2ram.test" ]; do touch "$WAIT_PATH/log2ram.test" sleep 0.1 done rm "$WAIT_PATH/log2ram.test" } ## @fn create_zram_log_drive() ## @brief Create zram log device create_zram_log_drive() { # Check Zram Class created if [ ! -d "/sys/class/zram-control" ]; then modprobe zram RAM_DEV='0' else RAM_DEV=$(cat /sys/class/zram-control/hot_add) fi 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}" } case "$1" in start) IFS=';' for i in $PATH_DISK; do # Skip the path if the folder doesn't exist [ ! -d "$i" ] && continue PATH_FIRST_PART="${i%/*}" PATH_LAST_PART="${i##/*/}" RAM_LOG="$i" HDD_LOG="${PATH_FIRST_PART}/hdd.${PATH_LAST_PART}" LOG2RAM_LOG="${RAM_LOG}/${LOG_NAME}" [ -d "$HDD_LOG" ] || mkdir "$HDD_LOG" mount --bind "$RAM_LOG"/ "$HDD_LOG"/ mount --make-private "$HDD_LOG"/ wait_for "$HDD_LOG" if [ "$ZL2R" = true ]; then create_zram_log_drive mount -t ext4 -o nosuid,noexec,noatime,nodev,user=log2ram "/dev/zram${RAM_DEV}" "$RAM_LOG"/ else mount -t tmpfs -o "nosuid,noexec,noatime,nodev,mode=0755,size=${SIZE}" log2ram "$RAM_LOG"/ fi wait_for "$RAM_LOG" sync_from_disk done exit 0 ;; stop) IFS=';' for i in $PATH_DISK; do PATH_FIRST_PART="${i%/*}" PATH_LAST_PART="${i##/*/}" RAM_LOG="$i" HDD_LOG="${PATH_FIRST_PART}/hdd.${PATH_LAST_PART}" LOG2RAM_LOG="${RAM_LOG}/${LOG_NAME}" sync_to_disk #ZRAM_LOG=$(awk '$2 == "/var/log" {print $1}' /proc/mounts) #ZRAM_LOG=$(echo ${ZRAM_LOG} | grep -o -E '[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 done exit 0 ;; write) IFS=';' for i in $PATH_DISK; do PATH_FIRST_PART="${i%/*}" PATH_LAST_PART="${i##/*/}" RAM_LOG="$i" HDD_LOG="${PATH_FIRST_PART}/hdd.${PATH_LAST_PART}" LOG2RAM_LOG="${RAM_LOG}/${LOG_NAME}" sync_to_disk done exit 0 ;; *) echo 'Usage: log2ram {start|stop|write}' >&2 exit 1 ;; esac log2ram-1.7.2/log2ram-daily.service000066400000000000000000000002051463237446000171170ustar00rootroot00000000000000[Unit] Description=Daily Log2Ram writing activities After=log2ram.service [Service] ExecStart=/bin/systemctl reload log2ram.service log2ram-1.7.2/log2ram-daily.timer000066400000000000000000000002111463237446000165740ustar00rootroot00000000000000[Unit] Description=Daily Log2Ram writing activities [Timer] OnCalendar=*-*-* 23:55:00 Persistent=true [Install] WantedBy=timers.target log2ram-1.7.2/log2ram.conf000066400000000000000000000073351463237446000153170ustar00rootroot00000000000000# Configuration file for Log2Ram (https://github.com/azlux/log2ram) under MIT license. # This configuration file is read by the log2ram service # Specify the amount of RAM reserved for storing logs. This setting determines the maximum size of the RAM folder. # Ensure 'SIZE=' is set larger than the current size of your /var/log directory to prevent startup failures. # Also, configure logrotate to manage log growth and prevent the /var/log directory from exceeding this reserved size. # The default setting of 128M suffices for many typical applications, but you may need to increase it for # servers or systems that generate extensive logging. SIZE=128M # Select the log syncing method between disk and RAM: # - 'rsync' is the default unless 'USE_RSYNC' is set to 'false'. # - If 'rsync' is unavailable, 'cp' is automatically used as a fallback. # - Set 'USE_RSYNC' to 'false' to explicitly use 'cp'. #USE_RSYNC=false # By default, if there is insufficient RAM space, a system notification email is sent. # Set this to 'false' to disable email notifications. (The error will still be logged locally). #NOTIFICATION=true # Specify the command for sending error notifications. # By default, it uses the `mail` command to send an email, with the message body provided via stdin. # You can replace this with any command (such as 'shoutrrr') or a custom script for handling notifications. #NOTIFICATION_COMMAND=mail -s "Log2Ram Error on $HOSTNAME" # Specify the directories to be stored in RAM. List each directory using its absolute path, e.g., `/path/folder`. # Corresponding directories on the HDD, named `/path/hdd.folder`, will be automatically created for each listed path. # Separate multiple paths with a semicolon `;` and do not include a trailing slash at the end of the paths. # Example: PATH_DISK="/var/log;/home/test/FolderInRam" 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 # Set to 'true' to enable log rotation for journald logs before syncing. # Note: 'rsync' must be used for this feature. # Ensure 'SystemMaxUse' is configured in 'journald.conf' # - (To limit journald’s disk usage to be smaller than the log2ram RAM allocation). JOURNALD_AWARE=true # **************** Zram backing conf **************** # Set ZL2R=true to enable zram, providing compressed RAM storage for log2ram. # Set ZL2R=false to use tmpfs, which provides uncompressed memory-only storage. ZL2R=false # Choose a compression algorithm from those listed in /proc/crypto. # 'lz4' is the fastest, offering the lightest CPU load but lower compression ratios. # 'deflate' (zlib) and 'Zstandard' (zstd) provide higher compression ratios but use more CPU. # 'lzo' is similar to 'lz4' but may perform better with certain binaries due to optimizations. # Set COMP_ALG to 'lz4' for speed, 'zstd' for better compression, or 'lzo' or 'zlib' if optimizations or availability are concerns. COMP_ALG=lz4 # LOG_DISK_SIZE specifies the uncompressed zram disk size. # (Sets the size of the zram disk that will be presented to the operating system). # To estimate amount of RAM this will consume, divide LOG_DISK_SIZE by your chosen compression algorithm's ratio: # - lzo/lz4 typically compresses at a ratio of 2.1:1 # - zlib compresses at about 2.7:1 # - zstandard (zstd) achieves around 2.9:1 # Example calculation using lz4: # Given LOG_DISK_SIZE = 256M (which represents 256 Megabytes of uncompressed log data), # the estimated zram RAM usage = 256 MB / 2.1 ≈ 122 MB of RAM. LOG_DISK_SIZE=256M log2ram-1.7.2/log2ram.logrotate000066400000000000000000000001411463237446000163560ustar00rootroot00000000000000/var/log/log2ram.log { rotate 7 daily missingok notifempty delaycompress compress } log2ram-1.7.2/log2ram.service000066400000000000000000000011031463237446000160150ustar00rootroot00000000000000[Unit] Description=Log2Ram DefaultDependencies=no Before=basic.target rsyslog.service syslog-ng.service syslog.target systemd-journald.service sysinit.target shutdown.target zram-swap-conf.service apache2.service lighttpd.service After=local-fs.target Conflicts=shutdown.target reboot.target halt.target RequiresMountsFor=/var/log /var/hdd.log IgnoreOnIsolate=yes [Service] Type=oneshot ExecStart=/usr/local/bin/log2ram start ExecStop=/usr/local/bin/log2ram stop ExecReload=/usr/local/bin/log2ram write TimeoutStartSec=120 RemainAfterExit=yes [Install] WantedBy=sysinit.target log2ram-1.7.2/uninstall.sh000077500000000000000000000013501463237446000154440ustar00rootroot00000000000000#!/usr/bin/env bash if dpkg -l log2ram 2>/dev/null; then echo "Please run : apt remove log2ram" exit 1 fi if [ "$(id -u)" -eq 0 ]; then echo "Not apt installed. Remove will continue with this script..." 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 -f /etc/logrotate.d/log2ram if [ -d /var/hdd.log ]; then rm -r /var/hdd.log fi echo "Log2Ram is uninstalled, removing the uninstaller in progress" rm /usr/local/bin/uninstall-log2ram.sh echo "##### Reboot isn't needed #####" else echo "You need to be ROOT (sudo can be used)" fi