Starting, Stopping, and Restarting Tomcat – Tomcat: The Definitive Guide, 2nd Edition [Book]

once you have the initiation completed, you will probably be eager to start Tomcat and see if it works. This incision details how to start up and shut down Tomcat, including specific information on each supported operate arrangement. It besides details common errors that you may encounter, enabling you to promptly identify and resolve any problems you run into .

Starting Up and Shutting Down

The right way to start and stop Tomcat depends on how you installed it. For example, if you installed Tomcat from a Linux RPM software, you should use the init script that came with that software to start and stop Tomcat. Or, if you installed Tomcat on Windows via the graphic installer from tomcat.apache.org, you should start and stop Tomcat as you would any Windows service. Details about each of these package-specific cases are given in the next several sections. If you installed Tomcat by downloading the binary release archive ( .zip or .tar.gz ) from the Tomcat downloads page—what we ‘ll call the generic installation case—you should use the command-line scripts that reside in the CATALINA_HOME/bin directory. There are several scripts in the bin directory that you will use for starting and stopping Tomcat. All the scripts you will need to invoke immediately are provided both as beat script files for Unix ( .sh ) and batch files for Windows ( .bat ). mesa 1-1 lists these scripts and describes each. When referring to these, we have omitted the filename elongation because catalina.bat has the lapp think of for Microsoft Windows users that catalina.sh [ ] has for Unix users. consequently, the diagnose in the table appears plainly as catalina. You can infer the appropriate file extension for your system. table 1-1. Tomcat invocation scripts

script Purpose
catalina The independent Tomcat script. This runs the java instruction to invoke the Tomcat startup and closure classes .
cpappend This is used internally, and then only on Windows systems, to append items to Tomcat classpath environment variables .
digest This makes a crypto digest of Tomcat passwords. Use it to generate code passwords .
service This script installs and uninstalls Tomcat as a Windows service .
setclasspath This is besides lone used internally and sets the Tomcat classpath and several other environment variables .
shutdown This runs catalina stop and shuts down Tomcat .
startup This runs catalina originate and starts up Tomcat .
tool-wrapper This is a generic Tomcat command-line instrument wrapper handwriting that can be used to set environment variables and then call the independent method acting of any in full qualified class that is in the classpath that is set. This is used internally by the digest script .
version This runs the catalina version, which outputs Tomcat ‘s translation information .

The main script, catalina, is invoked with one of several arguments. The most common arguments are start, run, or stop. When appeal with start ( as it is when called from inauguration ), it starts up Tomcat with the standard output and standard error stream directed into the charge CATALINA_HOME/logs/catalina.out. The run controversy causes Tomcat to leave the standard output signal and erroneousness streams where they presently are ( such as to the console window ) useful for running from a terminal when you want to see the inauguration output. This output signal should look similar to Example 1-1. exemplar 1-1. output from catalina run

ian:389$ bin/catalina.sh start
Using CATALINA_BASE:   /home/ian/apache-tomcat-6.0.14
Using CATALINA_HOME:   /home/ian/apache-tomcat-6.0.14
Using CATALINA_TMPDIR: /home/ian/apache-tomcat-6.0.14/temp
Using JRE_HOME:       /usr/java/jdk1.6.0_02
Sep 27, 2007 10:42:16 PM org.apache.catalina.core.AprLifecycleListener lifecycleEvent
INFO: The Apache Tomcat Native library which allows optimal performance in produ ction
environments was not found on the java.library.path:
/usr/java/jdk1.5.0_06/bin/../jre/bin:/usr/lib
Sep 27, 2007 10:42:17 PM org.apache.coyote.http11.Http11BaseProtocol init
INFO: Initializing Coyote HTTP/1.1 on http-8080
Sep 27, 2007 10:42:17 PM org.apache.catalina.startup.Catalina load
INFO: Initialization processed in 948 ms
Sep 27, 2007 10:42:17 PM org.apache.catalina.core.StandardService start
INFO: Starting service Catalina
Sep 27, 2007 10:42:17 PM org.apache.catalina.core.StandardEngine start
INFO: Starting Servlet Engine: Apache Tomcat/6.0.14
Sep 27, 2007 10:42:17 PM org.apache.catalina.core.StandardHost start
INFO: XML validation disabled
Sep 27, 2007 10:42:27 PM org.apache.coyote.http11.Http11BaseProtocol start
INFO: Starting Coyote HTTP/1.1 on http-8080
Sep 27, 2007 10:42:28 PM org.apache.jk.common.ChannelSocket init
INFO: JK: ajp13 listening on /0.0.0.0:8009
Sep 27, 2007 10:42:29 PM org.apache.jk.server.JkMain start
INFO: Jk running ID=0 time=0/106  config=null
INFO: Find registry server-registry.xml at classpath resource
Sep 27, 2007 10:42:30 PM org.apache.catalina.startup.Catalina start
INFO: Server startup in 1109 ms

