#!/usr/bin/env bash set +u set -e base_dir=$( cd "$(dirname "$0")" pwd ) cd $base_dir if [[ $1 != "no_logo" ]]; then cat << 'LOGO' ############################################################### LOGO else shift 1 fi # extra function ## func of log function log_warn() { local date=$(date "+%Y-%m-%d-%H:%M:%S") local para=$1 echo "[WARN] $date $1" | tee -a "./log/stop_log" } function log_info() { local date=$(date "+%Y-%m-%d-%H:%M:%S") local para=$1 echo "[INFO] $date $1" | tee -a "./log/stop_log" } function log_err() { local date=$(date "+%Y-%m-%d-%H:%M:%S") local para=$1 echo "[ERROR] $date $1" | tee -a "./log/stop_log" } function stop_process() { ID=$(ps -aux | grep "$1" | grep -v "$0" | grep -v "grep" | awk '{print $2}') if [[ "$ID" ]]; then log_info "$1 运行中,准备关闭" for id in $ID; do kill -15 "$id" echo "stop $1 process:(PID=${id})" done echo "---------------" fi } stop_process "node_exporter" stop_process "postgres_exporter" log_info "服务停止脚本运行完成"