linuxtomcattomcat9catalina

Tomcat 9 not starting on linux - Catalina.sh can't use JAVA_OPTS


We have a new Tomcat 9 installed but we're having an issue when starting it.

It seems catalina.sh isn't able to work with the JAVA_OPTS, here what the log says :

/usr/local/tomcat-d-9/bin/catalina.sh line 505: -Djava.security.auth.login.config=: command not found

The WEBAPP repo (line 507) actually exists so I'm confused, also why is it interpreting a url (line 508) as a dir/repo ?
These are only 3 examples of the errors in the log to illustrate the issue, but this is happening for every single JAVA_OPTS in my setenv.sh . It's either :

  1. "no such file or directory" : but the file/directory actually exists
  2. "no such file or directory" : but it's for a url
  3. "command not found" : but it's not a command to run, just a parameter

I'm fairly new to this so I might be missing something obvious. Any idea what could be happening here ?

Here's my edited setenv.sh

#!/bin/bash
COMMON="/usr/local/etc/BashStartFunctions.bash"
[ ! -e "$COMMON" ] && echo "Missing $COMMON" && exit 1
source $COMMON
checkUsr
fetchAppEnv

echo "PRG=$1"

JAVA_OPTS="${JAVA_OPTS_EXTRA}
   -Dspring.profiles.active=dev \
   -Djava.library.path=/usr/lib64:/usr/local/tomcat-apr-connector/lib:/lib64 \
   -DWEBAPP-CONF-ROOT=${WEBAPP_CONF_ROOT} \
   -Dcas.url=${CAS_URL} \
   -Dserver.url=${SERVER_URL} \
   -Dcom.vmd.xmltcp.client.XmltcpClient.reuseClientSocket=false \
   -Dcom.aubesoft.jdbc.recovery.ChainedJdbcExecutionWithRecoveryHelper.overrideChainProcessorRecoveryFile=${overrideChainProcessorRecoveryFile} \
   -Dcom.aubesoft.jdbc.recovery.ChainedJdbcExecutionWithRecoveryHelper.overrideInChainRecoveryFile=${overrideInChainRecoveryFile} \
   -Dcom.aubesoft.jdbc.recovery.RecoveryPolicy.overrideDefaultRecoveryFile=${overrideDefaultRecoveryFile} \
   -Djavax.net.ssl.trustStore=${TRUSTSTORE} \
   -Dapp.id=${APP_ID} \
   -Dserver.xml.serverPort=${SERVER_PORT} \
   -Djava.awt.headless=true"

if [ "$1" = "start" ];then
   JAVA_OPTS="${JAVA_OPTS} \
   -Denv=${APP_ENV} \
   -Dtomcat.hosts=${TOMCAT_HOSTS} \
   -Dstore.url=${store_url} \
   -Dlog.dir=${LOG_DIR} \
   -Dserver.xml.httpPort=${HTTP_PORT} \
   -Dserver.xml.ajp13Port=${AJP13_PORT} \
   -Dserver.xml.ajp13.maxThreads=${AJP13_MAX_THREADS} \
   -Dserver.xml.httpsPort=${HTTPS_PORT} \
   -Dserver.xml.https.maxThreads=${HTTPS_MAX_THREADS} \
   -Dserver.xml.https.sslCertFile=${HTTPS_CERT_FILE} \
   -Dserver.xml.https.sslCertKeyFile=${HTTPS_CERT_KEY_FILE} \
   -Dserver.xml.https.sslKeystoreFile=${HTTPS_KEYSTORE_FILE} \
   -Dserver.xml.https.sslKeystorePass=${HTTPS_KEYSTORE_PASS} \
   -Dserver.xml.https.sslKeyAlias=${HTTPS_KEYSTORE_KEY_ALIAS} \
   -Dserver.xml.jvmRoute=${HOSTNAME}.${AJP13_PORT} \
   -Dserver.xml.maxHeaderSize=${MAX_HEADER_SIZE} \
   -Dcom.sun.management.jmxremote \
   -Dcom.sun.management.jmxremote.port=${JMX_PORT} \
   -Dcom.sun.management.jmxremote.ssl=false \
   -Dcom.sun.management.jmxremote.authenticate=false \
   -Dscoperta.zone=${SCOPERTA_ZONE} \
   -Dscoperta.env=${APP_ENV} \
   -Dhttps.protocols=TLSv1 \
   -Dsmartd.authentication.signing.secret.file=${SMARTD_AUTHENTICATION_SIGNING_SECRET_FILE} \
   -Dspring.profiles.active=${SMARTD_SPRING_PROFILES}
   "


   if [ ! -z ${CAS_SECURE} ]; then
      JAVA_OPTS="${JAVA_OPTS} -Djava.security.auth.login.config=${JAAS_CONFIG} \
        -Djava.security.krb5.kdc=${KRB5_KDC} \
        -Djava.security.krb5.realm=${KRB5_REALM} \
        -Dcas.TGTTimeoutMS=${CAS_TGT_TIMEOUT_MS} \
        -Dcas.secure=${CAS_SECURE}"
   fi

fi

CATALINA_OUT=/usr/local/tomcat-d-9/logs/catalina_${APP_ID}.out

echo "JAVA_OPTS=$JAVA_OPTS"

EDIT

After the answer of @Olaf Kock, It's now partially working.

The last if in setenv.sh is now the only portion with the error message. I edited the post to show what it currently looks like.


Solution

  • You're splitting up your settings into multiple lines:

    -DWEBAPP-CONF-ROOT=/usr/local/webapps-conf/: No such file or directory
    

    does not refer to /usr/local/webapps-conf/ not existing, but -DWEBAPP-CONF-ROOT=/usr/local/webapps-conf/ not existing (obviously)

    You can escape the linebreaks using a \, e.g.

    JAVA_OPTS="${JAVA_OPTS} \
    -Denv=${APP_ENV} \
    -Dtomcat.hosts=${TOMCAT_HOSTS} \
    ....
    

    or

    JAVA_OPTS="${JAVA_OPTS} -Denv=${APP_ENV}"
    JAVA_OPTS="${JAVA_OPTS} -Dtomcat.hosts=${TOMCAT_HOSTS}"
    ....
    

    or just write them all in a single line.

    Also, consider to use CATALINA_OPTS, rather than JAVA_OPTS.