From ae30e95ff8753cb9ca8f7469d0f4382cae19ce17 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Tue, 2 Feb 2021 22:23:56 +0000
Subject: [PATCH] Clear up some unaccounted process logs

---
 roles/autoradio/files/icecast2.cron      |  3 +++
 roles/autoradio/files/icecast2.logrotate | 12 ------------
 roles/autoradio/files/mtail.logrotate    | 12 ++++++++++++
 roles/autoradio/tasks/main.yml           | 10 +++++-----
 roles/autoradio/tasks/mtail.yml          |  5 +++++
 5 files changed, 25 insertions(+), 17 deletions(-)
 create mode 100644 roles/autoradio/files/icecast2.cron
 delete mode 100644 roles/autoradio/files/icecast2.logrotate
 create mode 100644 roles/autoradio/files/mtail.logrotate

diff --git a/roles/autoradio/files/icecast2.cron b/roles/autoradio/files/icecast2.cron
new file mode 100644
index 0000000..a0d8216
--- /dev/null
+++ b/roles/autoradio/files/icecast2.cron
@@ -0,0 +1,3 @@
+MAILTO=""
+7 5 * * * root find /var/log/icecast2/ -type f -mtime +7 -delete
+
diff --git a/roles/autoradio/files/icecast2.logrotate b/roles/autoradio/files/icecast2.logrotate
deleted file mode 100644
index 0f41d96..0000000
--- a/roles/autoradio/files/icecast2.logrotate
+++ /dev/null
@@ -1,12 +0,0 @@
-/var/log/icecast2/*.log {
-	daily
-	missingok
-	rotate 1
-	postrotate
-		if pgrep icecast2 >/dev/null; then
-			invoke-rc.d --quiet icecast2 reload > /dev/null
-		fi
-	endscript
-	compress
-	notifempty
-}
diff --git a/roles/autoradio/files/mtail.logrotate b/roles/autoradio/files/mtail.logrotate
new file mode 100644
index 0000000..9882446
--- /dev/null
+++ b/roles/autoradio/files/mtail.logrotate
@@ -0,0 +1,12 @@
+/var/log/mtail/mtail.log {
+	daily
+	missingok
+	rotate 1
+	postrotate
+		if pgrep mtail >/dev/null; then
+			invoke-rc.d --quiet mtail restart > /dev/null
+		fi
+	endscript
+	compress
+	notifempty
+}
diff --git a/roles/autoradio/tasks/main.yml b/roles/autoradio/tasks/main.yml
index af5c52d..e94692a 100644
--- a/roles/autoradio/tasks/main.yml
+++ b/roles/autoradio/tasks/main.yml
@@ -18,11 +18,6 @@
 - include_tasks: local_install.yml
   when: "source_repository_path is defined"
 
-- name: Set up icecast logrotate policy
-  copy:
-    src: icecast2.logrotate
-    dest: /etc/logrotate.d/icecast2
-
 - name: Set up icecast static files
   copy:
     src: "icecast/{{ item }}"
@@ -58,6 +53,11 @@
     dest: /etc/cron.d/autoradio-backup
   when: "backup_repository is defined"
 
+- name: Setup icecast log clearing cron job
+  copy:
+    src: "icecast2.cron"
+    dest: "/etc/cron.d/icecast2"
+
 - import_tasks: mtail.yml
 
 - name: Install ip block script
diff --git a/roles/autoradio/tasks/mtail.yml b/roles/autoradio/tasks/mtail.yml
index bd88359..4917faf 100644
--- a/roles/autoradio/tasks/mtail.yml
+++ b/roles/autoradio/tasks/mtail.yml
@@ -11,6 +11,11 @@
     dest: "/etc/default/mtail"
   notify: "restart mtail"
 
+- name: Install mtail logrotate config
+  copy:
+    src: "mtail.logrotate"
+    dest: "/etc/logrotate.d/mtail"
+
 - name: Install mtail programs
   copy:
     src: "icecast2.mtail"
-- 
GitLab