Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 942
Asghar Avatar asked Jul 01 '26 18:07

Asghar


2 Answers

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?

like image 190
Martin Ivančič Avatar answered Jul 04 '26 15:07

Martin Ivančič


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

/bin/su tomcat -c whatever_command
like image 30
Mat Avatar answered Jul 04 '26 14:07

Mat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!