How to restart the tomcat server

hi,
I need a command that restart the tomcat server.

for example for restart the tomcat i am using following command, /etc/init.d/tomcat restart ..but sometimes is not working...might be i want to use java code access this peace of script.

like using the grep and ps commands can i use?

1.find the tomcat is running or not if yes find the command and try to execute that command again

for example
ps -ef| grep tomcat >>/dev/null

i am not sure how to write such scenario... please help anybody on this?

Thank you

Sankar

  1. You don't need java code for this.
  2. You might check why it works only sometimes and fix it or get an update for your OS/tomcat.
  3. Depending on distribution etc. there could be somewhere a script like "startup.sh" in your tomcat's bin directory which you might want to use instead.

This can be used..

#!/bin/bash

export OPTS=$*

if [ ! -z "$OPTS" ]; then
   grep -v "EXTRA_JAVA_OPTS" /etc/tomcat5/tomcat5.conf > /tmp/tomcat5.conf
   cp /tmp/tomcat5.conf /etc/tomcat5/tomcat5.conf
   echo EXTRA_JAVA_OPTS=\"$OPTS\" >> /etc/tomcat5/tomcat5.conf
   echo "JAVA_OPTS=\"\$EXTRA_JAVA_OPTS \$JAVA_OPTS\";export JAVA_OPTS" >> /etc/tomcat5/tomcat5.conf
fi

/sbin/service tomcat5 restart