Linux system startup script from Tomcat service

Linux system startup script from Tomcat service

In linux system, manual and find startup.sh shutdown.sh file in the bin directory tomcat often takes a long time !!

Herein provide a way to tomcat linux system and services, you may be provided with tomcat iptables other systems with the same start-up services, and provides start stop restarts status commands, easy to operate.

Prerequisites !! JDK correctly installed and is properly set up environment variables.

(1) Create a tomcat service in the /etc/init.d directory

(2) vi editor tomcat added file

  . 1 #! / Bin / the bash
   2  #
   . 3  # Tomcat
   . 4  # 
   . 5  
  . 6 # --level <Level Code>   specify the read system in which the service to open or shut a completed execution hierarchy.
  7  # Level 0 represents: represents a shutdown
   8  # Level 1 represents: single-user mode
   9  # Level 2 represents: a multi-user command line mode without the network connection
 10  # Level 3 means: a multi-user command line network connection
 11  # Level 4 represents: not available
 12  indicates level # 5: multi-user mode with a graphical interface
 13  # level 6 represents: restart
 14  
15 # the chkconfig: 2345  88  86 
16  # Description:. Tomcat Server \
 . 17 This Service at The Soho starts up # OpenSSH Server daemon.
 18  #
 19  
20  
21  
22  # on the number of arguments passed to judge
 23 [$ # ne 1 ] && echo  " parameter passed incorrect parameters can only be:! Tomcat {start | stop | restart | status} where a " && Exit 2 
24  
25  # import library function
 26 is . /etc/rc.d/init.d/ functions
 27 TOMCAT_HOME = " / the root / tomcat " 
28  # tomcat to determine whether activated, we need to start the process after the tomcat ID saved. can be followed to determine whether to start the process according to ID
 29 pid_file the = / tmp / tomcat.pid
 30  function # judge whether tomcat started
 31 tomcat_status () {
 32          IF [-f $ pid_file]; the then   the process ID is stored into pid_file #tomcat in determining the presence of the document
 33 is                  the PID = ` CAT $ # pid_file` process ID read from the file to a local variable assigned the PID
 34 is                  iF [! -s $ PID]; the then    # determines whether the local variable is not empty PID
 35                          checkpid PID # $ check the current process is running tomcat
 36                          return $?        
 37 [                  Fi     
38 is          Fi 
39          return . 1 
40  }
 41 is  #tomcat start function
 42  tomcat_start () {
 43          # pID file may not exist, if there is no need to create the pid file with the touch command
44          IF [-f $ pid_file The!]; The then 
45                  Touch $ pid_file The
 46          fi 
47          # If the current tomcat does not start, we start tomcat
 48          tomcat_status
 49          IF [$ -eq? 0 ]; the then 
50                  echo  " tomcat has started, do not need to start again " 
51 is                  return 0 
52 is          Fi 
53 is          
54 is          # tomcat execution of startup. SH , start tomcat
 55          IF [the -X- " $ TOMCAT_HOME / bin / the startup.sh " ]; the then 
56 is                 # Startup.sh execute the file, if the file is executed after the tomcat process can print it out, that much easier to get pid
 57                  $ TOMCAT_HOME / bin / the Startup. SH | grep  " ^ Tomcat Started " | Cut -d " = " - F2> $ pid_file the
 58          Fi 
59  }
 60  # tomcat defined stop function
 61 is  tomcat_stop () {
 62 is          # stop tomcat accomplished by performing shutdown.sh, to determine what is stopped before has been started if the tomcat
 63 is          tomcat_status
 64          iF [$? - EQ 0 ]; the then 
65                  IF [the -X- "TOMCAT_HOME $ / bin / shutdown.sh " ]; the then 
66                          . $ TOMCAT_HOME / bin / the shutdown SH &> / dev / null 
67                          ? return $
 68                  the else 
69                          echo  " permissions for the user does not, check the " 
70                  fi 
71          the else 
72                  echo  " Tomcat does not start, no need to stop " 
73 is                  return 0 
74          Fi 
75  }
 76  Case $ . 1  in 
77  " start " )
 78         # Execute statements started
 79          tomcat_start
 80          IF [$ -eq? 0 ]; the then 
81                  tomcat_status && echo  " Tomcat has started successfully " 
82          the else 
83                  echo  " Tomcat startup error, please check the " 
84          fi 
85          
86          ;;
 87  " STOP " )
 88          # tomcat stop execution of sentence
 89          tomcat_stop
 90          IF [$ -eq? 0 ]; the then 
91                  echo  "tomcat has stopped ... " 
92          Fi 
93          ;;
 94  " the restart " )
 95      # statement execution restart tomcat
 96          tomcat_stop
 97          SLEEP  . 1 
98          tomcat_start
 99      ;;
 100  " Status " )
 101      # tomcat performed See server status statement
 102          tomcat_status
 103          IF [$ -eq? 0 ]; the then 
104                  echo  " Tomcat running .... " 
105          the else 
106                  echo " Tomcat does not start " 
107          Fi 
108      ;;
 109 * )
 110          echo  " Incoming parameter error " 
111          echo  " parameter can only be: tomcat {start | stop | restart | status} where a " 
112          Exit 2 
113          ;;
 114  Esac

(3) to set permissions tomcat file (be sure to remember to add execute permissions, other permissions depending on the individual set)

 chmod +x  tomcat

 

Guess you like

Origin www.cnblogs.com/eric666666/p/10994777.html