i needed to change the tomcat process to be executed by non root user. created user tomcat and put that in tomcat_group group. changed permissions. and then changed the startup script in init.d.
My old script which is running as a root user is
#!/bin/bash
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 234 20 80
JAVA_HOME=/usr/java/jdk1.6.0_31
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/usr/share/apache-tomcat-7.0.26
case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
esac
exit 0
This is running fine as a root user.
New script is that
#!/bin/bash
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 234 20 80
JAVA_HOME=/usr/java/jdk1.6.0_31
export JAVA_HOME
PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/usr/share/apache-tomcat-7.0.26/bin
case $1 in
start)
/bin/su tomcat $CATALINA_HOME/startup.sh
;;
stop)
/bin/su tomcat $CATALINA_HOME/shutdown.sh
;;
restart)
/bin/su tomcat $CATALINA_HOME/shutdown.sh
/bin/su tomcat $CATALINA_HOME/startup.sh
;;
esac
exit 0
but this gives error when start my service
unable to find whats the issue
This is most likely a result of changing the
$CATALINA_HOMEvariable to be the/bin.The
startup.shcalls thecatalina.shscript which depends on the$CATALINA_HOMEbeing a specific directory. I’d definitely recommend changing it back toCATALINA_HOME=/usr/share/apache-tomcat-7.0.26and then adding/binback into the command calls. Tomcat relies heavily on theCATALINA_HOMEenvironment variable.Hope that helps.
EDIT: You still need to take into account Mat’s answer, this should just fix the file not found error you are now getting.