views:

45

answers:

2

I'm currently using java service wrapper to wrap a java application that I've developed. I'm needing to ability to pass in additional command line parameters to my application through the java service wrapper.

Pretend my app is called myapp and I've setup java service wrapper so that the script I run to start is called myapp. I'd like to be able to do something like this:

./myapp start Parameter1 parameter2

and have those additional parameters get passed into my application. Any ideas how to do this? I'm finding that googling and looking at the documentation is only pulling up how to use command line arguments to setup java service wrapper. I've had difficulty finding anything about passing command line arguments to your application except for having them hard coded in your wrapper.conf file.

Right now I feel like my option is to take the additional command line parameters, set them to environment variables and have those hard coded in the wrapper.conf. I'd prefer not to go down that road though and am hoping I've overlooked something.

A: 

Can you post an example of what the "myapp" script looks like? Not the whole thing but it'd be useful to see what the part that launches the java process looks like.

What you want to accomplish should be as simple as making sure that $@ is passed into the java process by the script. In Bash, $@ is an array that contains all of the arguments passed into the script. If the wrapper produced by java service wrapper needs you to pass in "start" as one of the arguments, then you might have to add a bit of scripting to pass all of the arguments but the first to the java process.

matt b
A: 

Hi,

in the 3.5.2 release of the wrapper, we added a possibility to achieve what you are asking for, by using "--" to precede parameters to the java application: https://sourceforge.net/tracker/?func=detail&aid=3017567&group_id=39428&atid=425190

this is basically working for calling the binary of the wrapper directly, but for shell script you can easily achieve the same by modifying it a bit:

open the script and in the console(), start() ( and optionally launchdinternally()) set the command_line to the following:

    COMMAND_LINE="$CMDNICE \"$WRAPPER_CMD\" \"$WRAPPER_CONF\" wrapper.syslog.ident=\"$APP_NAME\" wrapper.pidfile=\"$PIDFILE\" wrapper.name=\"$APP_NAME\" wrapper.displayname=\"$APP_LONG_NAME\" $ANCHORPROP $STATUSPROP $LOCKPROP $@"

note the $@ at the end.

now, go to quite the end of the script, where it decides what function it should call (console, start, stop, restart, etc.)

in the 'console', 'start' (and 'launchdinternal') set a shift and pass over the parameters from the commandline to the function:

'console')
    checkUser touchlock $1
    shift
    console $@
    ;;

'start')
    if [ "$DIST_OS" = "macosx" -a -f "/Library/LaunchDaemons/${APP_PLIST}" ] ; then
        macosxstart
    else
        checkUser touchlock $1
        shift
        start $@
    fi
    ;;

.. 'launchdinternal')

    shift
    launchdinternal $@
    ;;

after that, you can call the script like this:

./script start|console -- para1 para2 ...

hope this helps you out.

cheers, christian

Tanuki Software