Subversion Repositories SmartDukaan

Rev

Blame | Last modification | View Log | RSS feed

#!/bin/bash

if [ $# -ne 1 ]
then
        echo "Usage: $0 <DEPLOY|ROLLBACK>"
        exit 1
fi

ACTION=$1
if [ $ACTION != "DEPLOY" -a $ACTION != "ROLLBACK" ]
then
        echo "Wrong input"
        echo "Usage: $0 <DEPLOY|ROLLBACK>"
        exit 1
fi


# Define your function here
ReadUserInput () {
        read userinput
        while [ $userinput != "yes" -a $userinput != "no" ]
        do
                echo "Wrong input. Please try again [yes/no] : "
                read userinput
        done
        echo $userinput
}

PROD_SERVERS="prod1 prod2 prod3"


for PROD_SERVER in ${PROD_SERVERS}
do
        echo "Deploying on server: ${PROD_SERVER}. R you sure ? [yes/no] \n"
        response=$(ReadUserInput)
        echo $response
        if [ "$response" =  "yes" ]
        then
                echo "Stopping apache on server"
                ssh ${PROD_SERVER} "/etc/init.d/apache2 stop"
                echo "Stopped apache on server"
                
                
                echo "Deploying on server"
                ssh ${PROD_SERVER} "/root/code/trunk/runutils/deploy-everything.sh DEPLOY"
                echo "Deployed on server."
                
                echo "Please test everything on the ${PROD_SERVER} using 8080 port."
                echo "Is everything fine on ${PROD_SERVER} ? [yes/no]"
                depstatus=$(ReadUserInput)
                if [ "$depstatus" = "no" ]
                then
                        echo "Want to rollback on ${PROD_SERVER} ? [yes/no]"
                        rollback=$(ReadUserInput)
                        if [ "$rollback" = "yes" ]
                        then
                                ssh ${PROD_SERVER} "/root/code/trunk/runutils/deploy-everything.sh ROLLBACK"
                                echo "You have rolled back to the previous version. Please verify it using 8080 port and start apache manually."
                        else
                                echo "You have chosen to not to roll back. Please verify it using 8080 port and start apache manually."
                        fi
                else
                        echo "Starting apache on server"
                        ssh ${PROD_SERVER} "/etc/init.d/apache2 start"
                        echo "Started apache on server"
                fi

        else
                echo "Nothing to deploy"
                exit 1
        fi
done