Subversion Repositories SmartDukaan

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4851 rajveer 1
#!/bin/bash
2
 
3
if [ $# -ne 1 ]
4
then
5
	echo "Usage: $0 <DEPLOY|ROLLBACK>"
6
	exit 1
7
fi
8
 
9
ACTION=$1
10
if [ $ACTION != "DEPLOY" -a $ACTION != "ROLLBACK" ]
11
then
12
	echo "Wrong input"
13
	echo "Usage: $0 <DEPLOY|ROLLBACK>"
14
	exit 1
15
fi
16
 
17
 
18
# Define your function here
19
ReadUserInput () {
20
	read userinput
21
	while [ $userinput != "yes" -a $userinput != "no" ]
22
	do
23
		echo "Wrong input. Please try again [yes/no] : "
24
		read userinput
25
	done
26
	echo $userinput
27
}
28
 
29
PROD_SERVERS="prod1 prod2 prod3"
30
 
31
 
32
for PROD_SERVER in ${PROD_SERVERS}
33
do
34
	echo "Deploying on server: ${PROD_SERVER}. R you sure ? [yes/no] \n"
35
	response=$(ReadUserInput)
36
	echo $response
37
	if [ "$response" =  "yes" ]
38
	then
39
		echo "Stopping apache on server"
40
		ssh ${PROD_SERVER} "/etc/init.d/apache2 stop"
41
		echo "Stopped apache on server"
42
 
43
 
44
		echo "Deploying on server"
45
		ssh ${PROD_SERVER} "/root/code/trunk/runutils/deploy-everything.sh DEPLOY"
46
		echo "Deployed on server."
47
 
48
		echo "Please test everything on the ${PROD_SERVER} using 8080 port."
49
		echo "Is everything fine on ${PROD_SERVER} ? [yes/no]"
50
		depstatus=$(ReadUserInput)
51
		if [ "$depstatus" = "no" ]
52
		then
53
			echo "Want to rollback on ${PROD_SERVER} ? [yes/no]"
54
			rollback=$(ReadUserInput)
55
        	        if [ "$rollback" = "yes" ]
56
			then
57
				ssh ${PROD_SERVER} "/root/code/trunk/runutils/deploy-everything.sh ROLLBACK"
58
				echo "You have rolled back to the previous version. Please verify it using 8080 port and start apache manually."
59
			else
60
				echo "You have chosen to not to roll back. Please verify it using 8080 port and start apache manually."
61
			fi
62
		else
63
			echo "Starting apache on server"
64
			ssh ${PROD_SERVER} "/etc/init.d/apache2 start"
65
			echo "Started apache on server"
66
		fi
67
 
68
	else
69
		echo "Nothing to deploy"
70
		exit 1
71
	fi
72
done
73
 
74