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
I know this is an old question, but this answer might benefit someone.
I had the same issue with the "No such file or directory". I ran the service command as a shell script
$> /etc/init.d/tomcat stop
which returned:
-bash: /etc/init.d/tomcat: /bin/bash^M: bad interpreter: No such file or directory
Because I created the script in Windows environment it had Windows line endings. As soon as I fixed that, Tomcat could be started as a service without problems.
This article might help with line changing How to convert DOS/Windows newline (CRLF) to Unix newline (\n) in a Bash script?
su needs a -c if you want to start a command with it:
/bin/su tomcat -c whatever_command
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With