1 #!/bin/bash
2 #############################################
3 # this script is created by xuxuedong. #
4 # e_mail:365686746@qq.com #
5 # qqinfo:365686746 #
6 # This is server start to chkconfig. #
7 # version:1.1 #
8 #############################################
9 # chkconfig: 2345 92 92
10 # description: Saves and restores system entropy pool for \
11 # higher quality random number generatio
12
13 . /etc/init.d/functions
14 #set env
15 export PATH=$PATH:/bin:/sbin:/usr/sbin
16 export LANG="zh_CN.GB18030"
17
18 # Require root to run this script.
19 if [[ "$(whoami)" != "root" ]]; then
20 echo "Please run this script as root." >&2
21 exit 1
22 fi
23
24 # Source function library.
25 #. /etc/init.d/functions
26 if [ ! -f /opt/software/apache-tomcat-7.0.72/bin/startup.sh ]
27 then
28 echo "tomcat is not exit.please install."
29 exit 1
30 fi
31 #This is a function for start tomcat
32 function start(){
33 if [ `ps -ef |grep java|grep -v grep|grep -v sh|wc -l` -eq 0 ]
34 then
35 /bin/sh /opt/software/apache-tomcat-7.0.72/bin/startup.sh >/dev/null 2>&1
36 [ $? -eq 0 ]&&\
37 sleep 1
38 action "tmocat start." /bin/true
39 else
40 action "tomcat had been startted." /bin/true
41 exit 3
42 fi
43 }
44 #This is a function for stop tomcat
45 function stop(){
46 if [ `ps -ef |grep java|grep -v grep|grep -v sh|wc -l` -gt 0 ]
47 then
48 PID=`ps -ef |grep java|grep -v grep|awk '{print $2}'`
49 kill -9 $PID
50 [ $? -eq 0 ]&&\
51 echo "tomcat is stopping..."
52 sleep 1
53 action "tomcat been stoped." /bin/true
54 else
55 action "tomcat had been stoped." /bin/true
56 exit 4
57 fi
58 }
59 #This is a function for restart tomcat
60 function restart(){
61 if [ `ps -ef |grep java |grep -v grep|grep -v sh|wc -l` -gt 0 ]
62 then
63 PID1=`ps -ef |grep java|grep -v grep|awk '{print $2}'`
64 kill -9 $PID1
65 [ $? -eq 0 ]&&/bin/sh /opt/software/apache-tomcat-7.0.72/bin/startup.sh >/dev/null 2>&1
66
67 [ $? -eq 0 ]&&echo "tomcat is restarting..."
68 sleep 1
69 action "tomcat is restartted ." /bin/true
70 else
71 action "tomcat is not running,please start." /bin/true
72 exit 5
73 fi
74 }
75 #This is a function for status tomcat
76 function status(){
77 if [ `ps -ef |grep java |grep -v grep|wc -l` -gt 0 ]
78 then
79 action "tomcat is running." /bin/true
80 else
81 action "tomcat is stopped." /bin/false
82 exit 5
83 fi
84 }
85 case $1 in
86 start)
87 start
88 ;;
89 stop)
90 stop
91 ;;
92 restart)
93 restart
94 ;;
95 status)
96 status
97 ;;
98
99 *)
100 echo "USAG:start|stop|restart|status"
101 esa