#!/bin/bash# chkconfig: 35 55 25# description: source tomcat server# processname: tomcatexport jre_home=/usr/local/jdkexport java_bin=/usr/local/jdk/binexport path= $JRE _home/bin: $PATHexport classpath=.: $JRE _home/lib/dt.jar: $JRE _home/lib/tools.jarexport Jre_home java_bin path classpathstart () {netstat -tulnp | grep :8080 &> /dev/nullif [ $? -eq 0 ];thenecho -e tomcat8080 Port started: " \033[31m [prohibit start] \033[0m " else su -m www -c /usr/local/tomcat/bin/startup.sh &> /dev/null#su command, -m Keep environment variable,-c use WWW user startup service sleep 5 netstat -tulnp | grep :8080 &> /dev/nullif [ $? -eq 0 ];thenecho -e start tomcat: "\033[32m [OK] \033[0m " elseecho -e start tomcat: "\033[31m [failure] \033[0m " fifi}stop () { netstat -tulnp | Grep :8005 &> /dev/null if [ $? -eq 0 ];then/usr/local/tomcat/bin/shutdown.sh &> /dev/nullsleep 10netstat -tulnp | grep :8080 &> /dev/nullif [ $? -eq 0 ];thenkill ' Ps aux | grep java | grep -v grep | awk ' {print $2} ' Sleep 5netstat -tulnp | grep :8080 &> /dev/nullif [ $? -eq 0 ];thenecho -e Close tomcat: "\033[31m [failure] \033[0m " else echo -e Close tomcat: "\033[32m [OK] \033[0m "fielseecho -e off tomcat: " \033[32m [Determine] \033 [0m " fielseecho -e tomcat8005 Port does not start: " \033[31m [Disable] \033[0m "Fi}status () {Ps aux | grep java netstat -tlnp | grep java | grep --color 80}restart () {echo -e Restart time longer: "\033[32m [please later ...] \033[0m "Stopstart}case $1 instart) start;; Stop) stop;; Status) status;; restart) restart;; *) echo -e usage:/etc/init.d/tomcat "\033[32m {start|stop|restart|status} \ 033[0m " esac
This article is from the "Wsyht blog" blog, make sure to keep this source http://wsyht2015.blog.51cto.com/9014030/1791398
Tomcat startup script