Skip to content

Instantly share code, notes, and snippets.

@nchapon
Created March 24, 2015 15:28
Show Gist options
  • Save nchapon/a3651352bc47dfee2950 to your computer and use it in GitHub Desktop.
Save nchapon/a3651352bc47dfee2950 to your computer and use it in GitHub Desktop.
Apache Tomcat Start / Stop / Status init.d script that works fine with ansible
#!/bin/sh
# description: Tomcat Start Stop Restart
# processname: tomcat
# chkconfig: 234 20 80
# source function library
. /etc/rc.d/init.d/functions
TOMCAT_USER=tomcat
LOCKFILE=/var/lock/tomcat
export JAVA_HOME=/usr/local/jdk
export TOMCAT_HOME=/usr/local/tomcat
export CATALINA_PID=/home/tomcat/tomcat.pid
[ -f $TOMCAT_HOME/bin/catalina.sh ] || exit 0
case "$1" in
start)
# Start daemon.
echo -n "Starting Tomcat: "
su -p -s /bin/sh $TOMCAT_USER -c "$TOMCAT_HOME/bin/catalina.sh start"
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch $LOCKFILE
;;
stop)
# Stop daemons.
echo -n "Shutting down Tomcat: "
su -p -s /bin/sh $TOMCAT_USER -c "$TOMCAT_HOME/bin/catalina.sh stop -force"
RETVAL=$?
echo
[ $RETVAL = 0 ] && rm -f $LOCKFILE
;;
restart)
$0 stop
$0 start
;;
status)
status -p $CATALINA_PID -l $(basename $LOCKFILE) tomcat
RETVAL=$?
;;
*)
echo "Usage: $0 {start|stop|restart|status}"
exit 1
esac
exit $RETVAL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment