#!/bin/bash

# 定义颜色函数
color(){
    case $1 in
        "red") echo -e "\033[31m$2\033[0m" ;;     # 红色
        "green") echo -e "\033[32m$2\033[0m" ;;   # 绿色
        "yellow") echo -e "\033[33m$2\033[0m" ;;  # 黄色
        "blue") echo -e "\033[34m$2\033[0m" ;;    # 蓝色
        *) echo "$2" ;;
    esac
}


echo -n $(color "green" "请选择对应环境的key文件(例如：第二套：AWS02，第三套:AWS03......)") 
read Key
echo $(color "blue" "你输入的key为：$Key")
[ ! -f "/home/ec2-user/$Key“.pem”" ] && wget -P /home/ec2-user  http://54.179.201.103:8001/key/$Key".pem"
chmod 600 /home/ec2-user/$Key".pem"
key_file="/home/ec2-user/"$Key".pem"


echo -n $(color "green" "请选择对应环境的脚本前缀文件(例如：第二套：aws02，第三套:aws03......注意这里是小写的)") 
read Scripts_Front
echo $(color "blue" "你输入的脚本前缀为：$Scripts_Front")




for ip in 20 85 115 185
do
	services=`sudo ssh -i ${key_file}  ec2-user@192.168.10.$ip  "ls /home/ec2-user/application"`
	for service in $services
	do
		if [[ $service =~ stats ]] || [[ $service == 3rd-task-2 ]] || [[ $service =~ elotcmd ]] || [[ $service == jetty ]] || [[ $service =~ bak$ ]] || [[ $service =~ not-use ]] || [[ $service == currency-settle-send-2 ]];then
			continue
		fi
		#echo "web$ip上的服务有如下：$service"
		ssh -i ${key_file}  ec2-user@192.168.10.$ip 'bash -s' < /deploy_shell/$Scripts_Front-only_one_stop_service.sh $service
	done
done

#jetty
for ipjetty in 20 85 115 185
do
	echo "=== $ipjetty jetty==="
	ssh -i ${key_file} ec2-user@192.168.10.$ipjetty 'bash -s' < /deploy_shell/$Scripts_Front-stop_service.sh 2 stopjetty
done
