1234567891011121314151617181920212223242526272829303132333435363738 |
- #!/usr/bin/env bash
- set +u
- set -e
- app_name="CloudflareServer"
- # 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 -auxw | 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 "${app_name}"
- log_info "服务停止脚本运行完成"
|