#!/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 systemctl stop nz-telegraf # promtail.service, deprecated if service_exists promtail; then echo 'service promtail exists, close the service' 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