#!/bin/bash
ip_last=$1
project_type=$2
public_ip=$3
set timeout 1200
ip=192.168.4.$ip_last
echo "参数为：
ip : ${ip}
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}
	 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;"
