TOMCAT START/STOP#!/bin/bash## tomcat This shell script takes care of starting and stopping Tomcat## chkconfig: - 80 20#### BEGIN INIT INFO# Provides: tomcat# Required-Start: $network $syslog# Required-Stop: $network $syslog# Default-Start:# Default-Stop:# Short-Description: start and stop tomcat### END INIT INFOTOMCAT_USER=liferayappTOMCAT_HOME="/opt/liferay/tomcat-7.0.27"SHUTDOWN_WAIT=45tomcat_pid() {echo `ps aux | grep org.apache.catalina.startup.Bootstrap | grep -v grep | awk '{ print $2 }'`}start() {pid=$(tomcat_pid)if [ -n "$pid" ]thenecho "Tomcat is already running (pid: $pid)"else# Start tomcatecho "Starting tomcat"/bin/su - -c "cd $TOMCAT_HOME/bin && $TOMCAT_HOME/bin/startup.sh" $TOMCAT_USERfireturn 0}stop() {pid=$(tomcat_pid)if [ -n "$pid" ]thenecho "Stoping Tomcat"/bin/su - -c "cd $TOMCAT_HOME/bin && $TOMCAT_HOME/bin/shutdown.sh" $TOMCAT_USERlet kwait=$SHUTDOWN_WAITcount=0count_by=5until [ `ps -p $pid | grep -c $pid` = '0' ] || [ $count -gt $kwait ]doecho "Waiting for processes to exit. Timeout before we kill the pid: ${count}/${kwait}"sleep $count_bylet count=$count+$count_by;doneif [ $count -gt $kwait ]; thenecho "Killing processes which didn't stop after $SHUTDOWN_WAIT seconds"kill -9 $pidfielseecho "Tomcat is not running"fireturn 0}case $1 instart)start;;stop)stop;;restart)stopstart;;status)pid=$(tomcat_pid)if [ -n "$pid" ]thenecho "Tomcat is running with pid: $pid"elseecho "Tomcat is not running"fi;;esacexit 0STARTING STOPPING WEBLOGIC ADMIN SERVER#!/bin/sh if [ -z "$1" ]; then echo "You must supply either start or stop command while calling this script! correct usage: weblogic_start_stop.sh start|stop" exit fi bold=`tput bold` normal=`tput sgr0` case "$1" in 'start') echo "Starting Management Node & Weblogic Server 10.3.6" echo "Starting NodeManager" nohup $WLS_HOME/server/bin/startNodeManager.sh > /dev/null 2>&1 & sleep 10 output=`ps -ef | grep -i nodemanager.javahome | grep -v grep | awk {'print $2'} | head -1` set $output pid=$1 echo "Weblogic NodeManager Service was started with process id : ${bold}$pid${normal}" echo "Starting WebLogic Domain" nohup $MW_HOME/user_projects/domains/ClassicDomain/bin/startWebLogic.sh > /dev/null 2>&1 & # Sleep until exiting sleep 60 echo "All done, exiting" exit esac ################################Stopping the services################################## case "$1" in 'stop') echo "Stopping Weblogic Server & Node Manager" nohup $MW_HOME/user_projects/domains/ClassicDomain/bin/stopWebLogic.sh > /dev/null 2>&1 & sleep 30 # echo "Killing Nodemanager process now" output=`ps -ef | grep -i nodemanager.javahome | grep -v grep | awk {'print $2'} | head -1` set $output pid=$1 echo "Killing Weblogic NodeManager Service Process : ${bold}$pid${normal}" kill -9 `ps -ef | grep -i nodemanager.javahome | grep -v grep | awk {'print $2'} | head -1` echo "All done, exiting" exit esac
Apache Ant for Java build file
Tuesday, January 20, 2015
sampleshellscripting
Monday, April 21, 2014
Thursday, December 22, 2011
Apache Ant for Java build file
PROJECT
A project has three attributes:
TARGET
A target is a container of tasks that cooperate to reach a desired state during the build process.
Targets can depend on other targets and Apache Ant ensures that these other targets have been executed before the current target. For example you might have a target for compiling and a target for creating a distributable. You can only build a distributable when you have compiled first, so the distribute target depends on the compile target.
Ant tries to execute the targets in the
A project has three attributes:
| Attribute | Description | Required |
| name | the name of the project. | No |
| default | the default target to use when no target is supplied. | No; however, since Ant 1.6.0, every project includes an implicit target that contains any and all top-level tasks and/or types. This target will always be executed as part of the project's initialization, even when Ant is run with the -projecthelp option. |
| basedir | the base directory from which all path calculations are done. This attribute might be overridden by setting the "basedir" property beforehand. When this is done, it must be omitted in the project tag. If neither the attribute nor the property have been set, the parent directory of the buildfile will be used. |
TARGET
A target is a container of tasks that cooperate to reach a desired state during the build process.
Targets can depend on other targets and Apache Ant ensures that these other targets have been executed before the current target. For example you might have a target for compiling and a target for creating a distributable. You can only build a distributable when you have compiled first, so the distribute target depends on the compile target.
Ant tries to execute the targets in the
depends attribute
in the order they appear (from left to right). Keep in mind that it is
possible that a target can get executed earlier when an earlier target
depends on it:Suppose we want to execute target D. From its<target name="A"/> <target name="B" depends="A"/> <target name="C" depends="B"/> <target name="D" depends="C,B,A"/>
depends attribute,
you might think that first target C, then B and then A is executed.
Wrong! C depends on B, and B depends on A, so first A is executed, then
B, then C, and finally D.Call-Graph: A --> B --> C --> D
SAMPLE ANT FILE
<project name="MyProject" default="dist" basedir=".">
<description>
simple example build file
</description>
<!-- set global properties for this build -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
<target name="compile" depends="init"
description="compile the source " >
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}"/>
</target>
<target name="dist" depends="compile"
description="generate the distribution" >
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyProject-${DSTAMP}.jar" basedir="${build}"/>
</target>
<target name="clean"
description="clean up" >
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
mkdir/copy/delete-
mkdir dir="${webapp}"/><mkdir dir="${web-inf}"/><mkdir dir="${classes}"/><mkdir dir="${resources}"/><delete file="${res}/beans.xml"/><copy file="${res}/beans.xml.template" tofile="${res}/beans.xml"/><replace file="${res}/beans.xml" replacefilterfile="build.properties"/>UPDATE SVN REVISION<target name="updateSVNRevision">
<description>This task adds svn info in output files</description><typedef resource="org/tigris/subversion/svnant/svnantlib.xml" classpathref="svnant.classpath"/><svn><wcVersion path="${basedir}"/></svn><!--svn><update path="${basedir}" force="true" recursive="true" /></svn--><echo message="Subversion repository url: ${repository.url}"/><echo message="Highest revision number : ${revision.max}"/><echo message="Highest last commited revision number : ${committed.max}"/><echo message="Revision range if workingCopy is mixed : ${revision.range}"/><echo message="Build version is : ${build.version}"/><echo message="Build Date ( mm/dd/yyyy hh:mm:ss aa ) is : ${current.timestamp}"/><replaceregexp match="svnHighestRevisionNumber=(.*)" replace="svnHighestRevisionNumber=${revision.max}>" byline="true"><fileset dir="${webapp}" includes="${builf.info.files}"/></replaceregexp><replaceregexp match="svnLastCommitedRevisionNumber=(.*)" replace="svnLastCommitedRevisionNumber=${committed.max}>" byline="true"><fileset dir="${webapp}" includes="${builf.info.files}"/></replaceregexp><replaceregexp match="buildVersionNumber=(.*)" replace="buildVersionNumber=${build.version}>" byline="true"><fileset dir="${webapp}" includes="${builf.info.files}"/></replaceregexp><replaceregexp match="buildDate=(.*)" replace="buildDate=${current.timestamp}>" byline="true"><fileset dir="${webapp}" includes="${builf.info.files}"/></replaceregexp>
</target>
USAGE OF FILESET COMMAND Groups all files in directory${server.src}that are Java source files and don't have the textTestin their name.<fileset dir="${server.src}" casesensitive="yes"> <include name="**/*.java"/> <exclude name="**/*Test*"/> </fileset>Create war file example:<target name="war" depends="copy-resources, compileOnly"> <war destfile="${output}/${war.file}.war" webxml="${web}/WEB-INF/web.xml"> <fileset dir="${webapp}"> <include name="**/*.*" /> <exclude name="**/servlet-api.jar"/> </fileset> </war> </target>Copy-resource example<target name="copy-resources" depends="clean,init"> <mkdir dir="${towebserver}"/> <mkdir dir="${webapp}"> <copy todir="${webapp}"> <fileset dir="${web}"> <exclude name="*.jsp"> <exclude name="*.jspf"> <exclude name="**/WEB-INF/**"/> <fileset> </copy>Creating Jar file using ANT ScriptHow to start and stop Tomcat from ANT
MARCH 25, 2006 113 COMMENTSThis approach is not based on the Tomcat Ant Tasks or a brute force <exec dir=”${tomcat.home}/bin” executable=”startup.bat”/> kind of approach.After wading through startup.bat and catalina.bat I figured that they boil down to the following:
123456789101112<targetname="tomcat-start"><javajar="${tomcat.home}/bin/bootstrap.jar"fork="true"><jvmargvalue="-Dcatalina.home=${tomcat.home}"/></java></target><targetname="tomcat-stop"><javajar="${tomcat.home}/bin/bootstrap.jar"fork="true"><jvmargvalue="-Dcatalina.home=${tomcat.home}"/><argline="stop"/></java></target>You can have in build.properties, something like the following entry:tomcat.home=E:/peter/opt/apache-tomcat-5.5.12To execute the jar task, wrap it inside a target, most commonly, the build or package target, and execute them.<target name="build-jar"> <jar destfile="${web.dir}/lib/util.jar" basedir="${build.dir}/classes" includes="faxapp/util/**" excludes="**/Test.class"> <manifest> <attribute name="Main-Class" value="com.tutorialspoint.util.FaxUtil"/> </manifest> </jar> </target>Running Ant on this file creates the util.jar file for us.The following outcome is the result of running the Ant file:C:\>ant build-jar Buildfile: C:\build.xml BUILD SUCCESSFUL Total time: 1.3 seconds
Subscribe to:
Comments (Atom)