From b62992f21e4b6d23f5a25999c26d91f550800081 Mon Sep 17 00:00:00 2001 From: Ruakij Date: Fri, 9 Oct 2026 12:53:44 +0000 Subject: [PATCH] Cap the systemd journal at 512M on disk, 128M in memory and two weeks in the common role --- common/defaults/main.yml | 6 ++++++ common/handlers/main.yml | 5 +++++ common/tasks/journald.yml | 17 +++++++++++++++++ common/tasks/main.yml | 3 +++ 4 files changed, 31 insertions(+) create mode 100644 common/tasks/journald.yml diff --git a/common/defaults/main.yml b/common/defaults/main.yml index 7a45106..2b7b554 100755 --- a/common/defaults/main.yml +++ b/common/defaults/main.yml @@ -6,3 +6,9 @@ disk_maintenance: fstrim_on_calendar: # Cron "minute hour" of the monthly ZFS trim and scrub from zfsutils-linux; unset keeps 00:24. zfs_cron_time: + +# journald.conf [Journal] settings of a drop-in, in this order; null leaves journald untouched. +journald_size_cap: + SystemMaxUse: 512M + RuntimeMaxUse: 128M + MaxRetentionSec: 2week diff --git a/common/handlers/main.yml b/common/handlers/main.yml index 7ee7465..e77d0ef 100644 --- a/common/handlers/main.yml +++ b/common/handlers/main.yml @@ -1,2 +1,7 @@ - name: reload_sysctl command: sysctl --system + +- name: restart_journald + systemd: + name: systemd-journald + state: restarted diff --git a/common/tasks/journald.yml b/common/tasks/journald.yml new file mode 100644 index 0000000..8ce9d05 --- /dev/null +++ b/common/tasks/journald.yml @@ -0,0 +1,17 @@ +- name: Cap the journal size + when: journald_size_cap | default(none) is not none + block: + - name: Create the journald drop-in directory + file: + path: /etc/systemd/journald.conf.d + state: directory + + - name: Set the journal size cap + copy: + dest: /etc/systemd/journald.conf.d/10-size-cap.conf + content: | + [Journal] + {% for key, value in journald_size_cap.items() %} + {{ key }}={{ value }} + {% endfor %} + notify: restart_journald diff --git a/common/tasks/main.yml b/common/tasks/main.yml index ec2b032..4657896 100755 --- a/common/tasks/main.yml +++ b/common/tasks/main.yml @@ -11,3 +11,6 @@ - import_tasks: ./networking.yml - import_tasks: ./disk_maintenance.yml + +- import_tasks: ./journald.yml + tags: journald