博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
tomcat启动脚本
阅读量:6954 次
发布时间:2019-06-27

本文共 3038 字,大约阅读时间需要 10 分钟。

添加红色这一行,才会启动tomcat生成pid文件

[root@tomcat01 work]# cat -n /aliyun/tomcat7/bin/catalina.sh |sed -n '128,132p'
128 [ -z "$CATALINA_BASE" ] && CATALINA_BASE="$CATALINA_HOME"
129
130 ###tomcat qidong jiaoben use by wujianwei 2016-5-11
131 [ -n "$CATALINA_HOME" ] && CATALINA_PID=$CATALINA_HOME/work/catalina.pid
132 # Ensure that any user defined CLASSPATH variables are not used on startup,
但是此参数生成的pid文件catalina.pid 里面记录的是 tomcat 日志切割进程的进程号并不是tomcat 服务的进程号。如果当时没有做日志切割,catalina.pid文件记录的是tomcat的进程号.(据猜测,日志切割和pid文件的生成和在/aliyun/tomcat7/bin/catalina.sh文件的设置参数的先后顺序有关。但是有待验证)
而且每次启动一次tomcat,/aliyun/tomcat7/bin/startup.sh 。tomcat的日志就会切割一个,新生成一个tomcat01.2016-05-12.out ,把之前的tomcat01.2016-05-12.out里面的日志内容全部覆盖掉了。(日志切割时按天进行切割的,所以当天再次启动tomcat生成的新的日志,日期还是当天的日期)
而且当tomcat 启动后再次执行/aliyun/tomcat7/bin/startup.sh 时,会有如下提示:
Using CATALINA_BASE: /aliyun/tomcat7
Using CATALINA_HOME: /aliyun/tomcat7
Using CATALINA_TMPDIR: /aliyun/tomcat7/temp
Using JRE_HOME: /aliyun/java-1.7.0
Using CLASSPATH: /aliyun/tomcat7/bin/bootstrap.jar:/aliyun/tomcat7/bin/tomcat-juli.jar
Using CATALINA_PID: /aliyun/tomcat7/work/catalina.pid
Existing PID file found during start.
Tomcat appears to still be running with PID 9610. Start aborted.
If the following process is not a Tomcat process, remove the PID file and try again:
UID PID PPID C STIME TTY TIME CMD
root 9610 1 0 11:54 pts/2 00:00:00 /usr/local/sbin/cronolog /aliyun/tomcat7/logs/tomcat01.2016-05-12.out

[root@tomcat01 tomcat7]# cat /aliyun/tomcat7/work/catalina.pid

9416
[root@tomcat01 tomcat7]# ps -ef|grep "/usr/local/sbin/cronolog"|grep -v grep
root 9416 1 0 11:35 pts/2 00:00:00 /usr/local/sbin/cronolog /aliyun/tomcat7/logs/tomcat01.2016-05-12.out

注意:虽然有上述的提示,但是不影响以下脚本的正常使用。

线上脚本文件:
[root@tomcat01 work]# cat /etc/init.d/tomcat7
#!/bin/bash
#chkconfig 2345 10 90
#description: start and stop tomcat service scripts
#author : wujianwei
#email : tomcatfox@163.com
pid_file=/aliyun/tomcat7/work/catalina.pid
PID=$(ps -ef|grep "/aliyun/java-1.7.0/bin/java"|grep -v "grep"|awk '{print $2}'|xargs|awk '{print $1}'|grep -v "^$")
pid=$(ps -ef|grep "/aliyun/java-1.7.0/bin/java"|grep -v "grep"|awk '{print $2}'|xargs|awk '{print $1}'|grep -v "^$"|wc -l)
source /etc/profile
. /etc/init.d/functions
start() {
if [ -f $pid_file ]; then
action "tomcat7 service has start already!" /bin/false
else
/aliyun/tomcat7/bin/startup.sh >/dev/null
sleep 2
action "tomcat7 service is starting!" /bin/true
fi
}
stop() {
if [ -f $pid_file ]; then
rm -f $pid_file;
kill $PID;
sleep 1
action "tomcat7 service is stopped!" /bin/true
else
action "tomcat service has stop already" /bin/false
fi
}
status() {
if [ $pid -ne 0 ];then
echo "tomcat7 is running, pid is $PID!"
else
rm -f $pid_file
echo "tomcat7 has stoped!"
fi
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status
;;
restart)
stop;
sleep 1;
start
;;
*)
echo $"USEAGE: $0 {start|stop|status|restart}";;
esac
chmod +x /etc/init.d/tomcat7

[root@tomcat01 work]# chkconfig --add tomcat7

service tomcat7 does not support chkconfig

转载于:https://blog.51cto.com/wujianwei/2056451

你可能感兴趣的文章
thinkphp-execute
查看>>
bootstrap-缩略图-默认样式的实例
查看>>
Spring4-BeanPropertyRowMapper
查看>>
我的友情链接
查看>>
MongoDB根据时间aggregate示例
查看>>
等级保护项目SQL Server审计方案
查看>>
Java 之集合
查看>>
改进了一下上周写的那个加域和迁移用户资料的程序
查看>>
归并排序和快速排序的衍生问题
查看>>
web工具
查看>>
Iptables 规则基础笔记
查看>>
nagios访问web界面出现Internal Server Error解决方法
查看>>
LVM逻辑卷管理
查看>>
51nod 1294:修改数组
查看>>
java自动化滑动学习
查看>>
Mongodb 副本集 数据同步简单测试
查看>>
我的友情链接
查看>>
iOS nil、Nil、NULL和NSNull 的使用
查看>>
c++ primer第五版 练习7.9
查看>>
前途是自己掌握的
查看>>