This repository has been archived on 2025-09-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
nezha-nz-talon/tools/beforeinstall.sh
2023-04-26 17:39:53 +08:00

69 lines
1.7 KiB
Bash

#!/bin/bash
TALON_PATH=/opt/nezha/nz-talon
PROMTAIL_PATH=/opt/nezha/promtail
TELEGRAF_PATH=/opt/nezha/telegraf
service_exists(){
local n=$1
if [[ $(systemctl list-units --all -t service --full --no-legend "$n.service" | sed 's/^\s*//g' | cut -f1 -d' ') == $n.service ]]; then
return 0
else
return 1
fi
}
if [ 2 -eq $1 ];then
if [ ! -d ${TALON_PATH}/config ];then
exit 0
fi
systemctl stop nz-talon
# nz-telegraf.service
if service_exists nz-telegraf; then
systemctl stop nz-telegraf
fi
# promtail.service, deprecated
if service_exists promtail; then
systemctl stop promtail
systemctl disable promtail
rm /usr/lib/systemd/system/promtail.service
systemctl daemon-reload
systemctl reset-failed
fi
# nz-promtail.service
if service_exists nz-promtail; then
systemctl stop nz-promtail
fi
TMP_PATH=/tmp/nezha/nz-talon
rm -rf $TMP_PATH
mkdir -p $TMP_PATH
mkdir -p $TMP_PATH/promtail
mkdir -p $TMP_PATH/telegraf
cp -rf $TALON_PATH/config $TMP_PATH
[ -f "$PROMTAIL_PATH/promtail.yaml" ] && cp -rf $PROMTAIL_PATH/promtail.yaml $TMP_PATH/promtail
[ -f "$PROMTAIL_PATH/config.conf" ] && cp -rf $PROMTAIL_PATH/config.conf $TMP_PATH/promtail
[ -f "$TELEGRAF_PATH/config.conf" ] && cp -rf $TELEGRAF_PATH/config.conf $TMP_PATH/telegraf
[ -f "$TELEGRAF_PATH/telegraf.conf" ] && cp -rf $TELEGRAF_PATH/telegraf.conf $TMP_PATH/telegraf
[ -d "$TELEGRAF_PATH/telegraf.d" ] && cp -rf $TELEGRAF_PATH/telegraf.d $TMP_PATH/telegraf
echo 'backup config file from '${TALON_PATH}
if [ 0 -lt $(rpm -aq nz-talon|wc -w) ];then
echo 'clean before install...'
rm -rf $TALON_PATH
rm -rf $PROMTAIL_PATH
rm -rf $TELEGRAF_PATH
fi
fi