1

I work on huge repositories linked to my java project (running on Eclipse) and sometimes (when I do text search usually), my Eclipse stops working.

If I "hard close" it in that state and if I have my Tomcat started, the problem is that it will not stop tomcat before exiting.

When I launch Eclipse again, it will show me that Tomcat is stopped (it is not because it didn't stop tomcat when I hard closed Eclipse), and if I try to launch it again I have the following error :

Tomcat error

The only way for me to restart it is to reboot my computer.. I admit that it is a bit annoying..

Do you know if there is a way to stop my "phantom-running" tomcat server in Eclipse or do I have to restart my computer everytime it happens ? (I don't have admin rights on my computer, I can't use the task manager to kill process)

Many thanks

BCh
  • 65
  • 11
  • just open the task manager and kill the tomcat process from there. No need to restart the server – Svetlin Zarev Jun 13 '19 at 08:47
  • Hi, I don't have admin rights on my computer, I can't use the task manager to kill process. Is there a way to do it from Eclipse, or to "refresh" tomcat status – BCh Jun 13 '19 at 08:49
  • 1
    kill the ports 8005, 8080, 8009 [https://stackoverflow.com/questions/39632667/how-to-kill-the-process-currently-using-a-port-on-localhost-in-windows][1] – Apil Pokharel Jun 13 '19 at 08:50

1 Answers1

1

The standard mechanism to stop tomcat is to send a shutdown command on the shutdown port. Usually the shutdown port is 8005. You can stop the server by sending the command manually:

  • On linux (just for completeness): echo "SHUTDOWN" | nc -w 2 127.0.01 8005
  • On windows:
    1. telnet 127.0.0.1 8005
    2. type SHUTDOWN

If you do not have access to those commands, you can write a simple app in java:

   public static void main(String[] args) throws IOException {
        final InetSocketAddress shutdownAddress = new InetSocketAddress(Inet4Address.getLoopbackAddress(), 8005);
        try (Socket socket = new Socket()) {
            socket.connect(shutdownAddress);

            try (OutputStream out = socket.getOutputStream()) {
                out.write("SHUTDOWN".getBytes(StandardCharsets.US_ASCII));
            }
        }
    }

PS: On linux you can also send signal SIG_INT: kill -2 <PID>

Svetlin Zarev
  • 9,115
  • 3
  • 42
  • 69
  • telnet isn't availiable for me but I see what you want to do here. Plus, I don't think it requires admin rights. I'll search in my way to find an equivalent that I can use (maybe netstat -ano to get PID). Thank you – BCh Jun 13 '19 at 09:05
  • 1
    Well, you can do it programmatically as well. Just open a TCP socket to 127.0.0.1:8005 and send SHUTDOWN. It's not more than 20 lines in java. – Svetlin Zarev Jun 13 '19 at 16:38