Discussion:
Restart TC with cron/sh
Piller Sébastien
2008-07-07 13:43:48 UTC
Permalink
Hello,

I have my application in production for a month now. I've some problem
of memory leak that force me to restart TC each few days. I'm trying to
automate this operation with a cron that runs a *.sh file. But I don't
know how what to write in it. Actually, I've this:

/usr/local/tomcat/bin/shutdown.sh
killall -9 java
/usr/local/tomcat/bin/startup.sh

But when I run it using SSH, it makes a weird error:

[***@xxxxx bin]# /usr/local/tomcat/bin/restart.sh
: No such file or directoryrt.sh: line 1:*
/usr/local/tomcat/bin/shutdown.sh*
: no process killed
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jre1.5.0_06

... but shutdown.sh exists!

Does anybody have an example of a script that restart Tomcat?

Thanks a lot!




---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Edoardo Panfili
2008-07-07 13:49:51 UTC
Permalink
Post by Piller Sébastien
Hello,
I have my application in production for a month now. I've some problem
of memory leak that force me to restart TC each few days. I'm trying to
automate this operation with a cron that runs a *.sh file. But I don't
/usr/local/tomcat/bin/shutdown.sh
killall -9 java
/usr/local/tomcat/bin/startup.sh
: No such file or directoryrt.sh: line 1:*
/usr/local/tomcat/bin/shutdown.sh*
: no process killed
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jre1.5.0_06
... but shutdown.sh exists!
Does anybody have an example of a script that restart Tomcat?
Thanks a lot!
If you are using debian (and other linux versions)maybe
/etc/init.d/tomcat restart

Edoardo
--
Jabber: ***@talk.google.com
tel: 075 9142766


---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Piller Sébastien
2008-07-07 13:52:18 UTC
Permalink
Sorry, I've no "tomcat" in /etc/init.d/.
Post by Edoardo Panfili
If you are using debian (and other linux versions)maybe
/etc/init.d/tomcat restart
Edoardo
---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Edoardo Panfili
2008-07-07 13:59:57 UTC
Permalink
Post by Piller Sébastien
Sorry, I've no "tomcat" in /etc/init.d/.
Are you using linux? if so, what distribution?
How do you start Tomcat at startup time?

edoardo
Post by Piller Sébastien
Post by Edoardo Panfili
If you are using debian (and other linux versions)maybe
/etc/init.d/tomcat restart
Edoardo
---------------------------------------------------------------------
--
Jabber: ***@talk.google.com
tel: 075 9142766


---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Piller Sébastien
2008-07-07 14:11:02 UTC
Permalink
Yes, we're running Linux. I'm not sure what's my distrib. I'm using our
dedicated hosting, administrated via ssh. When I need to start tomcat, I
just use the startup.sh script (the one in /bin/). Same to shutdown: use
shutdown.sh.

It's possible to restart TC with a .sh, isn't it?
Post by Edoardo Panfili
Post by Piller Sébastien
Sorry, I've no "tomcat" in /etc/init.d/.
Are you using linux? if so, what distribution?
How do you start Tomcat at startup time?
edoardo
Post by Piller Sébastien
Post by Edoardo Panfili
If you are using debian (and other linux versions)maybe
/etc/init.d/tomcat restart
Edoardo
---------------------------------------------------------------------
---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Felix Schumacher
2008-07-07 14:17:06 UTC
Permalink
Post by Piller Sébastien
Yes, we're running Linux. I'm not sure what's my distrib. I'm using our
dedicated hosting, administrated via ssh. When I need to start tomcat, I
just use the startup.sh script (the one in /bin/). Same to shutdown: use
shutdown.sh.
Have you transferred the restart.sh from a windows box? Maybe you have
dos/windows line breaks, which are CR+LF. Such a combination can kill a
innocent looking shell script.
Post by Piller Sébastien
It's possible to restart TC with a .sh, isn't it?
Post by Edoardo Panfili
Post by Piller Sébastien
Sorry, I've no "tomcat" in /etc/init.d/.
Are you using linux? if so, what distribution?
How do you start Tomcat at startup time?
edoardo
Post by Piller Sébastien
Post by Edoardo Panfili
If you are using debian (and other linux versions)maybe
/etc/init.d/tomcat restart
Edoardo
---------------------------------------------------------------------
---------------------------------------------------------------------
---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Andrew Miehs
2008-07-07 14:20:33 UTC
Permalink
Post by Piller Sébastien
Yes, we're running Linux. I'm not sure what's my distrib. I'm using
our dedicated hosting, administrated via ssh. When I need to start
tomcat, I just use the startup.sh script (the one in /bin/). Same to
shutdown: use shutdown.sh.
It's possible to restart TC with a .sh, isn't it?
Dear Sébastien,

You can use cron to stop and restart tomcat every day - A little bit
of shell scripting may be required.

The apache distribution of tomcat can be stopped and started by using

cd $TOMCAT_HOME
./bin/shutdown.sh

./bin/startup.sh

(some developers ASSUME that $TOMCAT_HOME is the working directory)

As you are already having memory difficulties though, you may find
that shutdown.sh does not work correctly - and that you may need to
use "kill -9".

Either way however, should you be using this tomcat for a 'commercial
purpose' running on a '*nix' machine, I can only strongly recommend
that you find someone who can administer this machine.


Best of luck.

Andrew
---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Piller Sébastien
2008-07-07 14:50:10 UTC
Permalink
Felix,

Felix Schumacher a écrit :

Have you transferred the restart.sh from a windows box? Maybe you have
dos/windows line breaks, which are CR+LF. Such a combination can kill a
innocent looking shell script.

