Java Service Shell and Advanced Application Command-Line Options

I am currently using java service wrapper to wrap the Java application that I developed. I need to be able to pass additional command line parameters to my application through the java service shell.

Pretend my application is called myapp, and I installed the java service shell, so the script that I ran is called myapp. I would like to do something like this:

./myapp start parameter1 parameter2

and these additional parameters are passed to my application. Any ideas how to do this? I find that a google search and documentation look only pulled how to use command line arguments to install a Java service shell. It was hard for me to find anything about passing command line arguments to the application, except that they were hardcoded in your wrapper.conf file.

Now I feel that my option is to take additional command line parameters, set them to environment variables and have these hardcodes in the wrapper.conf file. I would rather not follow this road, although I hope that I have missed something.

+4
source share
3 answers

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

this basically works for calling the shell binary directly, but for a shell script you can easily achieve this by modifying it a bit:

open the script and in the console (), start () (and optionally launchdinternally ()) set 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.

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

in 'console', 'start' (and 'launchdinternal') set the shift and pass parameters from the command line 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 as follows:

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

Hope this helps you.

amuses, christian

+4
source

Jake, quick escort. In version 3.5.5 of the Java Service Wrapper script, we added a new option PASS_THROUGH to the beginning, which now allows passing command-line arguments to the JVM out of the box.

The script uses the command line parameter "-", which Christian mentioned in August.

Cheers, Leif

+1
source

Can you post an example of what the "myapp" script looks like? Not all, but it would be useful to see what the part that starts the java process looks like.

What you want to do should be as simple as $@ java script process. In Bash, $@ is an array containing all the arguments passed to the script. If the shell created by the shell of the java service, you need to pass "start" as one of the arguments, you may have to add a few scripts to pass all the arguments except the first to the java process.

0
source

Source: https://habr.com/ru/post/1312774/


All Articles