"-Dapp.pid=%%" passes in an incorrect pid to java jvm arguments in start script

153 Views Asked by At

In the start script for my application, the service is started with the following lines:

JVM_OPTS=$DEFAULT_JVM_OPTS" "$JAVA_OPTS" "$${optsEnvironmentVar}" -Dapp.pid=$$ -Dapp.home=$APP_HOME -Dbasedir=$APP_HOME"

exec nohup "$JAVACMD" -jar $JVM_OPTS <% if ( appNameSystemProperty ) { %>\"-D${appNameSystemProperty}=$APP_BASE_NAME\" <% } %> $CLASSPATH server /resources/config.yml >  /home/testUser/stdout.out 2>  /home/testUser/stderr.err &

The application starts up fine, but on code review, we noticed that the value of -Dapp.pid was incorrect, by checking it in ps -aux | grep appName, and comparing it to the PID of that command, along with the PID outputed by pgrep -f appName. I would like to know if there is any way to assign the correct PID to the parameter. So far, I've tried setting it to be:

-Dapp.pid=`preg -f appName`

But that simply ends up with -Dapp.pid being blank, which I assume is due to it calling that command before the exec is fully run. Has anyone else come across this before?

0

There are 0 best solutions below