You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by tomcatastrophe <na...@changethings.org> on 2009/06/25 15:46:35 UTC
Tomcat startup as service on CentOS 5.3
I have found and tried some startup scripts online and added them to
/etc/init.d as tomcat, so /etc/init.d/tomcat
I ran chmod a+x tomcat on the script and then chkconfig --add tomcat
chkconfig --list shows tomcat in the list
I have modified the script to have the proper location for my tomcat
installation.
When I try to run /etc/init.d/tomcat restart or /sbin/service tomcat restart
(or stop or start) I get this error:
-bash: /etc/init.d/tomcat: /bin/bash^M: bad interpreter: No such file or
directory
Any help would be great! I just need this to start as a service.
Here is the script I've been trying:
#!/bin/bash
#
# Init file for SixSigns Tomcat server
#
# chkconfig: 2345 55 25
# description: SixSigns Tomcat server
#
# Source function library.
. /etc/init.d/functions
RUN_AS_USER=root # Adjust run user here
CATALINA_HOME=/work/tomcat/apache-tomcat-6.0.20
start() {
echo "Starting Tomcat: "
if [ "x$USER" != "x$RUN_AS_USER" ]; then
su - $RUN_AS_USER -c "$CATALINA_HOME/bin/startup.sh"
else
$CATALINA_HOME/bin/startup.sh
fi
echo "done."
}
stop() {
echo "Shutting down Tomcat: "
if [ "x$USER" != "x$RUN_AS_USER" ]; then
su - $RUN_AS_USER -c "$CATALINA_HOME/bin/shutdown.sh"
else
$CATALINA_HOME/bin/shutdown.sh
fi
echo "done."
}
case "$1" in
start)
start
;;
stop)
stop
;;
restart)
stop
sleep 10
#echo "Hard killing any remaining threads.."
#kill -9 `cat $CATALINA_HOME/work/catalina.pid`
start
;;
*)
echo "Usage: $0 {start|stop|restart}"
esac
exit 0
--
View this message in context: http://www.nabble.com/Tomcat-startup-as-service-on-CentOS-5.3-tp24203574p24203574.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat startup as service on CentOS 5.3
Posted by tomcatastrophe <na...@changethings.org>.
Ok, I changed the owner and it works now. :)
tomcatastrophe wrote:
>
> I have gotten the script to work now, but I do want to change the user.
> When I change to a user that isn't root I get permission denied errors
> when trying to run the script.
>
> What do I need to do to get a different user to be able to run the script?
>
> Normally I'd just run sudo, but I'm not sure how to accomplish that with
> this script.
>
> I'm a little stuck.
>
>
> Jason Pyeron wrote:
>>
>>
>>> -----Original Message-----
>>> From: tomcatastrophe
>>> Sent: Thursday, June 25, 2009 9:47
>>> Subject: Tomcat startup as service on CentOS 5.3
>>>
>>>
>>> I have found and tried some startup scripts online and added
>>> them to /etc/init.d as tomcat, so /etc/init.d/tomcat
>>>
>>> I ran chmod a+x tomcat on the script and then chkconfig --add tomcat
>>>
>>> chkconfig --list shows tomcat in the list
>>>
>>> I have modified the script to have the proper location for my
>>> tomcat installation.
>>>
>>> When I try to run /etc/init.d/tomcat restart or /sbin/service
>>> tomcat restart (or stop or start) I get this error:
>>>
>>> -bash: /etc/init.d/tomcat: /bin/bash^M: bad interpreter: No
>>> such file or directory
>>
>> Edit in nano
>>
>> Then save / write output
>>
>> When it asks for the name esc-d I think to save as unix line ending.
>>
>>
>>>
>>> Any help would be great! I just need this to start as a service.
>>>
>>> Here is the script I've been trying:
>>>
>>> #!/bin/bash
>>> #
>>> # Init file for SixSigns Tomcat server
>>> #
>>> # chkconfig: 2345 55 25
>>> # description: SixSigns Tomcat server
>>> #
>>>
>>> # Source function library.
>>> . /etc/init.d/functions
>>>
>>> RUN_AS_USER=root # Adjust run user here
>>> CATALINA_HOME=/work/tomcat/apache-tomcat-6.0.20
>>>
>>> start() {
>>> echo "Starting Tomcat: "
>>> if [ "x$USER" != "x$RUN_AS_USER" ]; then
>>> su - $RUN_AS_USER -c "$CATALINA_HOME/bin/startup.sh"
>>> else
>>> $CATALINA_HOME/bin/startup.sh
>>> fi
>>> echo "done."
>>> }
>>> stop() {
>>> echo "Shutting down Tomcat: "
>>> if [ "x$USER" != "x$RUN_AS_USER" ]; then
>>> su - $RUN_AS_USER -c "$CATALINA_HOME/bin/shutdown.sh"
>>> else
>>> $CATALINA_HOME/bin/shutdown.sh
>>> fi
>>> echo "done."
>>> }
>>>
>>> case "$1" in
>>> start)
>>> start
>>> ;;
>>> stop)
>>> stop
>>> ;;
>>> restart)
>>> stop
>>> sleep 10
>>> #echo "Hard killing any remaining threads.."
>>> #kill -9 `cat $CATALINA_HOME/work/catalina.pid`
>>> start
>>> ;;
>>> *)
>>> echo "Usage: $0 {start|stop|restart}"
>>> esac
>>>
>>> exit 0
>>> --
>>> View this message in context:
>>> http://www.nabble.com/Tomcat-startup-as-service-on-CentOS-5.3-
>>> tp24203574p24203574.html
>>> Sent from the Tomcat - User mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>
>> --
>> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>> - -
>> - Jason Pyeron PD Inc. http://www.pdinc.us -
>> - Principal Consultant 10 West 24th Street #100 -
>> - +1 (443) 269-1555 x333 Baltimore, Maryland 21218 -
>> - -
>> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
>> This message is copyright PD Inc, subject to license 20080407P00.
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>>
>>
>
>
--
View this message in context: http://www.nabble.com/Tomcat-startup-as-service-on-CentOS-5.3-tp24203574p24204895.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat startup as service on CentOS 5.3
Posted by tomcatastrophe <na...@changethings.org>.
I have gotten the script to work now, but I do want to change the user. When
I change to a user that isn't root I get permission denied errors when
trying to run the script.
What do I need to do to get a different user to be able to run the script?
Normally I'd just run sudo, but I'm not sure how to accomplish that with
this script.
I'm a little stuck.
Jason Pyeron wrote:
>
>
>> -----Original Message-----
>> From: tomcatastrophe
>> Sent: Thursday, June 25, 2009 9:47
>> Subject: Tomcat startup as service on CentOS 5.3
>>
>>
>> I have found and tried some startup scripts online and added
>> them to /etc/init.d as tomcat, so /etc/init.d/tomcat
>>
>> I ran chmod a+x tomcat on the script and then chkconfig --add tomcat
>>
>> chkconfig --list shows tomcat in the list
>>
>> I have modified the script to have the proper location for my
>> tomcat installation.
>>
>> When I try to run /etc/init.d/tomcat restart or /sbin/service
>> tomcat restart (or stop or start) I get this error:
>>
>> -bash: /etc/init.d/tomcat: /bin/bash^M: bad interpreter: No
>> such file or directory
>
> Edit in nano
>
> Then save / write output
>
> When it asks for the name esc-d I think to save as unix line ending.
>
>
>>
>> Any help would be great! I just need this to start as a service.
>>
>> Here is the script I've been trying:
>>
>> #!/bin/bash
>> #
>> # Init file for SixSigns Tomcat server
>> #
>> # chkconfig: 2345 55 25
>> # description: SixSigns Tomcat server
>> #
>>
>> # Source function library.
>> . /etc/init.d/functions
>>
>> RUN_AS_USER=root # Adjust run user here
>> CATALINA_HOME=/work/tomcat/apache-tomcat-6.0.20
>>
>> start() {
>> echo "Starting Tomcat: "
>> if [ "x$USER" != "x$RUN_AS_USER" ]; then
>> su - $RUN_AS_USER -c "$CATALINA_HOME/bin/startup.sh"
>> else
>> $CATALINA_HOME/bin/startup.sh
>> fi
>> echo "done."
>> }
>> stop() {
>> echo "Shutting down Tomcat: "
>> if [ "x$USER" != "x$RUN_AS_USER" ]; then
>> su - $RUN_AS_USER -c "$CATALINA_HOME/bin/shutdown.sh"
>> else
>> $CATALINA_HOME/bin/shutdown.sh
>> fi
>> echo "done."
>> }
>>
>> case "$1" in
>> start)
>> start
>> ;;
>> stop)
>> stop
>> ;;
>> restart)
>> stop
>> sleep 10
>> #echo "Hard killing any remaining threads.."
>> #kill -9 `cat $CATALINA_HOME/work/catalina.pid`
>> start
>> ;;
>> *)
>> echo "Usage: $0 {start|stop|restart}"
>> esac
>>
>> exit 0
>> --
>> View this message in context:
>> http://www.nabble.com/Tomcat-startup-as-service-on-CentOS-5.3-
>> tp24203574p24203574.html
>> Sent from the Tomcat - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>
> --
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> - -
> - Jason Pyeron PD Inc. http://www.pdinc.us -
> - Principal Consultant 10 West 24th Street #100 -
> - +1 (443) 269-1555 x333 Baltimore, Maryland 21218 -
> - -
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> This message is copyright PD Inc, subject to license 20080407P00.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Tomcat-startup-as-service-on-CentOS-5.3-tp24203574p24204690.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat startup as service on CentOS 5.3
Posted by tomcatastrophe <na...@changethings.org>.
Sure enough, this did it! VERY helpful.
Jason Pyeron wrote:
>
>
>> -----Original Message-----
>> From: tomcatastrophe
>> Sent: Thursday, June 25, 2009 9:47
>> Subject: Tomcat startup as service on CentOS 5.3
>>
>>
>> I have found and tried some startup scripts online and added
>> them to /etc/init.d as tomcat, so /etc/init.d/tomcat
>>
>> I ran chmod a+x tomcat on the script and then chkconfig --add tomcat
>>
>> chkconfig --list shows tomcat in the list
>>
>> I have modified the script to have the proper location for my
>> tomcat installation.
>>
>> When I try to run /etc/init.d/tomcat restart or /sbin/service
>> tomcat restart (or stop or start) I get this error:
>>
>> -bash: /etc/init.d/tomcat: /bin/bash^M: bad interpreter: No
>> such file or directory
>
> Edit in nano
>
> Then save / write output
>
> When it asks for the name esc-d I think to save as unix line ending.
>
>
>>
>> Any help would be great! I just need this to start as a service.
>>
>> Here is the script I've been trying:
>>
>> #!/bin/bash
>> #
>> # Init file for SixSigns Tomcat server
>> #
>> # chkconfig: 2345 55 25
>> # description: SixSigns Tomcat server
>> #
>>
>> # Source function library.
>> . /etc/init.d/functions
>>
>> RUN_AS_USER=root # Adjust run user here
>> CATALINA_HOME=/work/tomcat/apache-tomcat-6.0.20
>>
>> start() {
>> echo "Starting Tomcat: "
>> if [ "x$USER" != "x$RUN_AS_USER" ]; then
>> su - $RUN_AS_USER -c "$CATALINA_HOME/bin/startup.sh"
>> else
>> $CATALINA_HOME/bin/startup.sh
>> fi
>> echo "done."
>> }
>> stop() {
>> echo "Shutting down Tomcat: "
>> if [ "x$USER" != "x$RUN_AS_USER" ]; then
>> su - $RUN_AS_USER -c "$CATALINA_HOME/bin/shutdown.sh"
>> else
>> $CATALINA_HOME/bin/shutdown.sh
>> fi
>> echo "done."
>> }
>>
>> case "$1" in
>> start)
>> start
>> ;;
>> stop)
>> stop
>> ;;
>> restart)
>> stop
>> sleep 10
>> #echo "Hard killing any remaining threads.."
>> #kill -9 `cat $CATALINA_HOME/work/catalina.pid`
>> start
>> ;;
>> *)
>> echo "Usage: $0 {start|stop|restart}"
>> esac
>>
>> exit 0
>> --
>> View this message in context:
>> http://www.nabble.com/Tomcat-startup-as-service-on-CentOS-5.3-
>> tp24203574p24203574.html
>> Sent from the Tomcat - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
>
> --
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> - -
> - Jason Pyeron PD Inc. http://www.pdinc.us -
> - Principal Consultant 10 West 24th Street #100 -
> - +1 (443) 269-1555 x333 Baltimore, Maryland 21218 -
> - -
> -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
> This message is copyright PD Inc, subject to license 20080407P00.
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Tomcat-startup-as-service-on-CentOS-5.3-tp24203574p24203818.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
RE: Tomcat startup as service on CentOS 5.3
Posted by Jason Pyeron <jp...@pdinc.us>.
> -----Original Message-----
> From: tomcatastrophe
> Sent: Thursday, June 25, 2009 9:47
> Subject: Tomcat startup as service on CentOS 5.3
>
>
> I have found and tried some startup scripts online and added
> them to /etc/init.d as tomcat, so /etc/init.d/tomcat
>
> I ran chmod a+x tomcat on the script and then chkconfig --add tomcat
>
> chkconfig --list shows tomcat in the list
>
> I have modified the script to have the proper location for my
> tomcat installation.
>
> When I try to run /etc/init.d/tomcat restart or /sbin/service
> tomcat restart (or stop or start) I get this error:
>
> -bash: /etc/init.d/tomcat: /bin/bash^M: bad interpreter: No
> such file or directory
Edit in nano
Then save / write output
When it asks for the name esc-d I think to save as unix line ending.
>
> Any help would be great! I just need this to start as a service.
>
> Here is the script I've been trying:
>
> #!/bin/bash
> #
> # Init file for SixSigns Tomcat server
> #
> # chkconfig: 2345 55 25
> # description: SixSigns Tomcat server
> #
>
> # Source function library.
> . /etc/init.d/functions
>
> RUN_AS_USER=root # Adjust run user here
> CATALINA_HOME=/work/tomcat/apache-tomcat-6.0.20
>
> start() {
> echo "Starting Tomcat: "
> if [ "x$USER" != "x$RUN_AS_USER" ]; then
> su - $RUN_AS_USER -c "$CATALINA_HOME/bin/startup.sh"
> else
> $CATALINA_HOME/bin/startup.sh
> fi
> echo "done."
> }
> stop() {
> echo "Shutting down Tomcat: "
> if [ "x$USER" != "x$RUN_AS_USER" ]; then
> su - $RUN_AS_USER -c "$CATALINA_HOME/bin/shutdown.sh"
> else
> $CATALINA_HOME/bin/shutdown.sh
> fi
> echo "done."
> }
>
> case "$1" in
> start)
> start
> ;;
> stop)
> stop
> ;;
> restart)
> stop
> sleep 10
> #echo "Hard killing any remaining threads.."
> #kill -9 `cat $CATALINA_HOME/work/catalina.pid`
> start
> ;;
> *)
> echo "Usage: $0 {start|stop|restart}"
> esac
>
> exit 0
> --
> View this message in context:
> http://www.nabble.com/Tomcat-startup-as-service-on-CentOS-5.3-
> tp24203574p24203574.html
> Sent from the Tomcat - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
- -
- Jason Pyeron PD Inc. http://www.pdinc.us -
- Principal Consultant 10 West 24th Street #100 -
- +1 (443) 269-1555 x333 Baltimore, Maryland 21218 -
- -
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
This message is copyright PD Inc, subject to license 20080407P00.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat startup as service on CentOS 5.3
Posted by Markus Schönhaber <to...@list-post.mks-mail.de>.
tomcatastrophe:
> I was using root just trying to get it to work. I'm not sure what you mean
> about line endings here... I don't have any \n in my file... or do you mean
> the character return ? I'm a little confused.
I'm talking about the character(s) that denotes a line ending, "return"
in a manner of speaking.
Fix the line endings of your script using dos2unix or, as Jason
proposed, using nano.
--
Regards
mks
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat startup as service on CentOS 5.3
Posted by tomcatastrophe <na...@changethings.org>.
I was using root just trying to get it to work. I'm not sure what you mean
about line endings here... I don't have any \n in my file... or do you mean
the character return ? I'm a little confused.
Markus Schönhaber-10 wrote:
>
> tomcatastrophe:
>
>> When I try to run /etc/init.d/tomcat restart or /sbin/service tomcat
>> restart
>> (or stop or start) I get this error:
>>
>> -bash: /etc/init.d/tomcat: /bin/bash^M: bad interpreter: No such file or
>> directory
>
> When you create script files for Linux on a Windows box, make sure you
> save them with the proper line endings, i. e. \n instead of \r\n.
> dos2unix might help.
>
>> RUN_AS_USER=root # Adjust run user here
>
> Not a good idea.
>
> --
> Regards
> mks
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>
--
View this message in context: http://www.nabble.com/Tomcat-startup-as-service-on-CentOS-5.3-tp24203574p24203771.html
Sent from the Tomcat - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org
Re: Tomcat startup as service on CentOS 5.3
Posted by Markus Schönhaber <to...@list-post.mks-mail.de>.
tomcatastrophe:
> When I try to run /etc/init.d/tomcat restart or /sbin/service tomcat restart
> (or stop or start) I get this error:
>
> -bash: /etc/init.d/tomcat: /bin/bash^M: bad interpreter: No such file or
> directory
When you create script files for Linux on a Windows box, make sure you
save them with the proper line endings, i. e. \n instead of \r\n.
dos2unix might help.
> RUN_AS_USER=root # Adjust run user here
Not a good idea.
--
Regards
mks
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org