Tomcat 6 in Linux is configured as a service

Source: Internet
Author: User

I posted on the official website

I am using a root user to log on. The specific operation steps are described below,

 

1. There is a commons-daemon-native.tar.gz compressed package in/usr/share/tomcat6/bin.

2nd release commons-daemon-native.tar.gz

[Root @ localhost ~] # Tar-zxvf commons-daemon-native.tar.gz

3. decompress the package and the commons-daemon-1.0.2-native-src folder (directory) appears)

1,
Go to the Unix directory under the commons-daemon-1.0.2-native-src

[Root @ localhost ~] # Ls

[Root @ localhost ~] # Cdcommons-daemon-1.0.2-native-src/Unix

2,
If the configure configuration file is found, run the following command to modify the properties:

[Root @ localhost ~] # Chmod 777 configure

4,
Execute the configure file

[Root @ localhost ~] #./Configure

5,
Compile

[Root @ localhost ~] # Make # An error will be reported

[Root @ localhost ~] # Make clean

[Root @ localhost ~] # Make # recompile successful

6. After compilation, the jsvc folder appears. Copy jsvc to the/usr/share/tomcat6/bin directory.

[Root @ localhost ~] # Cp jsvc/usr/share/tomcat6/bin

Bytes ------------------------------------------------------------------------------------

10. Compile the tomcat6 startup service configuration file in the/etc/init. d/directory.

[Root @ localhost ~] # Cd/etc/init. d/

[Root @ localhost ~] # Vi tomcat6

Enter the following content

#! /Bin/sh
# Tomcat: start/stop/restart Tomcat
#
# Chkconfig: 2345 85 15
# Description: Apache tomcat6

# Small shell script to show how to start/stop Tomcat using jsvc
# If you want to have Tomcat running on port 80 Please modify the server. xml
# File:
#
# <! -- Define a non-ssl http/1.1 Connector on port 80 -->
# <Connector classname = "org. Apache. Catalina. connector. http. httpconnector"
# Port = "80" minprocessors = "5" maxprocessors = "75"
# Enablelookups = "true" redirectport = "8443"
# Acceptcount = "10" DEBUG = "0" connectiontimeout = "60000" type = "codeph" text = "codeph"/>
#
Java_home =/usr/Java/jdk1.6.0 _ 31 # modify it based on your actual JDK location

Catalina_home =/usr/share/tomcat6 # modify it based on your actual Tomcat location
Daemon_home = $ catalina_home/bin
# I did not use the user.
# Tomcat_user = Tomcat

# For multi instances adapt those lines.
Tmp_dir = $ catalina_home/tmp
Pid_file =/var/run/jsvc. PID
Catalina_base = $ catalina_home
./Etc/rc. d/init. d/functions
Catalina_opts =
Classpath = \
$ Java_home/lib/tools. jar :\
$ Catalina_home/bin/commons-daemon.jar :\
$ Catalina_home/bin/Bootstrap. Jar

Start (){
Echo-N $ "Starting tomcat6 :"
# If you want to specify a user to run tomcat.
# Increase the 'user $ tomcat_user \ 'to the parameter list.
$ Daemon_home/jsvc \
-Home $ java_home \
-Dcatalina. Home = $ catalina_home \
-Dcatalina. base = $ catalina_base \
-Djava. Io. tmpdir = $ tmp_dir \
-Wait 10 \
-Pidfile $ pid_file \
-OUTFILE $ catalina_home/logs/Catalina. Out \
-Errfile '& 1 '\
$ Catalina_opts \
-CP $ classpath \
Org. Apache. Catalina. startup. Bootstrap
Echo "***************************** [OK]"
}

Stop (){
Echo-N $ "Stopping tomcat6 :"
#
$ Daemon_home/jsvc \
-Stop \
-Pidfile $ pid_file \
Org. Apache. Catalina. startup. Bootstrap
Echo "***************************** [OK]"
}

Status (){
PS ax -- width = 1000 | grep "[O] RG. apache. catalina. startup. bootstrap "| awk '{printf $1"}' | WC | awk '{print $2}'>/tmp/tomcat_process_count.txt
Read line </tmp/tomcat_process_count.txt
If [$ line-GT 0]; then
Echo-n "tomcat6 (PID"
PS ax -- width = 1000 | grep "[O] RG. Apache. Catalina. startup. Bootstrap" | awk '{printf $1 ""}'
Echo ") is running"
Else
Echo "tomcat6 is stopped"
Fi
}

Case "$1" in
Start)
# Start Tomcat
Start
Exit $?
;;

Stop)
# Stop Tomcat
Stop
Exit $?
;;
Restart)
# Restart Tomcat
Stop
Sleep 3
Start
Exit $?
;;
Status)
Status
Exit $?
;;
*)
Echo "Usage: tomcat6 {START | stop | restart | status }"
Exit 1 ;;
Esac

#####

####

11. input is complete. Press ESC. Input: WQ save and quit and grant the executable permission to the/etc/init. d/tomcat6 file.

[Root @ localhost ~] # Chmod 777/etc/init. d/tomcat6

------------------ Add a service -----------------------------------------

12. [root @ localhost ~] # Chkconfig -- add tomcat6 # Add a tomcat Service

13. [root @ localhost ~] # Chkconfig-list | grep tomcat6 # Check whether the Tomcat service is added

-------------------- Start the service ---------------------------------------------

14. [root @ localhost ~] # Service tomcat6 start # Start the Tomcat Service

15. [root @ localhost ~] # Service tomcat6 stop # Stop the Tomcat Service

16. [root @ localhost ~] # Service tomcat6 restart # restart Tomcat

17. [root @ localhost ~] # Service tomcat6 status # view the Tomcat service startup status

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.