Skip to content

Instantly share code, notes, and snippets.

@willnet
Forked from tcocca/tomcat6
Last active February 23, 2017 05:27
Show Gist options
  • Save willnet/4461426 to your computer and use it in GitHub Desktop.
Save willnet/4461426 to your computer and use it in GitHub Desktop.
tomcat init script for centos
#!/bin/bash
# description: Tomcat6 service
# processname: java
# chkconfig: - 99 1
# Source function library.
. /etc/init.d/functions
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-1.7.0.9.x86_64/jre
export TOMCAT_USER=solr
export CATALINA_HOME=/opt/tomcat6
export CATALINA_PID=$CATALINA_HOME/bin/tomcat6.pid
[ -d "$CATALINA_HOME" ] || { echo "Tomcat requires $CATALINA_HOME."; exit 1; }
case $1 in
start|stop|run)
if su $TOMCAT_USER bash -c "$CATALINA_HOME/bin/catalina.sh $1"; then
echo -n "Tomcat $1 successful"
[ $1 == "stop" ] && rm -f $CATALINA_PID
else
echo -n "Error in Tomcat $1: $?"
fi
;;
restart)
$0 start
$0 stop
;;
status)
if [ -f "$CATALINA_PID" ]; then
read kpid < "$CATALINA_PID"
if ps --pid $kpid 2>&1 1>/dev/null; then
echo "$0 is already running at ${kpid}"
else
echo "$CATALINA_PID found, but $kpid is not running"
fi
unset kpid
else
echo "$0 is stopped"
fi
;;
esac
exit 0
@Setekh
Copy link

Setekh commented Oct 28, 2015

Thanks =]

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