Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmake/project.cmake
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions debian.native/elos-plugin-backend-json.install
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
usr/lib/*/elos/backend/backend_json.so
usr/bin/elos_log_cleanup
5 changes: 5 additions & 0 deletions src/plugins/storagebackends/jsonbackend/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
61 changes: 61 additions & 0 deletions src/plugins/storagebackends/jsonbackend/elos_log_cleanup.sh
Original file line number Diff line number Diff line change
@@ -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 <NUMBER> keep NUMBER log files and delete the rest (default 10)
-H, --host <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
5 changes: 5 additions & 0 deletions src/plugins/storagebackends/jsonbackend/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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