Friday, 8 June 2018

How to deploy a war file to remote server on tomcat using shell script


Step1: reach to project directory where pom.xml file exist from terminal
Step2: clean mavan using below
mvn clean
Step3: create a war file
mvn package
Step4: remove existing war from webapps tomcat
ssh user@address 'rm /data/apache-tomcat-8.0.29/webapps/warFile'
Step5: remove module exist in webapps tomcat
ssh user@address 'rm -rf moduleName'
Step6: copy war file to wenapps tomcat to remote server
scp /pathOf local dirctory/project.war user@address:/data/apache-tomcat-8.0.29/webapps
echo "deployment done"!

we need to provide some write permission to remote server webapps folder using below:
step1: need to login remote server in teminal
step2: move to directory where you want to provide write access
step3:   chmod -R 777 .

we also need to add our system public key to remote because it will not ask password during deployment:
cat ~/.ssh/id_rsa.pub | ssh user@address 'cat >> .ssh/authorized_keys'


complete script save into a file(deploywar.sh):
mvn clean
mvn package
ssh user@address 'rm /data/apache-tomcat-8.0.29/webapps/warFile' 
ssh user@address 'rm -rf moduleName' 
scp /pathOf local dirctory/project.war user@address:/data/apache-tomcat-8.0.29/webapps 
echo "deployment done"! 

 execute below command from terminal from project location where pom.xml file exist:
/path where script file /deploywar.sh
 

No comments:

Post a Comment

links for Data Structure

  1) 𝐁𝐞𝐜𝐨𝐦𝐞 𝐌𝐚𝐬𝐭𝐞𝐫 𝐢𝐧 𝐋𝐢𝐧𝐤𝐞𝐝 𝐋𝐢𝐬𝐭:  https://lnkd.in/gXQux4zj 2) 𝐀𝐥𝐥 𝐭𝐲𝐩𝐞𝐬 𝐨𝐟 𝐓𝐫𝐞𝐞 𝐓𝐫𝐚𝐯𝐞𝐫𝐬𝐚𝐥𝐬...