Skip to content

Instantly share code, notes, and snippets.

@rodrigodealer
Created October 27, 2010 12:11
Show Gist options
  • Save rodrigodealer/648912 to your computer and use it in GitHub Desktop.
Save rodrigodealer/648912 to your computer and use it in GitHub Desktop.
Deploy via ant
Jars no classpath:
ant-contrib.jar
ant-jsch.jar
-- build.properties --
# Project information
version=1.0
release=1.0.0
# Production Deploy information
producao.sshhost=
producao.sshuser=
producao.sshpassword=
producao.backupdir=
producao.tomcatlocation=
producao.wartarget=${producao.tomcatlocation}/webapps
producao.tomcatstop=${producao.tomcatlocation}/bin/shutdown.sh
producao.warremovelink=cd ${producao.wartarget} && rm -rf ${warlink}
producao.backupwar=mv ${producao.tomcatlocation}/webapps/*.war ${producao.backupdir}
producao.removetrunk=cd ${producao.wartarget} && rm -rf ${version.name}*
producao.warcreatelink=cd ${producao.wartarget} && ln -sf ${version.name}-${release} ${version.name}
producao.tomcatstart=${producao.tomcatlocation}/bin/startup.sh
producao.backupdblocation=
producao.backupdbfile=
producao.backupdbuser=
producao.backupdbpassword=
producao.backupdbname=
producao.backupdbcommand=mysqldump
producao.host=http://${producao.sshhost}
producao.port=
-- build.xml --
<target name="producao.tomcat-stop" depends="war">
<echo>** Stopping Tomcat **</echo>
<sshexec command="${producao.tomcatstop}" host="${producao.sshhost}" password="${producao.sshpassword}" username="${producao.sshuser}" />
</target>
<target name="producao.unlink" depends="producao.tomcat-stop">
<echo>** Unlinking application directory **</echo>
<sshexec command="${producao.warremovelink}" host="${producao.sshhost}" password="${producao.sshpassword}" username="${producao.sshuser}" />
</target>
<target name="producao.backupwar" depends="producao.unlink">
<echo>** Starting Backup WAR **</echo>
<sshexec command="${producao.backupwar}" host="${producao.sshhost}" password="${producao.sshpassword}" username="${producao.sshuser}" />
</target>
<target name="producao.removetrunk" depends="producao.backupwar">
<echo>** Removing trunk **</echo>
<sshexec command="${producao.removetrunk}" host="${producao.sshhost}" password="${producao.sshpassword}" username="${producao.sshuser}" />
</target>
<target name="producao.backup_database" depends="producao.removetrunk">
<echo>** Starting Backup Mysql **</echo>
<sshexec command="${producao.backupdbcommand} --user=${producao.backupdbuser} --password=${producao.backupdbpassword} ${producao.backupdbname} > ${producao.backupdbfile}_${dateTime}.sql" host="${producao.sshhost}" password="${producao.sshpassword}" username="${producao.sshuser}" />
</target>
<target name="producao.sendwar" depends="producao.backup_database">
<echo>** Sending WAR **</echo>
<scp trust="true" file="${war.file}" todir="${producao.sshuser}:${producao.sshpassword}@${producao.sshhost}:${producao.wartarget}">
</scp>
</target>
<target name="producao.link" depends="producao.sendwar">
<echo>** Linking application directory **</echo>
<sshexec command="${producao.warcreatelink}" host="${producao.sshhost}" password="${producao.sshpassword}" username="${producao.sshuser}" />
</target>
<target name="producao.tomcat-start" depends="producao.link">
<echo>** Starting Tomcat **</echo>
<sshexec command="${producao.tomcatstart}" host="${producao.sshhost}" password="${producao.sshpassword}" username="${producao.sshuser}" />
</target>
<target name="producao.checktomcat" depends="producao.tomcat-start">
<echo>** Checking Tomcat connectivity **</echo>
<waitfor maxwait="2" maxwaitunit="minute"
timeoutproperty="tomcat.start.expired.time">
<and>
<socket server="${producao.sshhost}" port="${producao.port}"/>
<http url="${producao.host}:${producao.port}/${version.name}" errorsBeginAt="404"/>
</and>
</waitfor>
<fail if="tomcat.start.expired.time" message="Error when trying to startup Tomcat" />
</target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment