how to stop all ports in apache tomcat - java

While developing a web application using Apache Tomacat and Eclipse frequently I get this message
Several ports (7354, 6544, 9999) required by Tomcat v7.0 Server at localhost are already in use. The server may already be running in another process, or a system process may be using the port. To start this server you will need to stop the other process or change the port number(s).
I know that this ports are in use, but I don't if I stop all those servers also why get the same message. My question is - Is there any way to stop all ports at once in using Eclipse or Windows 7 ?

you can use the lsof in combination with awk. do the following:
lsof -i :<portnumber> | awk '{print "kill -9 "$2}' | sh
if you want to know only the processId from the port, use:
lsof -i :<portnumber> | awk '{print $2}'
btw: i have this problem sometimes too. If you're using eclipse check in the debug view if there is still a thread of the tomcat running. if so, stop them :)
Otherwise restart eclipse.

Have you tried the following?
ps -ef | grep <port number>
kill -9 <process id>

Related

Facing issue with Tomcat execution in eclipse

I tried uninstalling and reinstalling tomcat after removing the server instance from the eclipse environment. I spent so much time yet there is no use. This is the error I keep receiving.
Error in the eclipse environment.
It says that the port 8080 required by Tomcat is in use. But in port 8080 only tomcat is running. I am attaching a screenshot for the same.Ports in Resource Manager.
Please help me resolve this issue, Thanks in advance!!!.
netstat -ano | findstr :
for example, use the below command in the terminal or cmd
netstat -ano | findstr :8080
find the process id
and then use
taskkill /PID /F
to kill the task.

Shell script to validate if my tomcat is running or not - uniquely identify

