Skip to content

Instantly share code, notes, and snippets.

@rodolfo42
Last active May 13, 2020 06:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rodolfo42/5654188 to your computer and use it in GitHub Desktop.
Save rodolfo42/5654188 to your computer and use it in GitHub Desktop.
Apache Tomcat 7 service init script
#!/bin/bash
### BEGIN INIT INFO
# Provides: tomcat
# Defalt-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Apache Tomcat 7
### END INIT INFO
# base dir of tomcat installation #
CATALINA_HOME=/opt/tomcat/
# full path for file which will hold the PID #
# used by 'status' #
CATALINA_PID=/var/run/tomcat.pid
export CATALINA_PID
status=0
case $1 in
start)
sh $CATALINA_HOME/bin/startup.sh
;;
stop)
sh $CATALINA_HOME/bin/shutdown.sh
;;
restart)
sh $CATALINA_HOME/bin/shutdown.sh
sh $CATALINA_HOME/bin/startup.sh
;;
status)
if ! [ -z "$CATALINA_PID" ]; then
if [ -r $CATALINA_PID ]; then
pid=`cat "$CATALINA_PID"`
if ! [ -z $pid ]; then
echo "tomcat (pid $pid) is running..."
else
echo "tomcat is stopped"
fi
else
echo "tomcat is stopped"
fi
else
echo "No PID file found for tomcat..."
echo "(variable \$CATALINA_PID is not defined)"
status=1
fi
;;
esac
exit $status
@eldenis
Copy link

eldenis commented May 13, 2020

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment