Skip to content

Instantly share code, notes, and snippets.

@toomasr
Created October 15, 2012 14:42
Show Gist options
  • Save toomasr/3892850 to your computer and use it in GitHub Desktop.
Save toomasr/3892850 to your computer and use it in GitHub Desktop.
Tomcat startup script - should work :)
#!/bin/bash
#
# Tomcat - stops and starts Tomcat
#
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $network $syslog
# Required-Stop: $network $syslog
# Default-Start:
# Default-Stop:
# Short-Description: start and stop Tomcat
### END INIT INFO
export JAVA_HOME=/opt/java
export JAVA_OPTS=""
export PATH=$JAVA_HOME/bin:$PATH
export TOMCAT_HOME=/opt/tomcat
tomcat_pid() {
echo `ps u | grep $TOMCAT_HOME | grep "startup.Bootstrap" | grep -v grep | awk '{ print $2 }'`
}
start() {
PID=$(tomcat_pid)
if [ -n "$PID" ]
then
echo "Tomcat is already running: $PID"
else
$TOMCAT_HOME/bin/catalina.sh start
fi
return 0
}
stop() {
PID=$(tomcat_pid)
if [ -n "$PID" ]
then
$TOMCAT_HOME/bin/catalina.sh stop
else
echo "Tomcat is not running. Nothing to kill"
fi
return 0
return 0
}
case $1 in
start)
start
;;
stop)
stop
;;
restart)
stop
start
;;
status)
PID=$(tomcat_pid)
if [ -n "$PID" ]
then
echo "Tomcat is running: $PID"
else
echo "Tomcat is not running"
fi
;;
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment