From 47faa3296f888c8667ad7ec3bd409a39352c14a5 Mon Sep 17 00:00:00 2001
From: Evangelos Foutras <evangelos@foutrelis.com>
Date: Sat, 12 Mar 2022 20:14:42 +0200
Subject: [PATCH] common: use drop-ins for {journald,system}.conf

Keeps us from having to deal with .pacnew files.
---
 roles/common/tasks/main.yml             | 14 ++++--
 roles/common/templates/journald.conf.j2 | 39 ----------------
 roles/common/templates/system.conf.j2   | 62 -------------------------
 3 files changed, 9 insertions(+), 106 deletions(-)

diff --git a/roles/common/tasks/main.yml b/roles/common/tasks/main.yml
index d55eb7b7c..c9febbb1b 100644
--- a/roles/common/tasks/main.yml
+++ b/roles/common/tasks/main.yml
@@ -84,15 +84,19 @@
     sysctl_file: /etc/sysctl.d/net.conf
   when: tcp_wmem is defined
 
-- name: configure journald
-  template: src={{ item }}.j2 dest=/etc/systemd/{{ item }} owner=root group=root mode=644
-  with_items:
+- name: create drop-in directories for systemd configuration
+  file: path=/etc/systemd/{{ item }}.d state=directory owner=root group=root mode=0755
+  loop:
+    - system.conf
     - journald.conf
+
+- name: install journald.conf overrides
+  template: src=journald.conf.j2 dest=/etc/systemd/journald.conf.d/override.conf owner=root group=root mode=644
   notify:
     - restart journald
 
-- name: install system.conf
-  template: src=system.conf.j2 dest=/etc/systemd/system.conf owner=root group=root mode=0644
+- name: install system.conf overrides
+  template: src=system.conf.j2 dest=/etc/systemd/system.conf.d/override.conf owner=root group=root mode=0644
   notify:
     - systemd daemon-reload
 
diff --git a/roles/common/templates/journald.conf.j2 b/roles/common/templates/journald.conf.j2
index c1094d858..0ec5b3013 100644
--- a/roles/common/templates/journald.conf.j2
+++ b/roles/common/templates/journald.conf.j2
@@ -1,43 +1,4 @@
-#  This file is part of systemd.
-#
-#  systemd is free software; you can redistribute it and/or modify it
-#  under the terms of the GNU Lesser General Public License as published by
-#  the Free Software Foundation; either version 2.1 of the License, or
-#  (at your option) any later version.
-#
-# Entries in this file show the compile time defaults.
-# You can change settings by editing this file.
-# Defaults can be restored by simply deleting this file.
-#
-# See journald.conf(5) for details.
-
 [Journal]
-#Storage=auto
-#Compress=yes
-#Seal=yes
-#SplitMode=uid
-#SyncIntervalSec=5m
-#RateLimitIntervalSec=30s
 RateLimitBurst=100000
-#SystemMaxUse=
-#SystemKeepFree=
-#SystemMaxFileSize=
 SystemMaxFiles=10000
-#RuntimeMaxUse=
-#RuntimeKeepFree=
-#RuntimeMaxFileSize=
-#RuntimeMaxFiles=100
-#MaxRetentionSec=
-#MaxFileSec=1month
-#ForwardToSyslog=no
-#ForwardToKMsg=no
-#ForwardToConsole=no
 ForwardToWall=no
-#TTYPath=/dev/console
-#MaxLevelStore=debug
-#MaxLevelSyslog=debug
-#MaxLevelKMsg=notice
-#MaxLevelConsole=info
-#MaxLevelWall=emerg
-#LineMax=48K
-#ReadKMsg=yes
diff --git a/roles/common/templates/system.conf.j2 b/roles/common/templates/system.conf.j2
index 7c8cdf8aa..0cb1eb782 100644
--- a/roles/common/templates/system.conf.j2
+++ b/roles/common/templates/system.conf.j2
@@ -1,64 +1,2 @@
-#  This file is part of systemd.
-#
-#  systemd is free software; you can redistribute it and/or modify it
-#  under the terms of the GNU Lesser General Public License as published by
-#  the Free Software Foundation; either version 2.1 of the License, or
-#  (at your option) any later version.
-#
-# Entries in this file show the compile time defaults.
-# You can change settings by editing this file.
-# Defaults can be restored by simply deleting this file.
-#
-# See systemd-system.conf(5) for details.
-
 [Manager]
-#LogLevel=info
-#LogTarget=journal-or-kmsg
-#LogColor=yes
-#LogLocation=no
-#DumpCore=yes
-#ShowStatus=yes
-#CrashChangeVT=no
-#CrashShell=no
-#CrashReboot=no
-#CtrlAltDelBurstAction=reboot-force
-#CPUAffinity=1 2
 RuntimeWatchdogSec=5min
-#ShutdownWatchdogSec=10min
-#WatchdogDevice=
-#CapabilityBoundingSet=
-#NoNewPrivileges=no
-#SystemCallArchitectures=
-#TimerSlackNSec=
-#DefaultTimerAccuracySec=1min
-#DefaultStandardOutput=journal
-#DefaultStandardError=inherit
-#DefaultTimeoutStartSec=90s
-#DefaultTimeoutStopSec=90s
-#DefaultRestartSec=100ms
-#DefaultStartLimitIntervalSec=10s
-#DefaultStartLimitBurst=5
-#DefaultEnvironment=
-DefaultCPUAccounting=yes
-DefaultIOAccounting=no
-DefaultIPAccounting=no
-DefaultBlockIOAccounting=no
-DefaultMemoryAccounting=yes
-DefaultTasksAccounting=yes
-#DefaultTasksMax=15%
-#DefaultLimitCPU=
-#DefaultLimitFSIZE=
-#DefaultLimitDATA=
-#DefaultLimitSTACK=
-#DefaultLimitCORE=
-#DefaultLimitRSS=
-#DefaultLimitNOFILE=1024:524288
-#DefaultLimitAS=
-#DefaultLimitNPROC=
-#DefaultLimitMEMLOCK=
-#DefaultLimitLOCKS=
-#DefaultLimitSIGPENDING=
-#DefaultLimitMSGQUEUE=
-#DefaultLimitNICE=
-#DefaultLimitRTPRIO=
-#DefaultLimitRTTIME=
-- 
GitLab