thank you, that was exactly what was wrong. I was using CR/LF-windows
style EOL in my restart.sh. Now it works much more better :)
Post by Andrew Miehs
Either way however, should you be using this tomcat for a 'commercial
purpose' running on a '*nix' machine, I can only strongly recommend
that you find someone who can administer this machine.
I'm the only one developper... So I've to do everything myself...
Development, deployment, tuning, profiling, maintenance, customer calls,
etc... Yes, I'm sometimes "alone in the dark"...

---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
David Smith
2008-07-07 14:31:45 UTC
Permalink
Check to be sure the proper environment variables are set when the
script runs. When I read the error message, I understand the error to
be more like "I can't find rt.sh from line 1 of
/usr/local/tomcat/bin/shutdown.sh". You can test to confirm that
suspicion by just dropping in an echo line at the beginning of
shutdown.sh to confirm it is finding shutdown.sh and is executing it's
contents.

Also I'd be careful to put some sleep delay before the killall command
as it can take a few seconds for tomcat to shutdown depending on how the
webapps were designed.

--David
Post by Piller Sébastien
Hello,
I have my application in production for a month now. I've some problem
of memory leak that force me to restart TC each few days. I'm trying
to automate this operation with a cron that runs a *.sh file. But I
/usr/local/tomcat/bin/shutdown.sh
killall -9 java
/usr/local/tomcat/bin/startup.sh
: No such file or directoryrt.sh: line 1:*
/usr/local/tomcat/bin/shutdown.sh*
: no process killed
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jre1.5.0_06
... but shutdown.sh exists!
Does anybody have an example of a script that restart Tomcat?
Thanks a lot!
---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Piller Sébastien
2008-07-07 14:56:10 UTC
Permalink
The last answer of F. Schumacher was the right. I was messing with
Post by David Smith
Check to be sure the proper environment variables are set when the
script runs. When I read the error message, I understand the error to
be more like "I can't find rt.sh from line 1 of
/usr/local/tomcat/bin/shutdown.sh". You can test to confirm that
suspicion by just dropping in an echo line at the beginning of
shutdown.sh to confirm it is finding shutdown.sh and is executing it's
contents.
I put a "ping 127.0.0.1 -c 10" between "shutdown.sh" and "killall -9".
Now it has a delay ~ 10s before the killall call.
Post by David Smith
Also I'd be careful to put some sleep delay before the killall command
as it can take a few seconds for tomcat to shutdown depending on how
the webapps were designed.
--David
Thank you everybody for your advices :)

---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Alex Mestiashvili
2008-07-08 13:15:43 UTC
Permalink
Post by Piller Sébastien
Hello,
I have my application in production for a month now. I've some problem
of memory leak that force me to restart TC each few days. I'm trying
to automate this operation with a cron that runs a *.sh file. But I
do you have shebang header in your script ? - something like this #!/bin/sh

and do you have tomcat running under root ? -this is very not secure ...
Post by Piller Sébastien
/usr/local/tomcat/bin/shutdown.sh
killall -9 java
/usr/local/tomcat/bin/startup.sh
: No such file or directoryrt.sh: line 1:*
/usr/local/tomcat/bin/shutdown.sh*
are this script executable ? if not use chmod to set for example 755
permissions
another thing about CRON , absolute paths to scripts must be used ...
Post by Piller Sébastien
: no process killed
Using CATALINA_BASE: /usr/local/tomcat
Using CATALINA_HOME: /usr/local/tomcat
Using CATALINA_TMPDIR: /usr/local/tomcat/temp
Using JRE_HOME: /usr/java/jre1.5.0_06
... but shutdown.sh exists!
Does anybody have an example of a script that restart Tomcat?
I have one , I use it for my init script for tomcat ...
if you are interesting in bash scripting , here is great manual
http://www.tldp.org/LDP/abs/ or just google "Advanced Bash-Scripting
Guide"
restart.sh

#!/bin/sh

TOMCAT_USER="tomcat"
CATALINA_HOME="/opt/tomcat"
PATH=/bin:/sbin:/usr/bin:/usr/sbin
startdaemon="$CATALINA_HOME/bin/startup.sh"
stopdaemon="$CATALINA_HOME/bin/shutdown.sh"

export CATALINA_HOME

case "$1" in
start)
sudo -u $TOMCAT_USER $startdaemon >>
"$CATALINA_HOME/logs/catalina.out" 2>&1
;;
stop)
sudo -u $TOMCAT_USER $stopdaemon >>
"$CATALINA_HOME/logs/catalina.out" 2>&1
while [[ "$i" -lt "10" ]]
do
status=`pidof java 2>&1>/dev/null ; echo $?`
if [[ $status == '0' ]]
then
echo -n "."
sleep 2
fi
let "i += 1"
done
status=`pidof java 2>&1>/dev/null ; echo $?`
if [[ $status == '0' ]]
then
echo "Killing ALL JAVA Processes"
/usr/bin/killall -9 java
fi
;;
restart)
echo "Stopping Tomcat"
$0 stop
sleep 2
echo "Starting Tomcat"
$0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
;;
esac
exit 0
Post by Piller Sébastien
Thanks a lot!
---------------------------------------------------------------------
---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org
Dan Armbrust
2008-07-16 19:59:30 UTC
Permalink
Post by Piller Sébastien
Hello,
I have my application in production for a month now. I've some problem of
memory leak that force me to restart TC each few days.
Or, you know, you could fix the actual problem - the memory leak.

Go get yourself a profiler, and fix the problem :)

This one is pretty good, and has a free demo:

http://www.ej-technologies.com/products/jprofiler/overview.html

---------------------------------------------------------------------
To start a new topic, e-mail: ***@tomcat.apache.org
To unsubscribe, e-mail: users-***@tomcat.apache.org
For additional commands, e-mail: users-***@tomcat.apache.org

Loading...