Linux System Service self-starting settings _ Tomcat

Source: Internet
Author: User
1. Simple Method
The simplest method is to automatically start the instance by using the startup. Sh provided by Tomcat. edit/etc/rc. d/rc. Local and add:
Export jdk_home =/usr/local/JDK
Export java_home =/usr/local/JDK
/Usr/local/tomcat/bin/startup. Sh
 
2. Complicated and professional methods
The first method fails to specify the user who starts the Tomcat service, and there is a security risk. In addition, the Service cannot be automatically stopped when the system is disabled. In Linux, Tomcat can be started and stopped as a daemon. The jsvc tool in the project commons-Daemon must be used. After Tomcat is installed, it comes with the source code $ catalina_home/bin/jsvc.tar.gz of this tool. First install this tool:
# Tar zxvf jsvc.tar.gz
# Cd jsvc-Src
# Chmod + x configure
#./Configure -- With-Java =/usr/JDK
# Make
#./Jsvc-help // check
 
After chkconfig -- add Tomcat is set to automatic start, the error message "service Tomcat does not support chkconfig" is displayed, you need to modify the script $ catalina_home/bin/jsvc-src/native/tomcat. sh, and CP to/etc/rc. d/init. d. My startup script is as follows (several errors occurred in the middle, and it was found to be a script problem, so be careful ):
#! /Bin/sh
#
# STARTUP script for tomcat5
#
# Chkconfig: 345 87 13
# Description: Tomcat daemon
# Processname: jsvc
# Pidfile:/var/run/jsvc. PID
# Config:
#
# Source function library.
./Etc/rc. d/init. d/functions
#
Prog = Tomcat
#
# 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"/>
#
# You need a developement version of Tomcat (Apache Tomcat/4.1-dev)
#
# Adapt the following lines to your configuration
Java_home =/usr/local/JDK
Catalina_home =/usr/local/tomcat
Daemon_home = $ catalina_home/bin/jsvc-Src
Tomcat_user = Tomcat
Tmp_dir =/var/tmp
Catalina_opts =
Classpath = $ java_home/lib/tools. jar: $ catalina_home/bin/commons-daemon.jar: $ catalina_home/bin/Bootstrap. Jar
Start (){
Echo-N $ "Starting $ prog :"
#
# Start Tomcat
#
$ Daemon_home/jsvc \
-User $ tomcat_user \
-Home $ java_home \
-Dcatalina. Home = $ catalina_home \
-Djava. Io. tmpdir = $ tmp_dir \
-OUTFILE $ catalina_home/logs/Catalina. Out \
-Errfile '& 1 '\
$ Catalina_opts \
-CP $ classpath \
Org. Apache. Catalina. startup. Bootstrap
#
# To get a verbose JVM
#-Verbose \
# To get a debug of jsvc.
#-Debug \
Retval =$?
[$ Retval = 0] & Touch/var/lock/subsys/jsvc
[$ Retval = 0] & echo_success | echo_failure
Echo
Return $ retval
}
Stop (){
Echo-N $ "Stopping $ prog :"
#
# Stop Tomcat
#
PID = 'cat/var/run/jsvc. PID'
Kill $ PID
Retval =$?
[$ Retval = 0] & RM/var/lock/subsys/jsvc
[$ Retval = 0] & echo_success | echo_failure
Echo
Return $ retval
}
Case "$1" in
Start)
Start
;;
Stop)
Stop
;;
Restart | RELOAD)
Stop
Start
;;
*)
Echo "usage $0 start/stop"
Exit 1 ;;
Esac
In this way, you are done (some paths and user settings need to be modified according to your specific environment ). You may also need to use chown Tomcat and chmod + x tomcat to modify the owner and executable permissions.

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.