It will clean log files of qemu processes that are outdated. Here it means that VM where not active for given amount time (currently hardcoded to a month). --- src/logging/meson.build | 15 +++++++++++++++ src/logging/virtlogcleaner.service.in | 7 +++++++ src/logging/virtlogcleaner.sh | 9 +++++++++ src/logging/virtlogcleaner.timer | 8 ++++++++ src/logging/virtlogd.service.in | 1 + 5 files changed, 40 insertions(+) create mode 100644 src/logging/virtlogcleaner.service.in create mode 100755 src/logging/virtlogcleaner.sh create mode 100644 src/logging/virtlogcleaner.timer diff --git a/src/logging/meson.build b/src/logging/meson.build index 7066f16fad..d23f51b9fd 100644 --- a/src/logging/meson.build +++ b/src/logging/meson.build @@ -101,6 +101,21 @@ if conf.has('WITH_LIBVIRTD') 'name': 'virtlogd', 'in_file': files('virtlogd.init.in'), } + + if init_script == 'systemd' + systemd_unit_dir = prefix / 'lib' / 'systemd' / 'system' + + configure_file( + input: 'virtlogcleaner.service.in', + output: 'virtlogcleaner.service', + configuration: configuration_data({'sbindir': sbindir}), + install: true, + install_dir: systemd_unit_dir, + ) + + install_data('virtlogcleaner.timer', install_dir: systemd_unit_dir) + install_data('virtlogcleaner.sh', install_dir: sbindir) + endif endif log_inc_dir = include_directories('.') diff --git a/src/logging/virtlogcleaner.service.in b/src/logging/virtlogcleaner.service.in new file mode 100644 index 0000000000..1d1ff2b121 --- /dev/null +++ b/src/logging/virtlogcleaner.service.in @@ -0,0 +1,7 @@ +[Unit] +Description=Virtual machine log cleaner +Documentation=https://libvirt.org + +[Service] +Type=oneshot +ExecStart=@sbindir@/virtlogcleaner.sh diff --git a/src/logging/virtlogcleaner.sh b/src/logging/virtlogcleaner.sh new file mode 100755 index 0000000000..21ddefb15a --- /dev/null +++ b/src/logging/virtlogcleaner.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +logdir=/var/log/libvirt/qemu + +cd "$logdir" +find . -mtime +30 -name "*.log" | while read file +do + find . -regex "$file.[0-9]*" -delete && rm "$file" +done diff --git a/src/logging/virtlogcleaner.timer b/src/logging/virtlogcleaner.timer new file mode 100644 index 0000000000..a916f05f87 --- /dev/null +++ b/src/logging/virtlogcleaner.timer @@ -0,0 +1,8 @@ +[Unit] +Description=Periodic cleanup of virtual machine logs +Documentation=https://libvirt.org + +[Timer] +OnCalendar=daily +AccuracySec=1h +Persistent=true diff --git a/src/logging/virtlogd.service.in b/src/logging/virtlogd.service.in index 8ab5478517..e1883b73be 100644 --- a/src/logging/virtlogd.service.in +++ b/src/logging/virtlogd.service.in @@ -2,6 +2,7 @@ Description=Virtual machine log manager Requires=virtlogd.socket Requires=virtlogd-admin.socket +Requires=virtlogcleaner.timer Before=libvirtd.service Documentation=man:virtlogd(8) Documentation=https://libvirt.org -- 2.31.1