Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java service wrapper and additional application command line parameters

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.

like image 543
Jake Avatar asked Jun 14 '10 16:06

Jake


1 Answers

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

like image 164
Naytzyrhc Avatar answered Sep 28 '22 08:09

Naytzyrhc