summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshizhendong <[email protected]>2023-09-04 15:45:02 +0800
committershizhendong <[email protected]>2023-09-04 15:45:02 +0800
commit665daa1107f2cf776ecdfc59572ccc3efbec84d6 (patch)
tree964c0549ca15517929b96b29eec4e2714955e94d
parentbff7a87e512850aabedd9299b02c41dcf67c5dbf (diff)
feat: NEZ-3158 nz-talon 内置组件增加 rsyslog&logrotate 配置rel-23.07.02
-rw-r--r--tools/afterinstall.sh49
-rw-r--r--tools/afterremove.sh3
2 files changed, 52 insertions, 0 deletions
diff --git a/tools/afterinstall.sh b/tools/afterinstall.sh
index 77eac1d..56ddda5 100644
--- a/tools/afterinstall.sh
+++ b/tools/afterinstall.sh
@@ -12,6 +12,45 @@ service_exists(){
fi
}
+# 初始化 rsyslog & logrotate 配置
+fn_init_syslog_logrotate_config(){
+# promtail
+ cat > /etc/rsyslog.d/promtail.conf << "EOF"
+if $programname == 'promtail' then {
+ /var/log/nezha/promtail/promtail.log
+ stop
+}
+EOF
+ cat > /etc/logrotate.d/promtail << "EOF"
+/var/log/nezha/promtail/*.log {
+ daily
+ missingok
+ maxsize 100M
+ rotate 7
+ copytruncate
+ compress
+}
+EOF
+
+# telegraf
+ cat > /etc/rsyslog.d/telegraf.conf << "EOF"
+if $programname == 'telegraf' then {
+ /var/log/nezha/telegraf/telegraf.log
+ stop
+}
+EOF
+ cat > /etc/logrotate.d/telegraf << "EOF"
+/var/log/nezha/telegraf/*.log {
+ daily
+ missingok
+ maxsize 100M
+ rotate 7
+ copytruncate
+ compress
+}
+EOF
+}
+
compareMD5(){
if [ ! -f $1 ] || [ ! -f $2 ];then
echo 1
@@ -116,10 +155,14 @@ LimitMEMLOCK=8M:8M
WantedBy=multi-user.target
EOF
+ fn_init_syslog_logrotate_config
+
systemctl daemon-reload
systemctl enable nz-talon && systemctl restart nz-talon
systemctl enable nz-promtail && systemctl restart nz-promtail
systemctl enable nz-telegraf && systemctl restart nz-telegraf
+ systemctl enable crond && systemctl restart crond
+ systemctl enable rsyslog && systemctl restart rsyslog
echo 'install nz-talon success !'
fi
@@ -148,7 +191,13 @@ if [ 2 -eq $1 ];then
restoreComponentConfig $TELEGRAF_PATH/telegraf.d $TMP_PATH/telegraf/telegraf.d
fi
fi
+
+ fn_init_syslog_logrotate_config
+
+ systemctl daemon-reload
systemctl restart nz-talon
+ systemctl enable crond && systemctl restart crond
+ systemctl enable rsyslog && systemctl restart rsyslog
# nz-promtail.service
if service_exists nz-promtail; then
diff --git a/tools/afterremove.sh b/tools/afterremove.sh
index db73c86..4e15855 100644
--- a/tools/afterremove.sh
+++ b/tools/afterremove.sh
@@ -37,8 +37,11 @@ if [ 0 -eq $1 ];then
fi
rm -rf /usr/lib/systemd/system/{nz-talon.service,promtail.service,nz-promtail.service,nz-telegraf.service}
+ rm -rf /etc/rsyslog.d/{promtail.conf,telegraf.conf}
+ rm -rf /etc/logrotate.d/{promtail,telegraf}
systemctl daemon-reload
+ systemctl restart rsyslog
echo 'uninstall success!'
fi