If you use catalina with the start option or invoke the startup script rather of using the run argument, you see only the beginning few Using... lines on your cabinet ; all the stay of the end product is redirected into the catalina.out logfile. The shutdown script invokes catalina with the controversy stop, which causes Tomcat to connect to the default port specified in your Server chemical element ( discussed in Chapter 7 ) and send it a closure message. A complete list of startup options is listed in table 1-2. mesa 1-2. startup options

choice Purpose
-config [ server.xml file] This specifies an alternate server.xml shape file to use. The default is to use the server.xml file that resides in the $ CATALINA_BASE/conf directory. See the “ server.xml “ department in chapter 7 for more data about server.xml ‘s contents .
-help This prints out a compendious of the command-line options .
-nonaming This disables the function of JNDI within Tomcat .
-security This enables the use of the catalina.policy file .
debug This starts Tomcat in debugging manner .
embedded This allows Tomcat to be tested in an embedded modality, and is normally used by application waiter developers .
jpda start This starts Tomcat as a Java Platform Debugger Architecture-compliant debugger. See Sun ‘s JPDA documentation at hypertext transfer protocol : //java.sun.com/products/jpda .
run This starts up Tomcat without redirecting the standard output and errors .
start This starts up Tomcat, with criterion output signal and errors going to the Tomcat logfiles .
stop This stops Tomcat .
version This outputs Tomcat ‘s interpretation information .

Environment variables

To prevent fugitive programs from overwhelming the operate system, Java runtime environments feature limits such as “ maximal pile size. ” These limits were established when memory was more expensive than at stage ; for JDK 1.3, for exemplar, the default specify was only 32 MB. however, there are options supplied to the java command that let you control the limits. The claim form depends upon the Java runtime, but if you are using the Sun runtime, you can enter :

java -Xmx=256M MyProg

This will run a classify file called MyProg with a utmost memory size of 256 MB for the entire Java runtime process. These options become important when using Tomcat, as running servlets can begin to take up a lot of memory in your Java environment. To pass this or any other option into the java command that is used to start Tomcat, you can set the option in the environment variable JAVA_OPTS before running one of the Tomcat inauguration scripts. Windows users should set this environment variable from the Control Panel, and Unix users should set it directly in a shell prompt or login handwriting :

$ export JAVA_OPTS="-Xmx256M"  # Korn and Bourne shell
C:\> set JAVA_OPTS="-Xmx256M"  # MS-DOS
$ setenv JAVA_OPTS "-Xmx256M"  # C-shell

early Tomcat environment variables you can set are listed in mesa 1-3. table 1-3. Tomcat environment variables

option Purpose default
CATALINA_BASE This sets the base directory for writable or customize portions of a Tomcat installation tree, such as logging files, workplace directories, Tomcat’s conf directory, and the webapps directory. It is an alias for CATALINA_HOME . Tomcat facility directory

CATALINA_HOME This sets the base directory for electrostatic ( read-only ) portions of Tomcat, such as Tomcat ‘s lib directories and command-line scripts . Tomcat initiation directory
CATALINA_OPTS This passes through Tomcat-specific command-line options to the java command . none
CATALINA_TMPDIR This sets the directory for Tomcat irregular files . CATALINA_HOME/temp
JAVA_HOME This sets the localization of the Java runtime or JDK that Tomcat will use . none
JRE_HOME This is an alias to JAVA_HOME . none
JAVA_OPTS This is where you may set any Java command-line options . none
JPDA_TRANSPORT This variable may set the transport protocol used for JPDA debug . dt_socket
JPDA_ADDRESS This sets the address for the JPDA used with the catalina jpda start command . 8000
JSSE_HOME This sets the location of the Java Secure Sockets Extension used with HTTPS . none
CATALINA_PID This variable may optionally hold the path to the procedure ID file that Tomcat should use when starting up and shutting down . none