I see many shell scripts to check process if that is running we proceed further.
But there is scenario like below or if we have multiple tomcat running on single host, how do we identify if our process running?
e.g if I go to path /opt/alfresco/tomcat/bin and execute command
ps -ef | grep tomcat
It will give me output (even tomcat is not running)
[alfresco#host030 bin]$ ps -ef |grep tomcat
alfresco 12090 11302 0 22:57 pts/0 00:00:00 grep tomcat
[alfresco#host030 bin]$
So if I am using alfresco tomcat and I need to validate if my tomcat process actually started and running, how do I validate?
Also to differentiate between any java and tomcat running, HOW ?
You can try with the below script. Do grep for the listening port, use your port number.
JAVA_HOME=/usr/java/default
SHUTDOWN_PORT=`netstat -vatn|grep LISTEN|grep 8005|wc -l`
export JAVA_HOME=$JAVA_HOME
if [ $SHUTDOWN_PORT -ne 0 ]; then
echo 'Alfresco is running'
else
echo "Alfresco is not running"
To start it you can use
ALF_HOME=/www/web/dev1/alfresco
$ALF_SCRIPT start
If your tomcat is running as a service you can run service tomcat status.
If its not running as service its recommended to do it..
Read this how to do it: https://www.linux.com/learn/managing-linux-daemons-init-scripts

Getting PID of a process that has just started

I am working on a Gradle Java project. Which starts Tomcat for testing and stops it later.
I am supposed to kill this Tomcat instance when the test fails.
I tried using "ps aux| grep tomcat | grep -v grap | awk {print $2}" command to get the process id and kill the process.
But on Production, there will be so many Tomcat processes running simultaneously by many users, I just want the tomcat process started by my build.gradle for test execution.
So how can I accomplish the task? Please provide me some guidelines.
You need to find a unique string in the output of 'ps aux' which differentiates your test tomcat and others'.
I currently use the below script to run 'shutdown.sh' first and then kill the PID as most of the times, the application stops but the process does not stop.
PID=`ps -ef | grep $JAVA_HOME/bin/java | grep "$TOMCAT_LOC"/conf | grep -v grep | awk '{ print $2 }'`
if [ $PID ]; then
echo tomcat is running with PID:$PID.
# Stop or Kill running Tomcat
if [[ -f $TOMCAT_LOC/bin/shutdown.sh ]]; then
[[ ! -x $TOMCAT_LOC/bin/shutdown.sh ]] && chmod a+x $TOMCAT_LOC/bin/shutdown.sh
$TOMCAT_LOC/bin/shutdown.sh >>/dev/null
sleep 20
fi
kill -9 $PID
sleep 3
else
echo tomcat is not running
fi
You may also look at configuring a PID file by editing the 'catalina.sh' which you can read later to find out your PID.
# CATALINA_PID (Optional) Path of the file which should contains the pid
# of the catalina startup java process, when start (fork) is
# used
Java JRE has tool called jps in $JAVA_HOME/bin folder.
It's similar to unix ps command but for java only.
You can use it to determined exac java process you need.
Using this tool is more recommended and actually it is more useful, when you have more than one java applications is running on your host...
for example I have running h2 database and many other apps, but wanna kill only h2, so I can use jps to get it PID
$ jps
17810 GradleDaemon
17798 GradleWrapperMain
17816 h2-1.4.197.jar
17817 GradleDaemon
17818 GradleDaemon
18011 Jps
16479
and then just kill needed process:
kill -9 17816
and all other java apps will continue work normally. I not sure about tomcat, but I think it can be done in similar way, something like that:
kill -9 $(jps | grep tomcat | awk '{print $1}')
Lastly, little bit offtopic, but a specially to your case: correct way would be using start/stop/restart scripts provided by tomcat
The correct way to terminate a Tomcat instance is via its own shutdown command. You should not be thinking of processes, or PIDs, or kills, at all.
so if you want to kill tomcat from that user from which you have logged in then try following and let me know if this helps you.
ps -ef | grep -v grep | grep `whoami` | grep tomcat
So by ps -ef I am listing all the processes then grep -v grep will remove the grep command's process then grep whoami will look for your currently logged in user then grep tomcat will look only for tomcat process, test it once and if All is Well then you could kill it.
By the way how about tomcat stop script? In case it is there you could use that also.
You can use shell variable $!. It represents the PID of the most recent background command.
yourCommand &
CMD_PID=$!
echo $CMD_PID

Port 8005 Required by Tomcat, already in use

I am attempting to refresh my knowledge of Java. I've downloaded and started using Eclipse Mars. I was following a tutorial that uses Tomcat. I tried to create and start a server. I received the following message in the image: Port 8005 is in use.
I checked and surely it is but I don't know what is using it or how to either stop that process or make Tomcat use another port. Thank you in advance for the help.
Tomcat uses -
8005,8080,8009
Those three ports.
Open up command prompt -
C:\.....>netstat -o -n -a | findstr 0.0:8080
TCP 0.0.0.0:8080 0.0.0.0:0 LISTENING 1220
C:\....\username>taskkill /F /PID 1220
It will kill that task.Try it.
METHOD 1
ps -aef | grep java | grep apache | awk '8005'
list of process running with this port will display with its process id.
pick the process id say 1090.
kill -9 1090
METHOD 2
This will kill all the process with tomcat
kill $(ps -aef | grep java | grep apache | awk '{print $2}')

How to stop Jetty webserver in Google App Engine

If you are doing local development I want to know how we can stop/kill Jetty webserver? I have to close my Eclipse IDE whenever I need to do that. Is there any other way to do it? Or we have to kill the process?
Thanks.
You should see Jetty instance(s) running in one of the Console. Just press the Red Button.
Jetty can be stopped in the following ways:
You can click the "red" button in the Eclipse console window
You can type "q" then hit enter in the console window (or "r" for restart) (This may only work for Run Jetty Run)
If both of those fail, then if you're on linux or osx, you can open a terminal window and type the following to find the process id of Jetty and kill it. The process id is the 2nd column shown in the results, and you'll need to be careful that you're not seeing some other process here as well:
ps aux | grep jetty | grep java
then run the following to kill the process
kill process_id_from_above_call
You can run the above 2 commands in one shot by doing this:
kill $(ps aux | grep jetty | grep java | awk '{print $2}')
but be sure you're matching Jetty before you do this, as you may kill something you don't want to kill if it doesn't match correctly ;-) Note that if it still isn't killed by the above, you can force it to be killed by doing this:
kill -9 $(ps aux | grep jetty | grep java | awk '{print $2}')

Categories

Resources