Hosted by:
SourceForge
Get Firefox!

Launching Your Application (Linux / UNIX)
Launching Your Application (Linux / UNIX)
Launching Your Application
Launching Your Application (Win32)
Setup The Scripts

The Wrapper is shipped with a sh script which can be used to reliably start and stop any Java application controlled by the Java Service Wrapper.

First copy the sh script to the bin directory of your application.

{WRAPPER_HOME}\src\bin\sh.script.in

Rename the script file to reflect the name of the application.

/usr/lib/myapp/bin/myapp

Now open the script into an editor. We need to set the long and short names to reflect that the script is being used to launch your application. You will see two variables immediately after the header of the script. APP_NAME and APP_LONG_NAME. Note that the default values of both of these variables are Ant friendly tokens which can easily be replaced as part of a build. Suggested values for these variables are shown below.

APP_NAME="myapp"
APP_LONG_NAME="My Application"

The script should not require any additional modification. However it does assume that it is placed into the same directory as the wrapper executable. It also assumes that the wrapper.conf file will be located within a conf directory one level up, ../conf/wrapper.conf. If you wish to locate this file someplace else, then that can also be set using the WRAPPER_CONF variable in the script.

NOTE

Important! Before proceeding, please make sure that both the script and the wrapper executable have their executable bit set.

NOTE

The sh script will attempt to create a pid file in the /var/run. If the user used to launch the Wrapper does not have permission to write to this directory then this will result in an error. An alternative that will work in most cases is to write the pid file to the same directory where the wrapper executable is located. To make this change, edit the sh script and change the following line:

PIDDIR="/var/run"

to:

PIDDIR="./"
Running in a Console

The application can now be run by simply executing bin/myapp console. Because of the way the Wrapper script sets its current directory, it is not necessary to run this script from within the bin directory.

/usr/lib/myapp/bin/myapp console
Running My Application...
wrapper  | --> Wrapper Started as Console
wrapper  | Launching a JVM...
jvm 1    | Wrapper (Version 3.x.x)
jvm 1    |

When running using the console command, output from the JVM will be visible in the console.

The application can be terminated by hitting CTRL-C in the command window. This will cause the Wrapper to shut down the application cleanly.

As you will see if you omit a command, the scripts shipped with the wrapper are fairly standard daemon scripts. They accept console, start, stop, restart, status, and dump commands. The start, stop, and restart commands are common to most daemon scripts and are used to control the wrapper and its application as a daemon process. The status command can be used to find out whether or not the wrapper is currently running. The console command will launch the wrapper in the current shell, making it possible to kill the application with CTRL-C. The final command, dump, will send a kill -3 signal to the wrapper causing the its JVM to do a full thread dump.

Running as a Daemon Process

The application can be run as a detatched daemon process by executing the script using the start command.

/usr/lib/myapp/bin/myapp start
Running My Application...

When running using the start command, output from the JVM will only be visible by viewing the wrapper.log file using tail -f wrapper.log

Because the application is running as a detatched process, it can not be terminated using CTRL-C and will continue to run even if the console is closed.

To stop the application rerun the script using the stop command.

/usr/lib/myapp/bin/myapp stop
Stopping Test Wrapper Sample Application...
Stopped Test Wrapper Sample Application.
Installing The Application To Start on Reboot

Installing the application to start up when the system boots and shutdown when the system shutsdown is platform specific. I have tried to include instructions for platforms which I have access to. If your platform is not included, please read over those that have been included and adapt as necessary. Please post what you come up with to the wrapper-user@sourceforge.net mailing list and I will be more than happy to include them in the next release.

by Leif Mortenson

last modified: