sysSentry/set-logrotate.patch

93 lines
2.3 KiB
Diff
Raw Normal View History

2024-12-11 16:10:45 +08:00
From d74076f4b772822de4f5bee1c8a778dd6b1771d2 Mon Sep 17 00:00:00 2001
From: shixuantong <shixuantong1@huawei.com>
Date: Wed, 11 Dec 2024 15:25:33 +0800
Subject: [PATCH] set logrotate
---
config/logrotate | 9 ---------
config/logrotate-sysSentry.conf | 35 +++++++++++++++++++++++++++++++++
src/sh/logrotate-sysSentry.cron | 13 ++++++++++++
3 files changed, 48 insertions(+), 9 deletions(-)
delete mode 100644 config/logrotate
create mode 100644 config/logrotate-sysSentry.conf
create mode 100644 src/sh/logrotate-sysSentry.cron
diff --git a/config/logrotate b/config/logrotate
deleted file mode 100644
index 3dc77f5..0000000
--- a/config/logrotate
+++ /dev/null
@@ -1,9 +0,0 @@
-/var/log/sysSentry/*.log {
- compress
- missingok
- notifempty
- copytruncate
- rotate 2
- size +4096k
- hourly
-}
diff --git a/config/logrotate-sysSentry.conf b/config/logrotate-sysSentry.conf
new file mode 100644
index 0000000..cf5f994
--- /dev/null
+++ b/config/logrotate-sysSentry.conf
@@ -0,0 +1,35 @@
+# keep 4 hours worth of backlogs
+rotate 4
+
+# create new (empty) log files after rotating old ones
+create
+
+# compress log files
+compress
+
+# if a log file does not exist, go no to the next one without an error msg
+missingok
+
+# do not rotate the log if it is empty
+notifempty
+
+copytruncate
+
+# ignore any following matches of a log file.
+# Note that order is significant, it will not overwrite and take the first match.
+# require logrotate >= 3.21.0
+ignoreduplicates
+
+/var/log/sysSentry/sysSentry.log {
+ rotate 8
+ size +4096k
+}
+
+/var/log/sysSentry/cpu_sentry.log {
+ rotate 2
+ size +2048k
+}
+
+/var/log/sysSentry/*.log {
+ size +4096k
+}
diff --git a/src/sh/logrotate-sysSentry.cron b/src/sh/logrotate-sysSentry.cron
new file mode 100644
index 0000000..64d02f9
--- /dev/null
+++ b/src/sh/logrotate-sysSentry.cron
@@ -0,0 +1,13 @@
+#!/bin/sh
+
+TMPF=`mktemp /tmp/logrotate-sysSentry.XXXXXXXXX`
+
+/usr/sbin/logrotate /etc/logrotate-sysSentry.conf -v --log=$TMPF -s /var/lib/logrotate-syssentry/logrotate.status
+EXITVALUE=$?
+if [ $EXITVALUE != 0 ]; then
+ /bin/logger -t logrotate "ALERT exited abnormally with [$EXITVALUE], for details, see /var/log/sysSentry/logrotate.log"
+ /bin/logger -t logrotate -f $TMPF
+fi
+rm -rf $TMPF
+rm -rf /var/lib/logrotate-syssentry/logrotate.status
+exit $EXITVALUE
--
2.27.0