[Home] [Index] [Previous] [Next]

Command Line Oddjob

Using Oddjob without Oddjob Explorer.

Command Line Help

As we saw at the beginning of this manual how to run Oddjob from the command line. For further options use:

java -jar run-oddjob.jar -h

Additional arguments are passed into Oddjob and are set as the args property of the top Oddjob. If the command line is

java -jar run-oddjob -f greeting.xml "Hello World!"

and greeting.xml contained:

<oddjob id="oddjob">
 <job>
  <echo>${oddjob.args[0]}</echo>
 </job>
</oddjob>

Then the result would be:

Hello World!

Stopping Oddjob

Oddjob has a shutdown hook that attempts to stop Oddjob cleanly when the virtual machine detects it is being asked to terminate. Usually this happens with Ctr-C or the kill signal, but the exact implementation is machine dependent.

If a job is hanging and refuses stop Oddjob will forcibly exit after 5 seconds.

In the Linux Background

Oddjob comes with a server.xml that will start a server for use on a remote machine.

The following command will run Oddjob as a Linux background process.

nohup java -jar run-oddjob.jar -f server.xml &

Opening the corresponding client.xml file from Oddjob Explorer will allow jobs to be deployed to the server from the desktop using drag and drop or by changing the configuration directly on the server using Designer.

As a Windows Service

A quick 'Google' will reveal several projects for running a Java process as a service. The one we use is Procrun which is part of the Apache Daemon Project.

This script will download Procrun, install an Oddjob Service and start it:

<oddjob>
    <job>
        <sequential>
            <jobs>
                <properties environment="env">
                    <values>
                        <value key="work.dir" value="${oddjob.home}/work"/>
                        <value key="oddjob.bin.dir" value="${oddjob.home}/bin"/>
                        <value key="apache.daemon.version" value="1.3.1"/>
                        <value key="apache.daemon.zip.file" value="commons-daemon-${apache.daemon.version}-bin-windows.zip"/>
                        <value key="apache.daemon.host" value="dlcdn.apache.org"/>
                    </values>
                </properties>
                <mkdir dir="${work.dir}" name="Create Work Dir"/>
                <web:client name="Download Procrun" url="https://${apache.daemon.host}//commons/daemon/binaries/windows/${apache.daemon.zip.file}" xmlns:web="oddjob:web">
                    <output>
                        <file file="${work.dir}/${apache.daemon.zip.file}"/>
                    </output>
                    <ssl>
                        <web:ssl/>
                    </ssl>
                </web:client>
                <ant name="Ant Task to Unzip">
                    <tasks>
                        <xml>
                            <tasks>
                                <unzip dest="${work.dir}" src="${work.dir}/${apache.daemon.zip.file}"/>
                            </tasks>
                        </xml>
                    </tasks>
                </ant>
                <copy name="Copy procurun service exe" to="${oddjob.bin.dir}/OddjobService.exe">
                    <from>
                        <file file="${work.dir}/amd64/prunsrv.exe"/>
                    </from>
                </copy>
                <exec name="Install Service">${oddjob.bin.dir}/OddjobService.exe //IS 
"--DisplayName=Oddjob Server" 
"--Description=Oddjob Server" 
"--Jvm=${java.home}\bin\server\jvm.dll" 
--Classpath=${oddjob.run.jar} 
--StartMode=jvm --StopMode=jvm 
--StartClass=org.oddjob.launch.Launcher
--StartMethod=main --StartParams=-f;${oddjob.home}\server-web.xml 
--StopClass=org.oddjob.launch.Launcher --StopMethod=stop 
--LogPath=${oddjob.home}\logs --LogLevel=TRACE --LogJniMessages=1
--StdOutput=auto --StdError=auto 
--ServiceUser=${env.USERDOMAIN}\${env.USERNAME}
--ServicePassword=${my.win.password}
--Startup=auto
</exec>
                <exec name="Start Service">${oddjob.bin.dir}/OddjobService.exe //ES
</exec>
                <folder>
                    <jobs>
                        <exec name="Delete Service">${oddjob.bin.dir}/OddjobService.exe //DS
</exec>
                    </jobs>
                </folder>
            </jobs>
        </sequential>
    </job>
</oddjob>

Note that the double quotes are required to use the environment variables.

Another option would be Java Service Wrapper.

When Things Go Wrong

By default Oddjob writes to a log file called oddjob.log which will be in the same directory that Oddjob was started from.

The logging configuration is in the log4j.properties file located in oddjob_dir/opt/class. Changing the logging level to debug may provide additional information.


[Home] [Index] [Previous] [Next]