Asghar
Asghar

Reputation: 2346

tomcat startup script error

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

Upvotes: 2

Views: 11893

Answers (3)

Martin Ivančič
Martin Ivančič

Reputation: 121

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?

Upvotes: 6

clmarquart
clmarquart

Reputation: 4711

This is most likely a result of changing the $CATALINA_HOME variable to be the /bin.

The startup.sh calls the catalina.sh script which depends on the $CATALINA_HOME being a specific directory. I'd definitely recommend changing it back to CATALINA_HOME=/usr/share/apache-tomcat-7.0.26 and then adding /bin back into the command calls. Tomcat relies heavily on the CATALINA_HOME environment 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.

Upvotes: 1

Mat
Mat

Reputation: 206689

su needs a -c if you want to start a command with it:

/bin/su tomcat -c whatever_command

Upvotes: 2

Related Questions