Starting and stopping: The general case

If you have installed Tomcat via an Apache binary star release archive ( either a .zip file or a .tar.gz file ), change directory into the directory where you installed tom :

$ cd apache-tomcat-6.0.14

Echo your $JAVA_HOME environment variable. Make certain it ‘s set to the absolute path of the directory where the Java facility you want Tomcat to use resides. If it ‘s not, set it and export it nowadays. It ‘s oklahoma if the java interpreter is not on your $PATH because Tomcat ‘s scripts are chic enough to find and use Java based on your set of $JAVA_HOME. Make indisputable you ‘re not running a TCP waiter on port 8080 ( the default option Tomcat HTTP server socket port ), nor on TCP port 8005 ( the default option Tomcat closure server socket port ). Try running telnet localhost 8080 and telnet localhost 8005 to see if any existing server accepts a connection, fair to be certain. Start up Tomcat with its startup.sh handwriting like this :

$ bin/startup.sh
Using CATALINA_BASE:   /home/jasonb/apache-tomcat-6.0.14
Using CATALINA_HOME:   /home/jasonb/apache-tomcat-6.0.14
Using CATALINA_TMPDIR: /home/jasonb/apache-tomcat-6.0.14/temp
Using JAVA_HOME:       /usr/java/jdk1.6.0_02

