05 March 2008

Starting OC4J from Ant

Good question today from a colleague in Dublin, who basically wanted to know how to start an OC4J instance from Ant using the oc4j:restart.

On the surface that looks like a reasonable thing to do. The problem though is that the OC4J Ant tasks actually require a connection to be made to the server in order to execute the operation -- so if the OC4J instance is down, you can't issue a restart since you can't connect to it.

For situations where the OC4J instance is being managed by OPMN, then one possible solution to this is to call out to the opmnctl executable and ask it to start the OC4J instance.

To do this, you can make use of the ant:exec task as shown below:


<project name="opmn" basedir="." default="status">
<property name="oracle.home" value="d:/oracleas/10131/ohs_j2ee"/>
<property name="opmn.cmd" value="${oracle.home}/opmn/bin/opmnctl.exe"/>

<target name="base" description="Verify callout to opmnctl">
<exec executable="${opmn.cmd}"/>
</target>

<target name="status" description="Show the current status">
<exec executable="${opmn.cmd}">
<arg line="status"/>
</exec>
</target>

<!-- Start the oc4j.name instance-->
<target name="start-oc4j" description="Start the oc4j.name instance" depends="get-oc4j-name">
<echo message="${opmn.cmd} startproc process-type=${oc4j.name}"/>
<exec executable="${opmn.cmd}">
<arg line="startproc process-type=${oc4j.name}"/>
</exec>
<antcall target="status"/>
</target>

<target name="get-oc4j-name" unless="oc4j.name">
<input message="Specify OC4J instance: " addproperty="oc4j.name"/>
</target>
</project>


When this executes, it prompts for the OC4J instance name, calls opmnctl to execute a startproc on it and then displays the status.


>ant -f opmn.xml start-oc4j
Buildfile: opmn.xml

get-oc4j-name:
[input] Specify OC4J instance:
fred

start-oc4j:
[echo] d:/oracleas/10131/ohs_j2ee/opmn/bin/opmnctl.exe startproc process-type=fred
[exec] opmnctl: starting opmn managed processes...

status:

[exec] Processes in Instance: ohs_j2ee_changed
[exec] ---------------------------------+--------------------+---------+---------
[exec] ias-component | process-type | pid | status
[exec] ---------------------------------+--------------------+---------+---------
[exec] OC4JGroup:default_group | OC4J:foo | 2128 | Alive
[exec] OC4JGroup:default_group | OC4J:fred | 6012 | Alive
[exec] OC4JGroup:default_group | OC4J:home | N/A | Down

4 comments:

Anonymous said...

Hi,
if i have to start opmnctl in one server and stop in another how to achieve this using ANT?

Anonymous said...

Hi,
How can i use opmnctl command to start opmn managed processes of another machine.

Buttso said...

You just need to change the "opmnctl" command so that it references the instance you wish to interact with.

You specify the target instance using a pattern of

opmnctl @instance:<name> <command>

See here for details:

http://download-west.oracle.com/docs/cd/B15904_01/core.1012/b13996/tasks.htm#i1017215

Anonymous said...

Hi,
Thanks for ur reply. But still i am unable to get through on this.
The problem is that:
The application server is hosted on a linux machine. Then there are 2 nodes on which the application server is installed. But I am using the opmnctl command as you have suggested in the ANT script which runs on the windows machine. Could you please help me how I can achieve this? Is it the best practice to start/stop opmnctl of a remote server using ANT?