Created
March 5, 2014 17:52
-
-
Save joasgarcia/9372569 to your computer and use it in GitHub Desktop.
Deploy - Script Ant
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | |
<!-- | |
Project é tag principal | |
basedir = Diretório base para os demais diretórios informados no script. O "." indica o diretório atual do script | |
default = Target padrão a ser executado | |
name = Um nome para o projeto | |
--> | |
<project basedir="." default="main" name="deploy-map"> | |
<!-- | |
Definição variável com a localização do arquivo WAR. Note que como o atributo "name" permite o uso de "." o que pode ser | |
aproveitado para estabelecer uma hierarquia de variáveis | |
--> | |
<property name="war.location" value="${app.war.location}/${app.war.filename}"/> | |
<!-- | |
Definição das tasks do antcontrib. Permite utilizar a trycatch task | |
--> | |
<taskdef resource="net/sf/antcontrib/antcontrib.properties" /> | |
<!-- | |
Target disparado como padrão, conforme atributo "default" da tag "project" | |
--> | |
<target name="main"> | |
<!-- | |
Definição da sequência de chamadas dos targets, feito pelo name dos targets | |
--> | |
<antcall target="copy-war"/> | |
<antcall target="stop-tomcat"/> | |
<antcall target="tmp-to-webapps"/> | |
<antcall target="start-tomcat"/> | |
</target> | |
<!-- | |
Primeiro target a ser executado. Um target é composto por uma ou mais | |
tasks, no exemplo as tasks são "echo", "trycatch", "scp" ... | |
--> | |
<target name="copy-war" description="Copia WAR para o /tmp do server e renomeia-o para 'ROOT.war'"> | |
<echo message="Copiando WAR para o /tmp do servidor..." /> | |
<trycatch property="msg" reference="ex"> | |
<try> | |
<!-- | |
Executa o comando scp para copiar o war para o server. Note a utilização da | |
variável "war.location" definida no início do script | |
--> | |
<scp | |
file="${war.location}" | |
todir="${env.ssh.user}@${env.ssh.host}:/tmp/" | |
port="${env.ssh.port}" | |
trust="true" | |
keyfile="${env.ssh.keyfile}" /> | |
<!-- | |
Roda comandos em uma máquina remota rodando um serviço SSH | |
--> | |
<sshexec host="${env.ssh.host}" | |
username="${env.ssh.user}" | |
trust="true" | |
port="${env.ssh.port}" | |
command=" | |
cd /tmp/; | |
sudo mv ${app.war.filename} ROOT.war;" | |
timeout="${env.server.timeout}" | |
keyfile="${env.ssh.keyfile}" /> | |
<echo message="War copiado para o server com sucesso." /> | |
</try> | |
<catch> | |
<echo message="${msg}" /> | |
</catch> | |
<finally> | |
</finally> | |
</trycatch> | |
</target> | |
<target name="stop-tomcat" description="Para o tomcat"> | |
<echo message="Parando tomcat..." /> | |
<trycatch property="msg" reference="ex"> | |
<try> | |
<sshexec host="${env.ssh.host}" | |
username="${env.ssh.user}" | |
trust="true" | |
port="${env.ssh.port}" | |
command=" | |
cd ${env.server.tomcat.bin}; | |
sudo sh catalina.sh stop;" | |
timeout="${env.server.timeout}" | |
keyfile="${env.ssh.keyfile}" /> | |
<echo message="Tomcat parado com sucesso."/> | |
</try> | |
<catch> | |
<echo message="${msg}" /> | |
</catch> | |
<finally> | |
</finally> | |
</trycatch> | |
</target> | |
<target name="tmp-to-webapps" description="Limpa a pasta webapps e copia o WAR do /tmp para o webapps do tomcat"> | |
<echo message="Copiando WAR do tmp para webapps..." /> | |
<trycatch property="msg" reference="ex"> | |
<try> | |
<sshexec host="${env.ssh.host}" | |
username="${env.ssh.user}" | |
trust="true" | |
port="${env.ssh.port}" | |
command=" | |
cd ${env.server.tomcat.webapps}; | |
sudo rm -rf ROOT.war ROOT; | |
sudo cp /tmp/ROOT.war ${env.server.tomcat.webapps}; | |
rm -rf /tmp/ROOT.war" | |
timeout="${env.server.timeout}" | |
keyfile="${env.ssh.keyfile}" /> | |
<echo message="Transferência para o webapps concluída com sucesso." /> | |
</try> | |
<catch> | |
<echo message="${msg}" /> | |
</catch> | |
<finally> | |
</finally> | |
</trycatch> | |
</target> | |
<target name="start-tomcat" description="Inicia o tomcat"> | |
<echo message="Iniciando tomcat..." /> | |
<trycatch property="msg" reference="ex"> | |
<try> | |
<sshexec host="${env.ssh.host}" | |
username="${env.ssh.user}" | |
trust="true" | |
port="${env.ssh.port}" | |
command=" | |
cd ${env.server.tomcat.bin}; | |
sudo sh catalina.sh start;" | |
timeout="${env.server.timeout}" | |
keyfile="${env.ssh.keyfile}" /> | |
<echo message="Tomcat iniciado com sucesso." /> | |
</try> | |
<catch> | |
<echo message="${msg}" /> | |
</catch> | |
<finally> | |
</finally> | |
</trycatch> | |
</target> | |
</project> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment