I made tomcat init.d script used by service like 'service tomcat start'. script is like this.
...
CATALINA_HOME=/opt/tomcat7/default
if [ $UID -eq 0 ]
then
RUN_COMMAND="runuser -l tomcat -c"
RUN_TOMCAT_COMMAND="sh $CATALINA_HOME/bin"
else
RUN_COMMAND="sh "
RUN_TOMCAT_COMMAND="$CATALINA_HOME/bin"
fi
...
function process_startup() {
$RUN_COMMAND "$RUN_TOMCAT_COMMAND/startup.sh"
}
...
and CATALINA_HOME and CATALINA_BASE variables are set by making script file '/etc/profile.d/tomcat.sh'. So when I type command env in shell, CATALINA_BASE and CATALINA_HOME are shown like below.
...
CATALINA_HOME=/opt/tomcat7/default
CATALINA_BASE=/var/opt/tomcat7/base
...
So logging as root when I type command 'service tomcat start', tomcat start and CATALINA_BASE is set as '/var/opt/tomcat7/base'. right!. That's natural.
But logging as another user(tomcat) when I type command 'service tomcat start', tomcat start but CATALINA_BASE is not set(if CATALINA_BASE is not set, CATALINA_BASE is same as CATALINA_HOME). So When I write line 'echo $CATALINA_BASE' in the middle of 'catalina.sh', it print blank(means variable is not set). I don't know why catalina.sh cannot see environment variable 'CATALINA_BASE' when logging as non-root user and start init.d script by service. 'CATALINA_BASE' environment variable is set apparently!!