All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kuali.common.deploy.ant.deploy.xml Maven / Gradle / Ivy

The newest version!
<!--

    Copyright 2004-2013 The Kuali Foundation

    Licensed under the Educational Community License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

    http://www.opensource.org/licenses/ecl2.php

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<project name="Application Deployer">
  <taskdef name="mvn" classname="org.kuali.maven.common.MvnTask" />
  <property name="impex.dba.username" value="master" />
  <property name="deploy.mvn.profiles" value="prepare,deploy" />

  <property name="catalina.home" value="/usr/local/tomcat" />
  <property name="catalina.bin" value="${catalina.home}/bin" />
  <property name="catalina.base" value="/usr/local/${tomcat.instance}" />
  <property name="catalina.lib" value="${catalina.base}/lib" />
  <property name="catalina.webapps" value="${catalina.base}/webapps" />
  <property name="catalina.conf" value="${catalina.base}/conf" />

  <target name="resetks" depends="stop,clean,cleanjdbc,copyjdbc,copyksconfig,resetdb,copywar,start" />
  <target name="reset" depends="stop,clean,cleanjdbc,copy,resetdb,start" />
  <target name="deploy" depends="stop,clean,cleanjdbc,copy" />
  <target name="restart" depends="stop,clean,start" />
  <target name="waronly" depends="stop,clean,copywar,start" />
  <target name="configonly" depends="stop,clean,copy-appconfig,copy-envconfig,start" />
  <target name="copy" depends="copyjdbc,copyconfig,copysetenv,copyappdynamics,copywar" />

  <target name="copyappdynamics">
    <condition property="copyappdynamics.property">
      <and>
        <isset property="local.appdynamics.file" />
        <isset property="remote.appdynamics.file" />
        <isset property="remote.appdynamics.dir" />
      </and>
    </condition>
    <fail unless="copyappdynamics.property">Missing local.appdynamics.file, remote.appdynamics.file, or remote.appdynamics.dir</fail>
    <antcall target="mkdir">
      <param name="remote.dir" value="${remote.appdynamics.dir}" />
    </antcall>
    <antcall target="copyfile">
      <param name="local.file" value="${local.appdynamics.file}" />
      <param name="remote.file" value="${remote.appdynamics.file}" />
    </antcall>
  </target>

  <target name="copysetenv">
    <condition property="copysetenv.property">
      <and>
        <isset property="local.setenv.file" />
        <isset property="remote.setenv.file" />
      </and>
    </condition>
    <fail unless="copysetenv.property">Missing local.setenv.file or remote.setenv.file</fail>
    <antcall target="copyfile">
      <param name="local.file" value="${local.setenv.file}" />
      <param name="remote.file" value="${remote.setenv.file}" />
    </antcall>
    <antcall target="chmod">
      <param name="remote.perms" value="755" />
      <param name="remote.file" value="${remote.setenv.file}" />
    </antcall>
  </target>

  <target name="copyconfig">
    <condition property="copyconfig.property">
      <and>
        <isset property="local.config.dir" />
        <isset property="remote.config.dir" />
      </and>
    </condition>
    <fail unless="copyconfig.property">Missing local.config.dir or remote.config.dir</fail>
    <antcall target="mkdir">
      <param name="remote.dir" value="${remote.config.dir}" />
    </antcall>
    <antcall target="rsync">
      <param name="rsync.src" value="${local.config.dir}" />
      <param name="rsync.dst" value="${secure.user}@${deploy.server}:${remote.config.dir}" />
    </antcall>
    <antcall target="chowndir">
      <param name="remote.dir" value="${remote.config.dir}" />
    </antcall>
    <antcall target="chowndir">
      <param name="remote.dir" value="${tomcat.home}" />
    </antcall>
  </target>

  <property name="config.home" value="/home/${tomcat.instance}/kuali/main/${deploy.environment}" />
  <property name="ssh.verbose" value="false" />
  <property name="scp.verbose" value="false" />
  <property name="secure.user" value="root" />
  <property name="ssh.user" value="${secure.user}" />
  <property name="scp.user" value="${secure.user}" />

  <target name="copyksconfig">
    <antcall target="mkdir">
      <param name="remote.dir" value="${config.home}" />
    </antcall>
    <antcall target="copy-appconfig" />
    <antcall target="chowndir">
      <param name="remote.dir" value="/home/tomcat/.kuali" />
    </antcall>
  </target>

  <target name="checkout">
    <condition property="checkout.properties">
      <and>
        <isset property="manifest.SVN-URL" />
        <isset property="manifest.SVN-Revision" />
      </and>
    </condition>
    <fail unless="checkout.properties">Missing checkout properties</fail>
    <property name="manifest.svn.url" value="${manifest.SVN-URL}@${manifest.SVN-Revision}" />
    <echo>svn checkout ${manifest.svn.url} target/checkout/impex</echo>
    <exec executable="svn" outputproperty="ant.output" failonerror="true">
      <arg value="checkout" />
      <arg value="${manifest.svn.url}" />
      <arg value="target/checkout/impex" />
    </exec>
  </target>

  <target name="ssh-exec">
    <condition property="ssh.properties">
      <and>
        <isset property="ssh.command" />
      </and>
    </condition>
    <fail unless="ssh.properties">Missing ssh.command</fail>
    <sshexec command="${ssh.command}" username="${ssh.user}" host="${deploy.server}" keyfile="${deploy.auth}" trust="true" verbose="${ssh.verbose}" failonerror="true" />
  </target>

  <target name="stop" depends="check-basic-properties">
    <property name="stop.command" value="su - ${tomcat.instance} ${catalina.bin}/forced-shutdown.sh" />
    <!--
      Don't fail the build if the stop command fails
      If the deploy script gets interrupted along the way somewhere, catalina.pid may or may not
      exist on the remote server. The stop command returns a failure code if it thinks
      catalina.pid should be present but it is not. Generally speaking, if catalina.pid
      is not present tomcat is not running, which means the build should not fail.
    -->
    <sshexec command="${stop.command}" username="root" host="${deploy.server}" keyfile="${deploy.auth}" trust="true" verbose="${ssh.verbose}" failonerror="false" />
  </target>
  <target name="cleanjdbc" depends="check-basic-properties">
    <antcall target="delete">
      <param name="remote.delete" value="${catalina.lib}/mysql*.jar" />
    </antcall>
    <antcall target="delete">
      <param name="remote.delete" value="${catalina.lib}/ojdbc*.jar" />
    </antcall>
  </target>
  <target name="clean" depends="check-basic-properties">
    <antcall target="removedir">
      <param name="remote.dir" value="${catalina.base}/webapps/ROOT" />
    </antcall>
    <antcall target="runscript">
      <param name="message" value="Cleaning up ${tomcat.instance} on ${deploy.server}" />
      <param name="script" value="${catalina.bin}/cleanup.sh" />
    </antcall>
  </target>
  <target name="copy-commonconfig" depends="check-basic-properties">
    <condition property="copy-commonconfig.properties">
      <and>
        <isset property="deploy.config.common" />
      </and>
    </condition>
    <fail unless="copy-commonconfig.properties">Missing deploy.config.common</fail>
    <antcall target="mkdir">
      <param name="remote.dir" value="${config.home}" />
    </antcall>

    <antcall target="copyfile">
      <param name="local.file" value="${deploy.config.common}" />
      <param name="remote.file" value="${config.home}/common-config.xml" />
    </antcall>
  </target>

  <target name="copy-appconfig" depends="check-basic-properties">
    <condition property="copy-appconfig.properties">
      <and>
        <isset property="deploy.config.app" />
      </and>
    </condition>
    <fail unless="copy-appconfig.properties">Missing deploy.config.app</fail>
    <antcall target="copyfile">
      <param name="local.file" value="${deploy.config.app}" />
      <param name="remote.file" value="${config.home}/${deploy.app.configfile}" />
    </antcall>
  </target>
  <target name="copy-envconfig" depends="check-basic-properties,check-env-config" if="env.config.present">
    <antcall target="copyfile">
      <param name="local.file" value="${deploy.config.env}" />
      <param name="remote.file" value="${config.home}/env-config.xml" />
    </antcall>
  </target>
  <target name="copyjdbc" depends="check-basic-properties">
    <condition property="copyjdbc.properties">
      <and>
        <isset property="jdbc.driver.filename" />
        <isset property="jdbc.driver.location" />
      </and>
    </condition>
    <fail unless="copyjdbc.properties">Missing jdbc driver properties</fail>
    <antcall target="mkdir">
      <param name="remote.dir" value="${catalina.lib}" />
    </antcall>
    <antcall target="copyfile">
      <param name="local.file" value="${jdbc.driver.location}" />
      <param name="remote.file" value="${catalina.lib}/${jdbc.driver.filename}" />
    </antcall>
    <antcall target="chowndir">
      <param name="remote.dir" value="${catalina.lib}" />
    </antcall>
  </target>
  <target name="copywar" depends="check-basic-properties">
    <condition property="copywar.properties">
      <and>
        <isset property="deploy.war" />
      </and>
    </condition>
    <fail unless="copywar.properties">Missing deploy.war</fail>
    <property name="remote.war.file" value="${catalina.base}/webapps/ROOT.war" />
    <antcall target="copyfile">
      <param name="local.file" value="${deploy.war}" />
      <param name="remote.file" value="${remote.war.file}" />
    </antcall>
  </target>
  <target name="resetdb">
    <mvn basedir="${project.basedir}" pom="classpath:org/kuali/common/deploy/mvn/impex/pom.xml" filterPom="true">
      <arg value="initialize" />
    </mvn>
  </target>
  <target name="start" depends="check-basic-properties">
    <antcall target="runscript">
      <param name="message" value="Start ${tomcat.instance} on ${deploy.server}" />
      <param name="script" value="${catalina.bin}/startup.sh" />
    </antcall>
  </target>
  <target name="removedir">
    <condition property="removedir.properties">
      <and>
        <isset property="remote.dir" />
      </and>
    </condition>
    <fail unless="removedir.properties">Missing remote.dir</fail>
    <antcall target="ssh-exec">
      <param name="ssh.command" value="rm -rf ${remote.dir}" />
    </antcall>
  </target>
  <target name="copyfile">
    <condition property="copyfile.properties">
      <and>
        <isset property="local.file" />
        <isset property="remote.file" />
      </and>
    </condition>
    <fail unless="copyfile.properties">Missing either local.file or remote.file</fail>
    <echo>scp ${local.file} to ${scp.user}@${deploy.server}:${remote.file}</echo>
    <scp localFile="${local.file}" remoteToFile="${scp.user}@${deploy.server}:${remote.file}" keyfile="${deploy.auth}" trust="true" verbose="${scp.verbose}" />
    <antcall target="ssh-exec">
      <param name="ssh.command" value="chown ${tomcat.instance}:tomcat ${remote.file}" />
    </antcall>
  </target>
  <target name="check-env-config">
    <condition property="check-env-config.properties">
      <and>
        <isset property="deploy.config.env" />
      </and>
    </condition>
    <fail unless="check-env-config.properties">Missing deploy.config.env</fail>
    <available file="${deploy.config.env}" property="env.config.present" />
  </target>
  <target name="check-basic-properties">
    <condition property="basic.properties">
      <and>
        <isset property="deploy.server" />
        <isset property="tomcat.instance" />
      </and>
    </condition>
    <fail unless="basic.properties">Missing either deploy.server or tomcat.instance property</fail>
  </target>
  <target name="chmod">
    <antcall target="ssh-exec">
      <param name="ssh.command" value="chmod ${remote.perms} ${remote.file}" />
    </antcall>
  </target>
  <target name="chowndir">
    <antcall target="ssh-exec">
      <param name="ssh.command" value="chown -R ${tomcat.instance}:tomcat ${remote.dir}" />
    </antcall>
  </target>
  <target name="mkdir">
    <antcall target="ssh-exec">
      <param name="ssh.command" value="mkdir -p ${remote.dir}" />
    </antcall>
  </target>
  <target name="runscript">
    <antcall target="ssh-exec">
      <param name="ssh.command" value="su - ${tomcat.instance} ${script}" />
    </antcall>
  </target>
  <target name="delete">
    <condition property="delete.properties">
      <and>
        <isset property="remote.delete" />
      </and>
    </condition>
    <fail unless="delete.properties">Missing remote.delete</fail>
    <antcall target="ssh-exec">
      <param name="ssh.command" value="rm -rf ${remote.delete}" />
    </antcall>
  </target>
  <target name="rsync">
    <echo>rsync -a --delete ${rsync.src} ${rsync.dst}</echo>
    <exec executable="rsync" failonerror="true">
      <arg value="-a" />
      <arg value="--delete" />
      <arg value="${rsync.src}" />
      <arg value="${rsync.dst}" />
    </exec>
  </target>
</project>




© 2015 - 2025 Weber Informatics LLC | Privacy Policy