标签:tomcat启动脚本
#!/bin/bash # chkconfig: 35 55 25 # description: source tomcat server # processname: tomcat export JRE_HOME=/usr/local/jdk export JAVA_BIN=/usr/local/jdk/bin export PATH=$JRE_HOME/bin:$PATH export CLASSPATH=.:$JRE_HOME/lib/dt.jar:$JRE_HOME/lib/tools.jar export JRE_HOME JAVA_BIN PATH CLASSPATH start(){ netstat -tulnp | grep :8080 &> /dev/null if [ $? -eq 0 ];then echo -e tomcat8080端口已启动: "\033[31m [禁止启动] \033[0m" else su -m www -c /usr/local/tomcat/bin/startup.sh &> /dev/null#su 命令, -m 保持环境变量不变,-c 使用www用户启动服务 sleep 5 netstat -tulnp | grep :8080 &> /dev/null if [ $? -eq 0 ];then echo -e 启动tomcat: "\033[32m [确定] \033[0m" else echo -e 启动tomcat: "\033[31m [失败] \033[0m" fi fi } stop(){ netstat -tulnp | grep :8005 &> /dev/null if [ $? -eq 0 ];then /usr/local/tomcat/bin/shutdown.sh &> /dev/null sleep 10 netstat -tulnp | grep :8080 &> /dev/null if [ $? -eq 0 ];then kill `ps aux | grep java | grep -v grep | awk ‘{print $2}‘` sleep 5 netstat -tulnp | grep :8080 &> /dev/null if [ $? -eq 0 ];then echo -e 关闭tomcat: "\033[31m [失败] \033[0m" else echo -e 关闭tomcat: "\033[32m [确定] \033[0m" fi else echo -e 关闭tomcat: "\033[32m [确定] \033[0m" fi else echo -e tomcat8005端口未启动: "\033[31m [禁止关闭] \033[0m" fi } status(){ ps aux | grep java netstat -tlnp | grep java | grep --color 80 } restart(){ echo -e 重启时间比较长: "\033[32m [请稍后...] \033[0m" stop start } case $1 in start) start;; stop) stop;; status) status;; restart) restart;; *) echo -e 用法:/etc/init.d/tomcat "\033[32m {start|stop|restart|status} \033[0m" esac
本文出自 “wsyht的博客” 博客,请务必保留此出处http://wsyht2015.blog.51cto.com/9014030/1791398
标签:tomcat启动脚本
原文地址:http://wsyht2015.blog.51cto.com/9014030/1791398