From 3a4b59a7efd7aeb83beb113f4c84f001ce9dbbaa Mon Sep 17 00:00:00 2001 From: Friedrich Schwedler Date: Tue, 2 Dec 2025 13:23:41 +0100 Subject: [PATCH 1/2] feat: add script to cleanupd json log files --- .../elos-plugin-backend-json.install | 1 + .../jsonbackend/CMakeLists.txt | 5 ++ .../jsonbackend/elos_log_cleanup.sh | 61 +++++++++++++++++++ .../storagebackends/jsonbackend/index.rst | 5 ++ 4 files changed, 72 insertions(+) create mode 100755 src/plugins/storagebackends/jsonbackend/elos_log_cleanup.sh diff --git a/debian.native/elos-plugin-backend-json.install b/debian.native/elos-plugin-backend-json.install index cf6907be..b4c633b6 100644 --- a/debian.native/elos-plugin-backend-json.install +++ b/debian.native/elos-plugin-backend-json.install @@ -1 +1,2 @@ usr/lib/*/elos/backend/backend_json.so +usr/bin/elos_log_cleanup diff --git a/src/plugins/storagebackends/jsonbackend/CMakeLists.txt b/src/plugins/storagebackends/jsonbackend/CMakeLists.txt index 5e86a4bb..21689b1b 100644 --- a/src/plugins/storagebackends/jsonbackend/CMakeLists.txt +++ b/src/plugins/storagebackends/jsonbackend/CMakeLists.txt @@ -38,6 +38,11 @@ target_link_libraries( if (INSTALL_ELOS_PLUGINS) install(TARGETS backend_json DESTINATION ${ELOSD_BACKEND_PATH}) + install( + PROGRAMS elos_log_cleanup.sh + DESTINATION ${CMAKE_INSTALL_BINDIR} + RENAME elos_log_cleanup + ) endif() create_static_library_from_shared( diff --git a/src/plugins/storagebackends/jsonbackend/elos_log_cleanup.sh b/src/plugins/storagebackends/jsonbackend/elos_log_cleanup.sh new file mode 100755 index 00000000..e9ab4f2b --- /dev/null +++ b/src/plugins/storagebackends/jsonbackend/elos_log_cleanup.sh @@ -0,0 +1,61 @@ +#!/bin/sh +# SPDX-License-Identifier: MIT +############################################################################### +print_info() { + SCRIPT_NAME="${0##*/}" + echo " +Removes all but the last N elosd json log files + +Usage: ${SCRIPT_NAME} [OPTIONS] [STORAGE_PATH] + +Options: + -k, --keep keep NUMBER log files and delete the rest (default 10) + -H, --host only delete logs with that specified host id + -d, --dryrun don't delete anything just show what would be kept + -h, --help print this help + +Examples: + ${SCRIPT_NAME} # delete all files matching the pattern \"/tmp/elosd_*_*_*.log\" + ${SCRIPT_NAME} -k 1 # only keep the currently active log file +" +} +############################################################################### +set -eu + +STORAGE_PATH="/tmp/elosd_%host%_%date%_%count%.log" +HOST="*" +KEEP="10" +DRYRUN=0 + +while [ $# -gt 0 ]; do + case ${1} in + --keep | -k) KEEP="${2}"; shift ;; + --host | -H) HOST="${2}"; shift ;; + --dryrun | -d) DRYRUN=1 ;; + --help | -h) + print_info + exit 0 + ;; + -*) + echo "error: unknown option: ${1}" + print_info + exit 1 + ;; + *) STORAGE_PATH="${1}" ;; + esac + shift +done + +STORAGE_PATH="$(echo "${STORAGE_PATH}" | sed -e "s/%host%/${HOST}/g" -e 's/%date%/*/g' -e 's/%count%/*/g')" + +if [ "${DRYRUN}" -ne 0 ]; then + echo "# Keeping:" + ls -1t ${STORAGE_PATH} | head -n 10 +fi + +KEEP=$(($KEEP + 1)) +if [ "${DRYRUN}" -eq 0 ]; then + for log in $(ls -1t ${STORAGE_PATH} | tail -n "+${KEEP}"); do + rm "${log}" + done +fi diff --git a/src/plugins/storagebackends/jsonbackend/index.rst b/src/plugins/storagebackends/jsonbackend/index.rst index cf00d980..0968fda4 100644 --- a/src/plugins/storagebackends/jsonbackend/index.rst +++ b/src/plugins/storagebackends/jsonbackend/index.rst @@ -93,4 +93,9 @@ If PathSizeLimit itself is not set, it will default to 1024. This value can be changed by defining ``ELOS_JSON_LOGGING_PATH_LIMIT_DEFAULT`` at compile time. +Log Cleanup +----------- +To help with cleaning up old log files a small helper program is provided that deletes all but the newest few log files. + +.. program-output:: elos_log_cleanup --help From a9308e99354475e8a02f3083283f25bf759d60a6 Mon Sep 17 00:00:00 2001 From: Armin Butscher Date: Thu, 4 Dec 2025 13:30:13 +0100 Subject: [PATCH 2/2] elos: Update to 1.41.0 --- cmake/project.cmake | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/project.cmake b/cmake/project.cmake index 419a36ab..faf7eb68 100644 --- a/cmake/project.cmake +++ b/cmake/project.cmake @@ -1,5 +1,5 @@ # SPDX-License-Identifier: MIT -set(ELOS_VERSION 1.40.13) +set(ELOS_VERSION 1.41.0) # Attention: Aside from the version, as many things as possible in this file # should be put into functions, as this solves potential issues with commands