You should see output similar to this when tom starts up. once started, it should be able to serve vane pages on port 8080 ( if the server is localhost, try hypertext transfer protocol : //localhost:8080 in your web browser ). Invoke the shutdown.sh script to shut Tomcat down :

$ bin/shutdown.sh
Using CATALINA_BASE:   /home/jasonb/apache-tomcat-6.0.14
Using CATALINA_HOME:   /home/jasonb/apache-tomcat-6.0.14
Using CATALINA_TMPDIR: /home/jasonb/apache-tomcat-6.0.14/temp
Using JAVA_HOME:       /usr/java/jdk1.6.0_02

Starting and stopping on Linux

If you ‘ve installed Tomcat via the RPM package on Linux, you can test it out by issuing a beginning dominate via Tomcat ‘s init script, like this :

# /etc/rc.d/init.d/tomcat start
Starting tomcat:                                          [  OK  ]

Or, on some Linux distributions, such as Fedora and Red Hat, to do the lapp thing, you may alternatively type the shorter command :

# service tomcat start

If you installed the JPackage.org Tomcat RPM package, the name of the init script is tomcat55, so the instruction would be :

# /etc/rc.d/init.d/tomcat55 start

then, check to see if it ‘s run :

# ps auwwx | grep catalina.startup.Bootstrap

You should see several Java processes scroll by. Another way to see whether Tomcat is running is to request a web page from the server over TCP port 8080 .

Tip

If Tomcat fails to startup correctly, go back and make surely that the /opt/tomcat/conf/tomcat-env.sh file has all the right settings for your server computer ( in the JPackage.org RPM installation case, it ‘s the /etc/tomcat55/tomcat55.conf file ). besides check out the “ coarse Errors “ section, late in this chapter. To stop Tomcat, issue a stop command like this :

# /etc/rc.d/init.d/tomcat stop

Or ( shorter ) :

# service tomcat stop

Starting and stopping on Solaris

To use Tomcat ‘s init script on Solaris, you must be the root exploiter. Switch to root beginning. then, you can start Tomcat like this :

# /etc/init.d/cswtomcat5 start

And, you can stop it like this :

# /etc/init.d/cswtomcat5 stop

Watch your catalina.out logfile in /opt/csw/share/tomcat5/logs so that you ‘ll know if there are any errors .

Starting and stopping on Windows

On Microsoft Windows, Tomcat can be started and stopped either as a window overhaul or by running a batch file. If you arrange for automatic inauguration ( detail late in this chapter ), you may manually start Tomcat in the control condition empanel. If not, you can start Tomcat from the desktop icon. If you have Tomcat running in a comfort window, you can interrupt it ( normally with Ctrl-C ) and it will catch the sign and shut down :

Apache Tomcat/6.0.14
^C
Stopping service Tomcat-Standalone
C:\>

If the elegant closure does not work, you need to find the tend process and terminate it. The JVM running Tomcat will normally be identified as a Java march ; be sure you get the correct Java if other people or systems may be using Java. Use Ctrl-Alt-Delete to get to the undertaking coach, select the right Java serve, and suction stop on End Task .

Starting and stopping on Mac OS X

The Mac OS X installation of Tomcat is just the binary distribution, which means you can use the packaged carapace scripts that come with the Apache binary let go of. This provides a quick and easy set of scripts to start and stop Tomcat as required. First, we will show you the general lawsuit for starting and stopping Tomcat on Mac OS X. Mac OS X sets all your paths for you thus all you need to do is ensure that there are no TCP services already running on port 8080 ( the nonpayment Tomcat HTTP server socket port ), nor on port 8005 ( the default option Tomcat shutdown larboard ). This can be done easily by running the netstat command :

$ netstat -an | grep 8080

You should see no output. If you do, it means another platform is listening on port 8080, and you should shut it down first, or you must change the larboard numbers in your CATALINA_HOME/conf/server.xml configuration file. Do the like for port 8005. tom can be started on OS X with the follow command :

$ cd /; sudo -u nobody /usr/local/tomcat/bin/startup.sh; cd -

tom can be stopped with the follow dominate :

$ cd /; sudo -u nobody /usr/local/tomcat/bin/shutdown.sh; cd -

Because the user nobody is an unprivileged user, a bunch of folders on your magnetic disk are not accessible to it. This is of course a dear thing, but because the scripts for starting and stopping Tomcat attempt to determine the current directory, you will get errors if the scripts are not being called from a booklet to which the exploiter nobody has read access. To avoid this, the above commands dwell of three subcommands. First, they change to the root booklet ( / ), next they call script to start or stop Tomcat as the user nobody, and finally they return to the folder they started in. If you are running the commands from a folder to which the exploiter nobody has read access ( e.g., / ), you can shorten the commands by leaving out the first gear and end parts as follows :

$ sudo -u nobody /usr/local/tomcat/bin/startup.sh
$ sudo -u nobody /usr/local/tomcat/bin/shutdown.sh

late in the “ Automatic Startup on Mac OS X “ section, we show you how to create and install init scripts via Apple ‘s launchd, as you see in the Linux RPM installations and the BSD port installs, to allow you to not entirely start and stop Tomcat, but besides to automatically start Tomcat on boot—the Mac OS X manner !

Starting and stopping on FreeBSD

This port installs Tomcat into the ancestor way /usr/local/tomcat6.0/. The behavior of Tomcat may be configured through variables in your /etc/rc.conf file, which override settings that are contained in the /etc/defaults/rc.conf file. This port includes an RCng handwriting named $ { PREFIX } /etc/rc.d/tomcat60.sh. By default, this ends up being /usr/local/etc/rc.d/tomcat60.sh. Read the clear of this file to see what Tomcat variable settings you may apply in your /etc/rc.conf charge. Try starting Tomcat like this :

# /usr/local/etc/rc.d/tomcat60.sh start
Starting tomcat60.

This will merely work if you have added this line to your /etc/rc.conf file :

tomcat60_enable="YES"

You may use the tomcat60.sh handwriting to start, stop, and restart Tomcat 6. By default option, this FreeBSD port of Tomcat 6.0 sets Tomcat ‘s default HTTP port to be 8180, which is different than the default that is in the first place set ( for all operate systems ) in the Apache Software Foundation ‘s distribution of Tomcat ( which is 8080 ). Try accessing your FreeBSD Tomcat port via the URL hypertext transfer protocol : //localhost:8180/ .

source : https://thefartiste.com
Category : Tech

About admin

I am the owner of the website thefartiste.com, my purpose is to bring all the most useful information to users.

Check Also

articlewriting1

Manage participants in a zoom meeting webinar

Call the people who attend the meet as follows Alternate host host Who scheduled the …

Leave a Reply

Your email address will not be published.