Is Tomcat running?
is there a better way of checking that Tomcat is running? The above seem to be to be a ‘hacky’ way of checking that Tomcat is running.
18 Answers 18
On my linux system, I start Tomcat with the startup.sh script. To know whether it is running or not, i use
If the output result contains the whole path to my tomcat folder, then it is running
try this instead and because it needs root privileges use sudo
sudo service tomcat7 status
Why grep ps , when the pid has been written to the $CATALINA_PID file?
I have a cron ‘d checker script which sends out an email when tomcat is down:
kill -0 `cat $CATALINA_PID` > /dev/null 2>&1 if [ $? -gt 0 ] then echo "Check tomcat" | mailx -s "Tomcat not running" support@dom.com fi
I guess you could also use wget to check the health of your tomcat. If you have a diagnostics page with user load etc, you could fetch it periodically and parse it to determine if anything is going wrong.
is this as easy to do with windows? would i just modify the commands for windows equivalents, throw it in a batch file, and then schedule through scheduler?
You could do something along the lines of tasklist |find /I «Tomcat» || echo «Tomcat not running» in a bat file, but you may need to find java, not Tomcat depending on what the process name is.
To learn what the value of $CATALINA_PID is from your OS-installed Tomcat, try: ps aewwx | grep CATALINA_PID and you will find it in the output for the running process, amongst the other environment variables. In Debian 8 this value is: CATALINA_PID=/var/run/tomcat8.pid
It’s important to note that a pid file may not exist, it depends on the environment and how tomcat was started. See this answer to create a pid file on startup.
netstat -lnp | grep 8080 would probably be the best way, if you know Tomcat’s listening port. If you want to be certain that is is functional, you will have to establish a connection and send an HTTP request and get a response. You can do this programatically, or using any web browser.
IF you know the port, I think this is the simplest way given that there are variations in how you check if the executable is running depending on how you installed Tomcat, whether its a service or not etc.
You can check the status of tomcat with the following ways:
This will return the tomcat path if the tomcat is running
where 8080 is the tomcat port
If tomcat is installed locally, type the following url in a browser window:
This will display Tomcat home page with the following message.
If you’re seeing this, you’ve successfully installed Tomcat. Congratulations!
If tomcat is installed on a separate server, you can type replace localhost by a valid hostname or Iess where tomcat is installed.
The above applies for a standard installation wherein tomcat uses the default port 8080
If Tomcat is installed on a separate server, failing to access it from a browser won’t tell you for sure whether it’s running or not: it may be unreachable.
I have installed Tomcat8 on Ubuntu, but going to localhost:8080 results in the «Unable to connect» message.
Create a Shell script that checks if tomcat is up or down and set a cron for sh to make it check every few minutes, and auto start tomcat if down. Sample Snippet of code below
TOMCAT_PID=$(ps -ef | awk '/[t]omcat/') echo TOMCAT PROCESSID $TOMCAT_PID if [ -z "$TOMCAT_PID" ] then echo "TOMCAT NOT RUNNING" sudo /opt/tomcat/bin/startup.sh else echo "TOMCAT RUNNING" fi
I created a shell script that always return «TOMCAT RUNNING» even I stopped tomcat. But when I run the command on console, it worked fine.
Make sure that shell script name doesn’t as tomcat keyword .If script has tomcat name , then in process list shell script name would show up , the code would think as if tomcat running . You can give any name to script without tomcat keyword in it
INFO: Server startup in 77037 ms
then I know the server is up.
wget url or curl url where url is a url of the tomcat server that should be available, for example: wget http://localhost:8080 . Then check the exit code, if it’s 0 — tomcat is up.
I’ve found Tomcat to be rather finicky in that a running process or an open port doesn’t necessarily mean it’s actually handling requests. I usually try to grab a known page and compare its contents with a precomputed expected value.
Are you trying to set up an alert system? For a simple «heartbeat», do a HTTP request to the Tomcat port.
For more elaborate monitoring, you can set up JMX and/or SNMP to view JVM stats. We run Nagios with the SNMP plugin (bridges to JMX) to check Tomcat memory usage and request thread pool size every 10-15 minutes.
We have upgraded our systems to use «monit» to check the tomcat process. I really like it. With very little configuration it automatically verifies the service is running, and automatically restarts if it is not. (sending an email alert). It can integrate with the /etc/init.d scripts or check by process name.
Since my tomcat instances are named as tomcat_ . For example. tomcat_8086, I use
Other method is using nc utility
nc -l 8086 (port number )
ps aux | grep java
It will return the pid if tomcat is running.
tomcat.sh helps you know this easily.
no argument: display the process-id of the tomcat, if it’s running, otherwise do nothing
So, run command on your command prompt and check for pid:
$ sudo netstat -lpn |grep :8080
Is any tomcat is running under the server.
tsssinfotech-K53U infotech # ps -aef|grep tomcat
root 9586 9567 0 11:35 pts/6 00:00:00 grep —colour=auto tomcat
I have multiple tomcat instances running on different ports for my cluster setup. I use the following command to check each processes running on different ports.
Replace the port number as per your need.
And to kill the process use -k in the above command.
- This is much faster than the ps -ef way or any other commands where you call a command and call another grep on top of it.
- Works well with multiple installations of tomcat ,Or any other server that uses a port as a matter of fact running on the same server.
The equivalent command on BSD operating systems is fstat
This answer applies to Tomcat running as a service on recent versions of Ubuntu. One benefit of a service is that it provides tools for getting clear and unambiguous information on the status of the program.
If Tomcat is running as a systemd service, which it almost certainly will be if you installed it from the repository on any recent (16.04+) Ubuntu version, you can check if it’s running using
systemctl status tomcat9.service
(replacing «9» with whatever version you’re using) and visually inspecting the output for the Active: field, which will be active (running) if Tomcat is up or inactive (dead) if Tomcat is down.
This is also easy to script, since the command systemctl status tomcat9.service does not require sudo and returns an exit code of 0 if Tomcat is running, or 3 if it is stopped:
# Run the command and suppress the standard output: systemctl status tomcat9.service > /dev/null 2>&1 # `$?` stores the exit code of the last command, # which is what we want: if [ $? -ne 0 ]; then # Tomcat is down, do whatever. fi
If you want to restart Tomcat in the event it’s down, that’s a bit harder to automate, since the command sudo systemctl (start|restart) tomcat9.service requires sudo . That’s a different question, though.
Prior to systemd , Tomcat was still installed as a service on Ubuntu as far back as I’m aware. On these systems, the equivalent command is
and you can check the exit codes in the same way.
how to start the tomcat server in linux?
what i tried before this is is correct or not? —please tell me my question is how to start a tomcat server in linux.Please tell me..
8 Answers 8
The command you have typed is /startup.sh , if you have to start a shell script you have to fire the command as shown below:
$ cd /home/mpatil/softwares/apache-tomcat-7.0.47/bin $ sh startup.sh or $ ./startup.sh
Please try that, you also have to go to your tomcat’s bin-folder (by using the cd-command) to execute this shell script. In your case this is /home/mpatil/softwares/apache-tomcat-7.0.47/bin .
stackoverflow.com/questions/6172258/… you have to set the path and export for JAVA_HOME and CATALAINA_HOME check the link
MY JDK IN JAVA_HOME=/home/mpatil/softwares/jdk-7u21-linux-x64.tar.gz i tried but nothing should comming
[root@localhost mpatil]# JAVA_HOME=/home/mpatil/softwares/jdk-7u21-linux-x64.tar.gz [root@localhost mpatil]#
Use ./catalina.sh start to start Tomcat. Do ./catalina.sh to get the usage.
I am using apache-tomcat-6.0.36.
if you are a sudo user i mean if you got sudo access:
otherwise: sh startup.sh
But things is that you have to be on the bin directory of your server like
I know this is old question, but this command helped me!
Go to your Tomcat Directory
Just type this command in your terminal:
cd apache-tomcat-6.0.43 ====: Go to Tomcat Directory sh bin/startup.sh =====: Start the tomcat on Linux sh bin/shutdown.sh ======:Shut Down the tomcat on Linux tail -f logs/catelina.out ====: Check the logs
Go to your Tomcat Directory with : cd/home/user/apache-tomcat6.0
Go to the appropriate subdirectory of the EDQP Tomcat installation directory. The default directories are:
On Linux: /opt/server/tomcat/bin
On Windows: c:\server\tomcat\bin
Run the startup command:
Run the shutdown command:
To run Apache Tomcat server in Linux following ways can be used. Let me share the difference as well since I see some got confusions with the multiple ways Apache Tomcat Server can be started.
The catalina.sh is the main control script for Tomcat . Following are the multiple ways of running tomcat:
Passing «run» argument for catalina.sh —> starts the Tomcat in the foreground and displays the running logs in the same console. when the console terminal is closed it will terminate the tomcat.
Passing «start» argument for catalina.sh —> starts the Tomcat in the background. Since in background no issues closing down the terminal. The logs need to be viewed as below: tail -f $CATALINA_HOME/logs/catalina.out
The last way is firing the startup.sh to start your Tomcat server. If you Vi the script you can see it calls catalina.sh script passing start as the argument. This will be running in background as well.
Tomcat 8 says it started but is not running on Linux / CentOS
New to Tomcat. Downloaded and unpacked tomcat 8.0.9 to my CentOS web server. Placed files in /opt/tomcat. /opt/tomcat/bin/setenv.sh contains: JRE_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java CATALINA_PID=»$CATALINA_BASE/tomcat.pid» My environment variable for CATALINA_HOME is set to /opt/tomcat, double checked by using: set | grep CATALINA_HOME
Using CATALINA_BASE: /opt/tomcat Using CATALINA_HOME: /opt/tomcat Using CATALINA_TMPDIR: /opt/tomcat/temp Using JRE_HOME: /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar Using CATALINA_PID: /opt/tomcat/tomcat.pid Existing PID file found during start. Removing/clearing stale PID file. Tomcat started.
However, it doesn’t really start. When I check netstat there is nothing listening on 8080: netstat -tulpn
Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1303/sshd tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 1065/master tcp 0 0 . 80 . * LISTEN 1504/httpd tcp 0 0 . 22 . * LISTEN 1303/sshd tcp 0 0 ::1:25 . * LISTEN 1065/master tcp 0 0 . 443 . * LISTEN 1504/httpd
Finally, when I run the shutdown.sh script it confirms that there was no tomcat process running even though the .pid file was created. /opt/tomcat/bin/shutdown.sh
Using CATALINA_BASE: /opt/tomcat Using CATALINA_HOME: /opt/tomcat Using CATALINA_TMPDIR: /opt/tomcat/temp Using JRE_HOME: /usr/lib/jvm/jre-1.7.0-openjdk.x86_64/bin/java Using CLASSPATH: /opt/tomcat/bin/bootstrap.jar:/opt/tomcat/bin/tomcat-juli.jar Using CATALINA_PID: /opt/tomcat/tomcat.pid PID file found but no matching process was found. Stop aborted.