tomcat啓動腳本

添加紅色這一行,纔會啓動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 : [email protected]
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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章