set logrotate

This commit is contained in:
shixuantong 2024-12-11 16:10:45 +08:00
parent 23812cba17
commit eb22893572
2 changed files with 111 additions and 4 deletions

92
set-logrotate.patch Normal file
View File

@ -0,0 +1,92 @@
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

View File

@ -4,7 +4,7 @@
Summary: System Inspection Framework
Name: sysSentry
Version: 1.0.2
Release: 64
Release: 65
License: Mulan PSL v2
Group: System Environment/Daemons
Source0: https://gitee.com/openeuler/sysSentry/releases/download/v%{version}/%{name}-%{version}.tar.gz
@ -86,6 +86,7 @@ Patch73: make-debug-msg-clear.patch
Patch74: add-boundary-check-for-settings.patch
Patch75: change-status-of-period-task-and-sort-mod-file.patch
Patch76: uniform-avg_block_io-log-and-ai_block_io-log.patch
Patch77: set-logrotate.patch
BuildRequires: cmake gcc-c++
BuildRequires: python3 python3-setuptools
@ -213,12 +214,10 @@ install config/tasks/rasdaemon.mod %{buildroot}/etc/sysSentry/tasks/
# xalarm
sh build/build.sh -i %{buildroot}%{_libdir}
mkdir -p %{buildroot}%{_sysconfdir}/logrotate.d
install -m 600 config/xalarm.conf %{buildroot}%{_sysconfdir}/sysSentry
install -d %{buildroot}%{_libdir}
install -d %{buildroot}%{_includedir}/xalarm
install -m 600 service/xalarmd.service %{buildroot}%{_unitdir}
install -m 600 config/logrotate %{buildroot}%{_sysconfdir}/logrotate.d/sysSentry
install -m 644 src/libso/xalarm/register_xalarm.h %{buildroot}%{_includedir}/xalarm/register_xalarm.h
# sentryCollector
@ -248,6 +247,12 @@ install config/tasks/hbm_online_repair.mod %{buildroot}/etc/sysSentry/tasks/
install src/c/hbm_online_repair/hbm_online_repair %{buildroot}%{_bindir}
install src/c/hbm_online_repair/hbm_online_repair.env %{buildroot}/etc/sysconfig/hbm_online_repair.env
# logrotate
mkdir -p %{buildroot}%{_localstatedir}/lib/logrotate-syssentry
mkdir -p %{buildroot}%{_sysconfdir}/cron.hourly
install -m 0600 config/logrotate-sysSentry.conf %{buildroot}%{_sysconfdir}/logrotate-sysSentry.conf
install -m 0500 src/sh/logrotate-sysSentry.cron %{buildroot}%{_sysconfdir}/cron.hourly/logrotate-sysSentry
pushd src/python
python3 setup.py install -O1 --root=$RPM_BUILD_ROOT --record=SENTRY_FILES
cat SENTRY_FILES | grep -v register_xalarm.* | grep -v sentry_notify.* > SENTRY_FILES.tmp
@ -298,10 +303,14 @@ rm -rf %{buildroot}
# xalarm
%attr(0550,root,root) %{_bindir}/xalarmd
%attr(0600,root,root) %config(noreplace) %{_sysconfdir}/logrotate.d/sysSentry
%attr(0600,root,root) %config(noreplace) %{_sysconfdir}/sysSentry/xalarm.conf
%attr(0600,root,root) %{_unitdir}/xalarmd.service
# logrotate
%dir %{_localstatedir}/lib/logrotate-syssentry
%attr(0600,root,root) %config(noreplace) %{_sysconfdir}/logrotate-sysSentry.conf
%attr(0500,root,root) %{_sysconfdir}/cron.hourly/logrotate-sysSentry
# cpu inspection module
%exclude %{_sysconfdir}/sysSentry/tasks/cpu_sentry.mod
%exclude %{_sysconfdir}/sysSentry/plugins/cpu_sentry.ini
@ -383,6 +392,12 @@ rm -rf %{buildroot}
%attr(0550,root,root) %{python3_sitelib}/syssentry/bmc_alarm.py
%changelog
* Wed Dec 18 2024 shixuantong <shixuantong@huawei.com> - 1.0.2-65
- Type:enhancement
- CVE:NA
- SUG:NA
- DESC:set logrotate
* Wed Dec 18 2024 jinsaihang <jinsaihang@h-partners.com> - 1.0.2-64
- Type:bugfix
- CVE:NA