Bug 65240 - Multi line CATALINA_OPTS is failing in with new catalina.sh
Summary: Multi line CATALINA_OPTS is failing in with new catalina.sh
Status: RESOLVED WONTFIX
Alias: None
Product: Tomcat 7
Classification: Unclassified
Component: Integration (show other bugs)
Version: 7.0.108
Hardware: PC Linux
: P2 normal (vote)
Target Milestone: ---
Assignee: Tomcat Developers Mailing List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-13 19:18 UTC by Maciej Jaros
Modified: 2021-04-26 12:14 UTC (History)
0 users



Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Maciej Jaros 2021-04-13 19:18:53 UTC
Steps:
1. Add setenv.sh with multiline variable.
2. Run tomcat (e.g. via init.d script).

In log I got things like:
/usr/share/apache-tomcat-7.0.108/bin/catalina.sh: line 509: -Dfile.encoding=UTF-8: command not found

This is with `sentenv.sh` more or less like this:
```
if [ "$1" != "stop" ] ; then
    CATALINA_OPTS="$CATALINA_OPTS -Xms512m -Xmx1800m -XX:MaxPermSize=512m -XX:NewRatio=4 -XX:+UseCompressedOops
        -Dcom.sun.management.jmxremote
        -Dfile.encoding=UTF-8
    "
fi
```

There were more options but I guess any lines will be a problem there.

The solution for me was to change evals to something like:
eval exec "\"$_RUNJDB\"" "\"$CATALINA_LOGGING_CONFIG\"" $LOGGING_MANAGER "$JAVA_OPTS" $CATALINA_OPTS \

So basically replace `"$CATALINA_OPTS"` with `$CATALINA_OPTS`.

Not sure why was this changed to quoted var? Seem to have worked fine before. At least for us ;-)
Comment 1 Christopher Schultz 2021-04-14 18:51:11 UTC
The origin of the quoted CATALINA_OPTS is bug #63815. I would recommend you read-through that bug to see why we are quoting CATALINA_OPTS.

I'm curious about your use-case of needing a multi-line value in CATALINA_OPTS.
Comment 2 Maciej Jaros 2021-04-15 21:47:58 UTC
Interesting case... Never had problem with stars in options. I guess because we keep application options in a properties file (and just point to the properties file).

Use case for multiline is quite simple really -- readability, editing and cleaner diffs. I would be surprised if it's not a common way of doing that.

We have quite a lot of that so that so more like this on a devel machine:
```
        -DmolnetConfigLocation=file:$CATALINA_BASE/conf/app.properties
        -Dspring.profiles.active=.
        -Dcom.sun.management.jmxremote
        -Dcom.sun.management.jmxremote.port=.
        -Dcom.sun.management.jmxremote.ssl=.
        -Dcom.sun.management.jmxremote.authenticate=.
        -Dcom.sun.management.jmxremote.local.only=.
        -Djava.rmi.server.hostname=.
        -Dfile.encoding=.
        -agentlib:jdwp=.
```
Nice and easy to ready, change, copy. Great for diffs in git.
Comment 3 mgrigorov 2021-04-16 12:35:03 UTC
Can you use trailing '\':

 -DmolnetConfigLocation=file:$CATALINA_BASE/conf/app.properties \
        -Dspring.profiles.active=. \
        -Dcom.sun.management.jmxremote \
        -Dcom.sun.management.jmxremote.port=. \
        ...

?

I haven't tried it but I think it should work.
Comment 4 Mark Thomas 2021-04-26 12:14:45 UTC
Local testing confirms that using a trailing '\' has the same effect as the quoting before the bug 63815 fix (the new lines are removed).

Another option I have seen used is:
CATALINA_OPTS="-Dfoo1=bar1"
CATALINA_OPTS="$CATALINA_OPTS -Dfoo2=bar2"
etc.

The fix for bug 63815 has been in place for over a year and this is the first report I recall of issues with multi-line variables.

I don't see a simple way to filter out the newlines using /bin/sh so I am going to resolve this as WONTFIX. The recommended workaround is to use one of the two alternative approaches described above.