管理Tomcat服务的Daemon脚本
2016-10-19 12:19
281 查看
一、脚本功能
# tomcat 的启动,重启,实时查看日志#!/bin/bash
# funtions:
# chkconfig: 345 80 15
# description: Multiple tomcats service management script.
# author: shaonbean
# Source function library.
. /etc/rc.d/init.d/functions
# tomcat name
TOMCAT_PORT=$1
TOMCAT=tomcat_$1
TOMCAT_HOME=/opt/tomcats/${TOMCAT}
TOMCAT_BIN=${TOMCAT_HOME}/bin
#TOMCAT_LOG=${TOMCAT_HOME/logs/catalina.$(date +%Y-%m-%d).out
TOMCAT_LOG=${TOMCAT_HOME}/logs/catalina.out
#
# source function library.
. /etc/rc.d/init.d/functions
if [ -f ${TOMCAT_BIN}/catalina.sh ];then
echo "${TOMCAT} is valilable !!!"
else
echo "${TOMCAT} not valilable !!!"
exit
fi
RETVAL=$?
start(){
checkrun
if [ $RETVAL -eq 0 ]; then
echo "-- Starting ${TOMCAT}... --"
bash ${TOMCAT_BIN}/startup.sh
touch /var/lock/subsys/${TOMCAT_PORT}
checklog
status
else
echo "-- ${TOMCAT} already running !"
fi
}
# 停止某一台tomcat,如果是重启则带re参数,表示不查看日志,等待启动时再提示查看
stop(){
checkrun
if [ $RETVAL -eq 1 ]; then
echo "-- Shutting down tomcat..."
${TOMCAT_BIN}/shutdown.sh
if [ "$1" != "re" ]; then
checklog
else
sleep 5
fi
rm -rf /var/lock/subsys/${TOMCAT_PORT}
status
else
echo "-- ${TOMCAT} not running"
fi
}
status(){
checkrun
if [ $RETVAL -eq 1 ]; then
echo -n "-- ${TOMCAT} ( pid "
ps ax --width=1000 | grep ${TOMCAT_PORT}| grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'
echo -n ") is running..."
echo
else
echo "-- ${TOMCAT} is stopped"
fi
#echo "---------------------------------------------"
}
# 查看tomcat日志,带vl参数
log(){
status
checklog yes
}
# 如果tomcat正在运行,强行杀死tomcat进程,关闭tomcat
kill(){
checkrun
if [ $RETVAL -eq 1 ]; then
read -p "-- Do you really want to kill ${TOMCAT_PORT} progress?[no])" answer
case $answer in
Y|y|YES|yes|Yes)
ps ax --width=1000 | grep ${TOMCAT_PORT} | grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 " "}'| xargs kill -9
status
;;
*);;
esac
else
echo "-- exist with ${TOMCAT_PORT} still running..."
fi
}
checkrun(){
ps ax --width=1000 |grep ${TOMCAT_PORT}| grep "[o]rg.apache.catalina.startup.Bootstrap start" | awk '{printf $1 "\n"}' | wc -l > /var/run/tomcat_process_count
read line < /var/run/tomcat_process_count
if [ $line -gt 0 ]; then
RETVAL=1
return $RETVAL
else
RETVAL=0
return $RETVAL
fi
}
# 如果是直接查看日志viewlog,则不提示输入[yes],否则就是被stop和start调用,需提示是否查看日志
checklog(){
answer=$1
if [ "$answer" != "yes" ]; then
read -p "-- See Catalina.out log to check $2 status?[yes])" answer
fi
case $answer in
Y|y|YES|yes|Yes|"")
tail -f ${TOMCAT_LOG}
;;
*)
# status
# exit 0
;;
esac
}
checkexist(){
if [ ! -d ${TOMCAT_HOME} ]; then
echo "-- ${TOMCAT_HOME} does not exist."
exit 0
fi
}
case "$2" in
start)
checkexist
start
exit 0
;;
stop)
checkexist
stop
exit 0
;;
restart)
checkexist
stop re
start
exit 0
;;
status)
checkexist
status
#${TOMCAT_BIN}/catalina.sh version
exit 0
;;
log)
checkexist
log
exit 0
;;
kill)
checkexist
status
kill
exit 0
;;
*)
echo "Usage: $0 {start|stop|restart|status|log|kill}"
echo "service tomcat {8080|8081|..} {start|stop|restart|status|log|kill}"
esac
exit 0
相关文章推荐
- 管理多tomcat服务shell脚本(CentOS)
- [分享] 数据库服务管理脚本,超好用! 支持oracle,mysql,sqlserver,tomcat(本人在源程序上修改的)
- Centos5下搭建tomcat服务及java应用的部署和管理
- CentOS Tomcat 的启动服务脚本
- Solr4.2 + Tomcat 7 配置及使用solrnet访问和管理索引服务
- tomcat 管理脚本
- 使用dialog+chkconfig写的类似ntsysv服务管理脚本
- 自动检测tomcat服务的shell脚本
- Tomcat服务监控管理工具,利用delphi编写
- 使用Ant构建web项目 从编译到测试 生成测试报告 打包 邮件发送 远程下载tomcat 部署运行一条龙服务之ant脚本
- 学习tomcat安装服务脚本
- tomcat linux服务脚本
- 自动检测tomcat服务的shell脚本
- 脚本监测apache、tomcat服务
- nginx、tomcat、http服务shell监控脚本
- 使用交互式shell脚本实现对DNS服务的管理以及启动
- CentOS Tomcat 的启动服务脚本
- tomcat服务 启动/停止/重启脚本 推荐
- 多Tomcat服务 启动/停止/重启 脚本
- 由shell改进成Tomcat服务脚本_Linux运维笔记