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

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 507: -DWEBAPP-CONF-ROOT=/usr/local/webapps-conf/: No such file or directory
/usr/local/tomcat-d-9/bin/catalina.sh line 508: -Dcas.url=https://myurl.dev.com/cas/: No such file or directory
/usr/local/tomcat-d-9/bin/catalina.sh line 515: -Dapp.id=tomcat-d-9: 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 :
"no such file or directory" : but the file/directory actually exists
"no such file or directory" : but it's for a url
"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 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
# CAS args
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"

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.

Related

Function throwing an error "Syntax error: "}" unexpected" in shell script

#! bin/env sh
function idle_tm_ubu {
sudo apt remove npsrv
sudo rm -rf /etc/npsrv.conf
sudo rm -rf /var/log/npsrv.log
IDLE = /etc/npsrv.conf
if [ ! -f "$IDLE" ]; then
echo "Idle time out has been removed."
else
echo "Idle time out has not been removed"
fi
}
if [ "${AWSSTATUS}" = "active" ]
then
echo "Amazon ssm agent is $AWSSTATUS"
idle_tm_ubu
fi
When I execute this I get the error
Syntax error: "}" unexpected
How do I solve this?
You have a few simple errors you need to correct. To begin
IDLE = /etc/npsrv.conf
should be
IDLE=/etc/npsrv.conf
No spaces are allowed around = when used for assignment.
Always paste your script into ShellCheck to find errors and warnings. Then fix them.
Note the 'function' keyword is non-standard. Use 'foo()' instead of 'function foo'.
Also ensure the path to your interpreter
#! bin/env sh
is an ABSOLUTE path. bin/env is a RELATIVE path, did you mean /bin/env?

How to jump from one directory to another directory and also display the present working directory on screen otherwise show the error?

It's showing below error :
please check the destination directory
Try this:
var=( /home/divya/dir1 /home/divya/dir2 )
for dir_list in ${var[#]}
do
cd "${dir_list}"
test="$(pwd)"
if [ "${dir_list}" = "${test}" ] ; then
echo "Destination directory is ${test}"
else
echo "Check the destination directory"
fi
done

Twice Bash command substitution

I have directories a1..a5, b1..b5 and c1..c5. Inside each directory I have two files a1, b1 and c1.
do mkdir /tmp/{a,b}$d; touch /tmp/{a,b,c}$d/{a,b,c}1; done;
I want to get all the files starting with 'a' or 'b' inside the directories starting with an 'a'. I can do it with:
DIRS=`ls -1 -d /tmp/{a,b}*/a*`
echo ${DIRS}
and obtain:
/tmp/a1/a1 /tmp/a2/a1 /tmp/a3/a1 /tmp/a4/a1 /tmp/a5/a1
/tmp/b1/a1 /tmp/b2/a1 /tmp/b3/a1 /tmp/b4/a1 /tmp/b5/a1
Now, I will use a variable called DATA to store the directories and later get the files:
DATA="/tmp/{a,b}*"
echo ${DATA}
DIRS=`ls -1 -d ${DATA}/a*`
echo ${DIRS}
In the output, the DATA contents is OK (/tmp/{a,b}*), but I receive the following error:
ls: cannot access /tmp/{a,b}*/a*: No such file or directory
Any idea why this happens?
I solved the problem, but I can't find any reference about why my previous attempts failed.
DATA="/tmp/{a,b}*"
echo ${DATA}
DIRS=`eval "ls -1 -d ${DATA}/a*"`
echo ${DIRS}
Output:
/tmp/a1/a1 /tmp/a2/a1 /tmp/a3/a1 /tmp/a4/a1 /tmp/a5/a1 /tmp/b1/a1
/tmp/b2/a1 /tmp/b3/a1 /tmp/b4/a1 /tmp/b5/a1

undefined variable error in csh script

I have one function in csh script and in this function I am using one variable which is sourced from one file. But while using script its throwing undefined error for same variable.
I am using Linux.
My Code
function init_remote_commands_to_use
{
# Test if the environment variable SSH_FOR_RCOMMANDS is present in .temip_config file,
# use secured on non secured rcommand depending on the result
if [ "$SSH_FOR_RCOMMANDS" != "" ]
then
if [ "$SSH_FOR_RCOMMANDS" = "ON" ]
then
# Check if the environment variable SSH_PATH is specified in .temip_config file
if [ "$SSH_PATH" != "" ]
then
SH_RCMD=$SSH_PATH
else
SH_RCMD=$SSH_CMD
fi
# Check if a ssh-agent is already running
if [ "$SSH_AGENT_PID" = "" ]
then
#Run ssh-agent for secured RCommands
eval `ssh-agent`
ssh-add
STARTEDBYME=YES
fi
else
if [ "$SSH_FOR_RCOMMANDS" = "OFF" ]
then
SH_RCMD=$RSH_CMD
else
echo "Please set the SSH_FOR_RCOMMANDS value to ON or OFF in the .temip_config file"
exit 1
fi
fi
else
SH_RCMD=$RSH_CMD
fi
}
below is the error:
function: Command not found.
{: Command not found.
SSH_FOR_RCOMMANDS: Undefined variable.
Please anyone suggest what I am missing?
The C Shell csh does not have functions. It does have aliases, but those are harder to write and read. For exmaple, see here: https://unix.stackexchange.com/questions/62032/error-converting-a-bash-function-to-a-csh-alias
It might be a good idea to simply switch to Bash, where your existing code may already be working.

how to declare variable name with "-" char (dash ) in linux bash script

I wrote simple script as follow
#!/bin/bash
auth_type=""
SM_Read-only="Yes"
SM_write-only="No"
echo -e ${SM_Read-only}
echo -e ${SM_Write-only}
if [ "${SM_Read-only}" == "Yes" ] && [ "${SM_Write-only}" == "Yes" ]
then
auth_type="Read Write"
else
auth_type="Read"
fi
echo -e $auth_type
And when i execute it i got following output with errors.
./script.bash: line 5: SM_Read-only=Yes: command not found
./script.bash: line 6: SM_write-only=No: command not found
only
only
Read
Any one know correct way to declare the variable with "-" (dash)?
EDIT:
have getting response from c code and evaluate the variables for example
RESP=`getValue SM_ Read-only ,Write-only 2>${ERR_DEV}`
RC=$?
eval "$RESP"
from above scripts code my c binary getValue know that script want Read-only and Write-only and return value to script.So during eval $RESP in cause error and in my script i access variable by
echo -e ${SM_Read-only}
echo -e ${SM_Write-only}
which also cause error.
Rename the variable name as follows:
SM_Read_only="Yes"
SM_write_only="No"
Please, don't use - minus sign in variable names in bash, please refer to the answer, on how to set the proper variable name in bash.
However if you generate the code, based on others output, you can simply process their output with sed:
RESP=$(getValue SM_ Read-rule,Write-rule 2>${ERR_DEV}|sed "s/-/_/g")
RC=$?
eval "$RESP"
- is not allowed in shell variable names. Only letters, numbers, and underscore, and the first character must be a letter or underscore.
I think you cant have a dash in your variables names, only letters, digits and "_"
Try:
SM_Read_only
Or
SM_ReadOnly

Resources