Ubantu 启动,停止,重启多个服务,shell脚本

1、新建文件,svc 

#!/bin/bash

authentic_service="./authentic_service"
data_analysis_service="./data_analysis_service"
data_process_service="./data_process_service"
event_process_service="./event_process_service"
sync_process_service="./sync_process_service"
status_process_service="./status_process_service"

function killProsess() {
	NAME=$1
	echo $NAME
        
    # 获取进程 PID
	# PID=$(ps -e | grep $NAME | awk '{print $1}') 
	PID=$(ps -ef|grep $NAME| grep -v grep | awk '{print $2}') 
	
	echo "PID: $PID"
    #  杀死进程
	kill -9 $PID
}

function start() {
	(nohup $authentic_service 2>1 &) &&
	(nohup $data_analysis_service 2>1 &) &&
	(nohup $data_process_service 2>1 &) &&
	(nohup $event_process_service 2>1 &) &&
	(nohup $sync_process_service 2>1 &) &&
	(nohup $status_process_service 2>1 &) &&
	ps -ef | grep service
}

function stop() {
	killProsess $authentic_service
	killProsess $data_analysis_service
	killProsess $data_process_service
	killProsess $event_process_service
	killProsess $sync_process_service
	killProsess $status_process_service
}

function restart() {
	stop
	start
}

case "$1" in
	start )
		start
		echo "monitor start sucess"
		;;
	stop )
		stop
		echo "monitor stop sucess"
		;;
	restart )		
		restart
		echo "monitor restart sucess"
		;;
	* )
		echo "you can use ./svc start|stop|restart"
		;;
esac

2、启动命令

./svc start|stop|restart

 

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页