I have an Ant script which is used to deploy my application on two different machines at a time. With the local machine i do not have a problem, but when it comes to the remote machine, I want to check if Jboss is up or not. If it is up then I want to shut it down but if it is not then nothing should be done. I tried to do this by keeping the attribute of <sshexec> as failonerror="on". This works well when the Jboss is already down and the shutdown command only gives some errors. But the real problem that i faced was when Jboss was running and when the shutdown command was executed, it did not shutdown properly and gave some error. It is in these situations that I want to stop my build script and let the user know that there is something wrong with Jboss on the other machine and it needs to be looked at.
The target code for stopping the remote Jboss is
<target name="stopRemoteJboss" description="Stops Remote Instance of Jboss">
<echo message="Stopping Remote Jboss" />
<sshexec trust="true" host="${jboss.remote.host}" username="${jboss.remote.username}" password="${jboss.remote.password}" command="${jboss.remote.home}/bin/shutdown.sh -S" port="${jboss.remote.port}"/>
</target>
After a short check, I've found following, maybe you could reuse/or use as an inspiration for your script: http://shrubbery.homeip.net/c/display/W/Starting+JBoss+with+ANT
The relevant part for you seem to be:
<java jvm="#{jdkHome}/bin/java"
classname="org.jboss.Shutdown" fork="true" failonerror="false" resultproperty="shutdown.rc">
<arg line="-s jnp://#{bindAddr}:#{jnpPort}"/>
<classpath>
<pathelement path="#{jbossInstallDir}/bin/shutdown.jar"/>
<pathelement path="#{jbossInstallDir}/client/jbossall-client.jar"/>
</classpath>
</java>
<echo>Shutdown rc = ${shutdown.rc}</echo>
<condition property="shutdown.okay">
<equals arg1="${shutdown.rc}" arg2="0"/>
</condition>
<fail unless="shutdown.okay" message="Unable to shut down JBoss (maybe it hasn't fully started yet?)."/>
<echo>Waiting for #{bindAddr}:#{jnpPort} to stop listening...</echo>
Why not check to see if the remote port is active?
<project name="demo" default="check">
<condition property="server.running" value="running" else="not running">
<socket server="remoteserver" port="80"/>
</condition>
<target name="check" description="Print status message">
<echo message="Web server status: ${server.running}"/>
</target>
</project>
If your JBoss instance is configured as a reverse proxy you could use the alternative http condition to check the HTTP response code (which would be 503 "Service unavailable", if the appserver is down)
Related
I'm using ant scripts for initializing my exist-db.
But, I have this script below (dummy version) which is working in my local platform and not on my procution one. As I'm not the one who handle the configuration of this database, I don't know where to look in the conf to fix this.
Here is the script (which is just trying to add a new user) :
<project basedir="." default="default" name="ANTProject">
<property file="load.properties"/>
<path id="classpath.core">
<fileset dir="${path}/lib/core">
<include name="*.jar"/>
</fileset>
<pathelement path="${path}\exist.jar"/>
<pathelement path="${path}\exist-optional.jar"/>
</path>
<typedef resource="org/exist/ant/antlib.xml" uri="http://exist-db.org/ant">
<classpath refid="classpath.core"/>
</typedef>
<target name="default">
<echo message="Création du compte ${login}"/>
<xdb:adduser xmlns:xdb="http://exist-db.org/ant"
uri="xmldb:exist://${exist.uri}/exist/xmlrpc/db"
name="${login}" secret="${password}" primaryGroup="${user.group}" user="${root.login}"
password="${root.password}"/>
</target>
</project>
I get this error message :
XMLDB exception caught: No such handler: Default.setUser
I get the same thing if I use xdb:users task, but the xdb:store is working well... I'm running exist 2.1, in both my local and production plateform, and as already told, same scripts working well on local one...
I guess, it's something about the exist configuration, but I didn't find anything on enabling this tasks in the documentation.
If someone could help...
Ok, I got it.
Just for completeness, It was an issue on jar librairies. It seems I used ones which support xdb:store, but not others tasks (didn't find any release version of this)...
This ant depandancies is quite tricky and It's hard to know what your jars offer...
I have build a working Java application which I can succesfully build and deploy to my WebLogic11g server.
I'm automating this process now with Ant.
I can build my application, the builded application works fine when deployed manually. But the deployment trough Ant isn't working.
My Ant file:
<!-- GENERAL -->
<property name="project.dir" value="CustomReportingProvider"/>
<!-- JAR -->
<property name="deploy.dir" value="${project.dir}/deploy"/>
<property name="jar.deploy.dir" value="${deploy.dir}/jar"/>
<property name="jar.classes.dir" value="${project.dir}/classes"/>
<property name="jar.meta-inf.dir" value="${jar.classes.dir}/META-INF"/>
<!-- EAR -->
<property name="ear.meta-inf.dir" value="src/META-INF"/>
<target name="clean">
<delete dir="${deploy.dir}"/>
</target>
<target name="package" depends="clean">
<mkdir dir="${deploy.dir}"/>
<mkdir dir="${jar.deploy.dir}"/>
<jar destfile="${deploy.dir}/jar/VSBReportingProvider.jar" basedir="${jar.classes.dir}" includes="**/*/*.class">
<metainf dir="${jar.meta-inf.dir}" includes="*.xml"/>
</jar>
<ear destfile="${deploy.dir}/VSBReportingProvider.ear" basedir="${jar.deploy.dir}" appxml="${ear.meta-inf.dir}/application.xml">
<metainf dir="${ear.meta-inf.dir}" includes="*.xml" excludes="application.xml"/>
</ear>
</target>
<path id="wlappc.classpath">
<fileset dir="C:\Oracle\Middleware10.3.4\wlserver_10.3\server\lib">
<include name="*.jar"/>
</fileset>
</path>
<taskdef name="wldeploy" classpathref="wlappc.classpath" classname="weblogic.ant.taskdefs.management.WLDeploy"/>
<target name="deploy" depends="package">
<wldeploy action="deploy"
name="VSB Reporting Provider"
source="${deploy.dir}/VSBReportingProvider.ear"
user="weblogic"
nostage="true"
password="weblogic1"
verbose="true"
adminurl="t3://localhost:7001"
targets="AdminServer"
debug="true"/>
</target>
The response: http://pastebin.com/x0En9WtA
It keeps saying it can not connect to the server, so I checked the following:
weblogic / weblogic1 account works.
AdminServer is running, can log-on to it.
The 'Enable tunneling' option is enabled.
The same application can be installed trough the web console.
Any help or idea on where to look, would be appreciated.
I find an answer on the Middleware Magic site:
Then please make sure to add "wlfullclient.jar" at the beginning of the CLASSPATH in your >ANT Script...Also please refer to http://forums.oracle.com/forums/thread.jspa?threadID=2188580&tstart=0 - See more at: http://middlewaremagic.com/weblogic/?tag=deploy#sthash.rTLTxQK3.dpuf
see http://middlewaremagic.com/weblogic/?tag=deploy
I figured it out.
I'm working on a Windows 7 machine and was using a linux command-line tool. I don't know the reason, but the linux console wasn't showing all my environment variables, as it couldn't find or read them, I don't know.
All works fine when I deploy from Windows CMD.
I want use Ant to automate build, deployment,starting & stopping server of applications.
I'm able to build the application through Ant and copied the war file into the Tomcat webapps directory.
On the Internet, I found this article which contains more code to start and stop Tomcat. Since I can successfully deploy without those, I was wondering why they are there.
The code for my build.xml is below.
<?xml version="1.0"?>
<project name="Test" default="build-war">
<property file="build.properties"></property>
<target name="build-war" depends="clean">
<war destfile="Test.war" webxml="${web.dir}/WEB-INF/web.xml" >
<fileset dir="${web.dir}">
<include name="**/*.*"/>
</fileset>
<classes dir="${build.dir}/classes"></classes>
</war>
<copy todir="${deploy.path}" preservelastmodified="true">
<fileset
dir=".">
<include name="*.war"/>
</fileset>
</copy>
</target>
<target name="clean" description="Clean Test war directories">
<delete>
<fileset dir="${deploy.path}">
<include name="Test.war"/>
</fileset>
</delete>
</target>
</project>
There is no reliable way to (re)deploy an application to a web server. The reasons why an app might fail to deploy are numerous (thread leak, shutdown hooks, accessing parent classloaders) but in the end, there is no reliable way to tell whether a (complex) application could be deployed successfully.
This means that most developers have learned to use this cycle:
Deploy. Tomcat should automatically notice the new files and restart.
If something is odd, try to reload (ReloadTask). This tells Tomcat "no matter what you believe, the app has changed! Start it again!"
If the app still fails, stop and start Tomcat again.
If that fails, stop tomcat, delete all files, deploy again and after deployment, start Tomcat again.
If that fails, delete Tomcat and all files, reinstall, ...
Yes, I once had a script which could do every of the steps above. :-)
In the end, I gave up on deployment. My current solution is to write a Java application which creates an embedded Tomcat or Jetty server, configures it and starts the app. I have just a single classpath. No file copying, deployment or any such nonsense necessary. That way, I just have a single process, only a single web app in the container and I have all logs in one place.
how can i deploy a app in weblogic only if it is not present in it using wldeploy ant task
when i run ant testapp it deploys fresh everytime over existing app as far as i could see in console messages (ie in sysout).
i call this ant target as dependency in some other target, and i want this to run only if app is not already present in weblogic server (to be more efficient)
<target name="testapp" depends="init-wls">
<wldeploy action="deploy" verbose="true" debug="true"
name="testapp" failonerror="false"
...
source="testapp.war"/>
</target>
an interesting question. I'm not sure if wldeploy can do what you want. One approach that might work would be to use the wlconfig ant task. You could use it to get the ApplicationRuntimeMBeans and then query their ApplicationName attributes (again, with wlconfig task) to see if the application is deployed. Not super straightforward but at least you would avoid the application redeployment.
This is just a quick idea off the top of my head so not sure if it is feasible in practice, sorry.... :)
--edit: tried it out, something like this should work, the assumption here is that if we can find the MBean then it is already deployed which should be a valid assumption since these beans live under AppDeployments:
<project name="test" default="deploy">
<property name="domainName" value="ejbTestDomain"/>
<property name="serverName" value="AdminServer"/>
<property name="appName" value="ejbWebEAR"/>
<target name="findApp">
<wlconfig url="t3://localhost:7001" username="weblogic" password="password_for_weblogic">
<query pattern="${domainName}:ServerRuntime=${serverName},Name=${appName},*,Type=ApplicationRuntime" property="app.is.deployed"/>
</wlconfig>
</target>
<target name="deploy" unless="app.is.deployed" depends="findApp">
<echo message="Deploying..."/>
<!-- deploy using wldeploy task -->
</target>
</project>
<target name="CheckState">
<exec executable="${App.path}"/>
</target>
In this task, the executable will return a value which will indicate the state of my app. How could I get the value returned in the Ant build file. I will use this value to determine some behaviour.
Use the resultproperty and failonerror attributes of the exec task, e.g.:
<target name="CheckState">
<exec executable="${App.path}"
resultproperty="App.state"
failonerror="false"/>
<echo message="App state was: ${App.state}" />
</target>
Quoting from the exec task docs Errors and return codes:
By default the return code of an exec
is ignored; when you set
failonerror="true" then any return
code signaling failure (OS specific)
causes the build to fail.
Alternatively, you can set
resultproperty to the name of a
property and have it assigned to the
result code (barring immutability, of
course).
If the attempt to start the program
fails with an OS dependent error code,
then halts the build unless
failifexecutionfails is set to false.
You can use that to run a program if
it exists, but otherwise do nothing.
What do those error codes mean? Well,
they are OS dependent. On Windows
boxes you have to look at the
documentation; error code 2 means 'no
such program', which usually means it
is not on the path. Any time you see
such an error from any Ant task, it is
usually not an Ant bug, but some
configuration problem on your machine.
Here is a generic way to check the result and display the output of the execution only if the process returns a failure code.
<property
name="my.project.tmp.exec.output"
value="${tmp.dir}/exec-output.txt"/>
<target
name="my.project.my.task">
<exec
executable="${App.path}"
output="${my.project.tmp.exec.output}"
resultproperty="my.project.my.task.result"
failonerror="false"/>
<loadfile
srcfile="${my.project.tmp.exec.output}"
property="my.project.my.task.output"
/>
<fail message="ERROR: ${my.project.my.task.output}">
<condition>
<not>
<equals arg1="${my.project.my.task.result}" arg2="0"/>
</not>
</condition>
</fail>
<delete file="${my.project.tmp.exec.output}"/>
</target>