本文共 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-11131 [ -n "$CATALINA_HOME" ] && CATALINA_PID=$CATALINA_HOME/work/catalina.pid132 # 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/tomcat7Using CATALINA_HOME: /aliyun/tomcat7Using CATALINA_TMPDIR: /aliyun/tomcat7/tempUsing JRE_HOME: /aliyun/java-1.7.0Using CLASSPATH: /aliyun/tomcat7/bin/bootstrap.jar:/aliyun/tomcat7/bin/tomcat-juli.jarUsing CATALINA_PID: /aliyun/tomcat7/work/catalina.pidExisting 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 CMDroot 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 greproot 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.compid_file=/aliyun/tomcat7/work/catalina.pidPID=$(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/functionsstart() { if [ -f $pid_file ]; thenaction "tomcat7 service has start already!" /bin/falseelse/aliyun/tomcat7/bin/startup.sh >/dev/nullsleep 2action "tomcat7 service is starting!" /bin/truefi}stop() { if [ -f $pid_file ]; thenrm -f $pid_file;kill $PID;sleep 1action "tomcat7 service is stopped!" /bin/trueelseaction "tomcat service has stop already" /bin/falsefi}status() { if [ $pid -ne 0 ];thenecho "tomcat7 is running, pid is $PID!"elserm -f $pid_fileecho "tomcat7 has stoped!"fi}case "$1" instart)start;;stop)stop;;status)status;;restart)stop;sleep 1;start;;*)echo $"USEAGE: $0 {start|stop|status|restart}";;esacchmod +x /etc/init.d/tomcat7[root@tomcat01 work]# chkconfig --add tomcat7
service tomcat7 does not support chkconfig转载于:https://blog.51cto.com/wujianwei/2056451