Skip to content

Instantly share code, notes, and snippets.

@jamesnguyen101
Last active August 29, 2015 14:17
Show Gist options
  • Save jamesnguyen101/bf7296c8ec161ffe7a7f to your computer and use it in GitHub Desktop.
Save jamesnguyen101/bf7296c8ec161ffe7a7f to your computer and use it in GitHub Desktop.
tomcat service . /etc/init.d/tomcat.sh
#!/bin/sh
### BEGIN INIT INFO
# Provides: tomcat
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop Apache Tomcat
# Description: Enable Apache Tomcat service provided by daemon.
# touch /etc/init.d/tomcat
# chmod 755 /etc/init.d/tomcat
# chkconfig --add tomcat
# chkconfig --level 2345 tomcat on
# use: /etc/init.d/tomcat start|stop|status
### END INIT INFO
ECHO=/bin/echo
TEST=/usr/bin/test
TOMCAT_USER=root
TOMCAT_HOME=/opt/yosport/yosport_app/tomcat8
TOMCAT_SCRIPT=$TOMCAT_HOME/bin/catalina.sh
TOMCAT_PORT=8081
#$TEST -x $TOMCAT_SCRIPT || exit 0
#$TEST -x $TOMCAT_SCRIPT || exit 0
start() {
$ECHO "Starting Tomcat[$TOMCAT_PORT]"
su - $TOMCAT_USER -c "$TOMCAT_SCRIPT start "
}
stop() {
$ECHO "Stopping Tomcat[$TOMCAT_PORT]"
# stop tomcat
su - $TOMCAT_USER -c "$TOMCAT_SCRIPT stop 5 -force " # 60 -force
}
status() {
TOMCAT_PID=`ps -ef | grep "$TOMCAT_HOME/" | grep 'Bootstrap start$' | awk '{print $2}'`
if [ ! -z $TOMCAT_PID ] ; then
echo "Tomcat[$TOMCAT_PORT] to still be running with PID $TOMCAT_PID."
exit 1
else
echo "Tomcat[$TOMCAT_PORT] is stopped."
exit 1
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop
sleep 30
start
;;
*)
$ECHO "Usage: tomcat {start|stop|status|restart}"
exit 1
esac
exit 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment