Jdk1.5 and tomcat 5.5 are installed in SuSE Enterprise 10 environment, and tomcat settings are automatically started upon startup.

Source: Internet
Author: User
Tags stop script

(1) install JDK and tomcat

Tomcat: apache-tomcat-5.5.25.tar.gz

JDK: jdk-1_5_0_22-linux-i586-rpm.bin

(1) first install jdk1.5.

1. Open the terminal and run the command su root to switch to the Super User.
2. Switch CD to the/usr directory. Run the command chmod 755 jdk-1_5_0_22-linux-i586-rpm.bin to grant corresponding permissions.
3. Run the command./jdk-1_5_0_22-linux-i586-rpm.bin wait, follow the prompts to install JDK, follow the prompts to operate, JDK installation is complete.

(2). Set environment variables:
VI/etc/profile
Insert:
Java_home =/usr/Java/jdk-1_5_0_22 (installed in this directory by default)
Jre_home =/usr/Java/jdk-1_5_0_22/JRE
Path = $ path: $ java_home/bin: jre_home/bin
Classpath =.: $ java_home/lib/JT. jar: $ java_home/lib/tools. jar: $ jre_home/lib

Export java_home

Export jre_home

Export path

Export classpath

Press ESC, And then: WQ save and exit

(3). Make the environment variable take effect:
# Source/etc/profile
View: # echo $ java_home (the JDK directory is displayed)
# Java-version (view JDK version information)

(4). tomcat5.5 download:
CP apache-tomcat-5.5.25.tar.gz/usr/local // copy to this directory

Tar-zxvf apache-tomcat-5.5.25.tar.gz or tar xvzf
Apache-tomcat-5.5.25.tar.gz // unzip

Mv apache-Tomcat-5.5.25 Tomcat // rename the folder

CD/usr/local/tomcat/bin

Run Tomcat:
./Catalina. Sh start or./startup. Sh

Stop Tomcat:
./Shutdown. Sh or./Catalina. Sh stop

Enter http: // localhost: 8080 in the browser
The page is displayed normally and the example program can be run, proving that Tomcat is successfully installed.

You can also enter PS-Ef | grep tomcat to check whether the Tomcat process is running.

(If you want to kill a process, use the kill process number)

(2) Analysis of Automatic startup of SuSE Linux Tomcat
(Reprinted)

 

Maybe you know SuSE Linux very well. Maybe you don't know much about it. Here we will discuss each other. Today we are talking about Automatic startup of SuSE Linux tomcat. I hope this article will help you and hope you can learn how to enable SuSE Linux Tomcat automatically. Add the command to the/etc/init. d/boot. Local file. The corresponding file of the Red Hat system is/etc/rc. d/rc. Local.

For commands or programs automatically run during Linux Startup, In rh-based Linux systems, it is generally stored in/etc/rc. d/rc. Local. However, SuSE Linux does not have this file, and users are not recommended to manage the startup service in this way. We recommend that you use a regular method to manage the Service Startup Mode.

Some people may say that in The SuSE system, it can be placed in/etc/init. d/boot. Local, depending on the actual situation. Because SuSE/etc/init. d/boot. the local file is composed of/etc/init. the script D/boot is started, and the final boot script is complete. It is executed when you enter the runlevel environment to execute various rc scripts. The Rh/etc/rc. d/rc. Local file is executed in the runlevel environment.
RC script is executed in the last stage, so the layers are different. If the program you want to run is suitable for running the runlevel service before it is executed, you can put it in the boot. Local file in SuSE Linux.

However, if your service needs to be executed only after entering runlevel, the common practice of SuSE should be to write an RC Script and put it in/etc/init. d/directory, and then use the chkconfig or inssev program to manage whether to enable or disable the Service Project during startup of A runlevel environment. For the RC Script Writing Method, refer to the existing script files in/etc/init. d/. You should easily write your own version.

1. Create a startup/Stop script file

The script allows tomcat to run as a service.
#! /Bin/bash
# Chkconfig: 2345 10 90
# Description: starts and stops the Tomcat daemon.
Tomcat_home =/usr/local/tomcat/Apache-Tomcat-5.5.25
Tomcat_start = $ tomcat_home/bin/startup. Sh
Tomcat_stop = $ tomcat_home/bin/shutdown. Sh
# Necessary environment variables Export
Catalina_home = $ tomcat_home
Export java_home =/usr/Java/jdk1.6.0 _ 03
# Source function library.
./Etc/rc. d/init. d/functions
# Source networking configuration.
./Etc/rc. d/Network
# Check that networking is up.
["$ {Networking}" = "no"] & Exit 0
# Check for Tomcat script
If [! -F $ tomcat_home/bin/Catalina. Sh]
Then ECHO "Tomcat not valilable ..."
Exit
Fi
Start (){
Echo-n "Starting Tomcat :"
Daemon $ tomcat_start
Echo
Touch/var/lock/subsys/tomcat
}
Stop (){
Echo-N $ "shutting down Tomcat :"
Daemon $ tomcat_stop
Rm-F/var/lock/subsys/tomcat. PID echo
}
Restart (){
Stop
Start
}
Status (){
PS ax -- width = 1000 | grep "[O] RG. apache. catalina. startup. bootstrap start "| 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 "Tomcat (PID"
PS ax -- width = 1000 | grep "org. Apache. Catalina. startup. Bootstrap start" | awk '{printf $1 ""}'

Echo-n ") is running ..."
Echo
Else
Echo "Tomcat is stopped"
Fi
}
Case "$1" in
Start)
Start ;;
Stop)
Stop ;;
Restart)
Stop
Sleep 3
Start ;;
Status)
Status ;;
*)
Echo "Usage: tomcatd {START | stop | restart | status }"
Exit 1
Esac
Exit 0

Ii. Save and set the script file

Save the preceding script file in/etc/init. d and name it tomcat;
Set Tomcat file attributes
# Chmod A + x Tomcat

3. Set the service running level
Finally, use chkconfig to set service running.
# Chkconfig -- add Tomcat

The service is successfully added.

Then you can use chkconfig -- list to view the Custom Service in the service list.

Note:
In the comments statement of the first two lines of the Tomcat file, the chkconfig and description must be included (do not make spelling mistakes). Otherwise, when "chkconfig -- add Tomcat" is executed, the error message "Tomcat service does not support chkconfig" appears.

This line of chkconfig indicates the default startup running level and the priority of Start and Stop. if the service is not started at any running level by default, "-" is used instead of "Run level. In tomcat, the script is started at runtime Level 2, 3, 4, and 5. The start priority is 10, and the Stop priority is 90.

The description line describes the service. You can use "/" to annotate the service. In this way, you will learn the SuSE Linux Tomcat Automatic startup process.

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.