1

I've written a software module in PHP that manages the saving of data in different data stores (MySQL, ElasticSearch and Redis). To test the module, I've created several test plans in Apache JMeter, including some that make a lot of concurrent requests. The tests are run against a LAMP stack in an Ubuntu 14.04 LTS VM (a Vagrant box).

What I've observed is, that sometimes port 9200 (ElasticSearch) gets closed after a given number of requests. Which is fine, because I want to test scenarios where one of the data stores becomes unavailable. However, to validate the test results, I need that port open again.

ElasticSearch is still running and listening to the port.

Situation before test run

$ nmap -p 9200 localhost
(...)
PORT     STATE SERVICE
9200/tcp open  wap-wsp

$ sudo netstat -tlnp | grep '9200'
tcp6       0      0 :::9200                 :::*                    LISTEN      1057/java

Situation after test run

$ nmap -p 9200 localhost
(...)
PORT     STATE  SERVICE
9200/tcp closed wap-wsp

$ sudo netstat -tlnp | grep '9200'
tcp6       0      0 :::9200                 :::*                    LISTEN      1057/java

Question

So far, I've waited until the store opened up again or I've restarted the VM. However, this is very inconvenient, which leads me to the actual question:

Is there a command to re-open a closed port?

I've searched, but only found advise on how to configure iptables. I've tried

$ sudo iptables -A INPUT -d 0/0 -s 0/0 -p tcp --dport 9200 -j ACCEPT

But from what I gather, this only creates a rule, and it doesn't have any immediate effect on the port:

$ sudo iptables -L -n
Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0            tcp dpt:9200

$ nmap -p 9200 localhost
(...)
PORT     STATE  SERVICE
9200/tcp closed wap-wsp

1 Answer 1

1

I think that this java application listening on port 9200 just crashed and you need to restart it.

From netstat -nlpt | grep 9200, you can get the process id (just next to /java at the end).

Then with that id, run: ps aux | grep [process id] to find out what's the java app if you don't already now and just restart it, that should solve your issues!

2
  • Thank you for your answer. I think you are right. I used to restart the ElasticSearch service, but that never helped. Now I ran the procedure again and wanted to kill the Java process instead, but netstat didn't show anything listening. So I simply started the service (sudo service elasticsearch start) and the port was open immediately. I guess I'll just write a script that parses the output of netstat, kills the Java process if there is one, and then starts the service. I'll come back and accept this answer once I'm sure the issue is resolved. Thanks!
    – jgxvx
    Feb 8, 2015 at 23:04
  • No problem. To avoid having your issue, you should try to find out why java stops running as expected, either on the java app side, or the way your code interacts with it.
    – Val F.
    Feb 9, 2015 at 3:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .