Infrastructure

Deploying a Java-Tomcat-Webapp on AmazonAWS via ShellScript

A small shell script which i used to deploy our web apps to our Amazon AWS Infrastructure. This script I used for our test and staging systems. Next step will be a deployment pipeline.


#bash

# File to deploy
FILE=mywebapp.war

# Amazon AWS Informations (Host, User, SSL-Key)
EC2HOST=ec2-xxx-xxx-xxx-xxx.eu-west-1.compute.amazonaws.com
SSHUSER=root
SSHKEY=/path/to/ssh/key/keyfile.pem

# Check if file exists
if [ -f $FILE ];
then

# SSH Connection String
SSHCONNECTION=$SSHUSER@$EC2HOST

if [ -f $SSHKEY ];
then
# stop deployed app
ssh -i $SSHKEY $SSHCONNECTION "/etc/init.d/tomcat stop && killall java"

# deploy to amazon aws
ssh -i $SSHKEY $SSHCONNECTION rm -rf /opt/tomcat/webapps/ROOT /opt/tomcat/webapps/ROOT.war
scp -i $SSHKEY ./$FILE $SSHCONNECTION:/opt/tomcat/webapps/ROOT.war
rm -rf ./$FILE

# start new deployed app
ssh -i $SSHKEY $SSHCONNECTION "/etc/init.d/tomcat start && tailf /opt/tomcat/logs/catalina.out"

else
echo "SSH Key $SSHKEY doesn't found."
fi

else
echo "File $FILE does not exist."
fi

Standard

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.