#!/bin/bash
ip_last=$1
project_type=$2
public_ip=$3
set timeout 1200

pwd_path_0="/home/qa-deploy-utils"
IP_host=`sh $pwd_path_0/get-ip.sh $ip_last`

echo "参数为：
ip : ${IP_host}
project_type : ${project_type}
public_ip : ${public_ip}
"

sh /home/qa-deploy-utils/qa_shell_script/1_mount_config_files.sh $ip_last

expect -c "
	 set timeout 10
   spawn ssh root@${IP_host}
	 expect \"]#\"
	 send \"cd /usr/lib/rabbitmq/bin\r\"
	 expect \"]#\"
	 send \"./rabbitmqctl stop\r\"
	sleep 10 
	expect \"]#\"
	 send \"./rabbitmq-server -detached\r\"
	sleep 10 
	expect \"]#\"
	send \"cd /home/qa-deploy-utils/qa_shell_script\r\"
	sleep 10 
	expect \"]#\"
	 send \"sh rabbitmq/add_mq_user.sh\r\"
   expect \"]#\"
	sleep 10
	send \"sh rabbitmq/initial_mq.sh\r\"
   expect \"]#\"
	 send \"cd /home\r\"
	 expect \"]#\"
	 send \"sh /home/qa-deploy-utils/qa_shell_script/initial_env/db_tran.sh\r\"
	 expect \"]#\"
	 send \"cd /home/quant_group/mongodb/\r\"
	 expect \"]#\"
	 send \"sh start.sh\r\"
	 expect \"]#\"
	 send \"cd /home/qa-deploy-utils/qa_shell_script\r\"
   expect \"]#\"
	 send \"sh deploy_project_by_type.sh $project_type $branch_name $public_ip\r\"
     set timeout -1
   expect \"]#\"
   send \"exit\r\"
expect eof;"
