tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Alex Mestiashvili <alexander.mestiashv...@biotec.tu-dresden.de>
Subject Re: Restart TC with cron/sh
Date Tue, 08 Jul 2008 13:15:43 GMT
Piller S├ębastien wrote:
> 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:
>
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 ...
> /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:
>
> [root@xxxxx bin]# /usr/local/tomcat/bin/restart.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 ...

> : 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


> Thanks a lot!
>
>
>
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>



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


Mime
View raw message