I am trying to start elasticsearch as a process and stop it without closing the command prompt. For creating a new process, I am using:
C:\Users\User1\Desktop\Work\ElasticSearch\elasticsearch-1.3.1\bin>start /B elasticsearch
C:\Users\User1\Desktop\Work\ElasticSearch\elasticsearch-1.3.1\bin>start /B elasticsearch
C:\Users\User1\Desktop\Work\ElasticSearch\elasticsearch-1.3.1\bin>[2014-08-19 15:23:26,351][WARN ][bootstrap ] jvm uses the c
lient vm, make sure to run `java` with the server vm for best performance by adding `-server` to the command line
[2014-08-19 15:23:26,433][INFO ][node ] [Batroc the Leaper] version[1.3.1], pid[5800], build[2de6dc5/2014-07-28T14:45:15
Z]
The process runs on port 9200.
How can I get the process PID or name to use taskkill to kill this process using this command or something similar from either the already open command prompt or the existing command prompt in which the elasticsearch node process is running:
taskkill /PID <pid>
Pid of 5800(shown in process log in console above) did not work. Windows task manager did not have a process by the name elasticsearch. It only has a cmd process for the command prompt in which the elasticsearch is running and when I kill that process, the elasticsearch also gets killed.
I'd install and run Elasticsearch as a Windows service:
Windows users can configure Elasticsearch to run as a service to run in the background or start automatically at startup without any user interaction. This can be achieved through service.bat script under bin/ folder which allows one to install, remove, manage or configure the service and potentially start and stop the service, all from the command-line.
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/setup-service-win.html
It let's you run commands like start and stop to run and terminate elasticsearch from a script without having to track process ids or keep the same command prompt open.
UPDATE:
To run multiple instances of Elasticsearch at the same time as services you will need to pass in a unique serviceid when installing the service:
The script requires one parameter (the command to execute) followed by an optional one indicating the service id (useful when installing multiple Elasticsearch services).
Regarding what port and IP address ES is running on it should be no different - but I'd check your config files (elasticsearch.yml) and your logging config (logging.yml). More detail on configuration options here:
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/setup-configuration.html
If you Installing Elasticsearch as a Service on Windows, you can start/stop from the Services control panel, more info like start/stop use CMD see in the link.
The way above is convenient and correct. I try some other ways to stop ElasticSearch and record here,
Before knowing the method above, first I guess ElasticSearch may be a process in the Task Manager, so I found by name and really found a process name ElasticSearch.exe
, but after I kill that process, I still can get ElasticSearch Info from http://localhost:9200/
which is the ElasticSearch port on my computer, that means ElasticSearch is still running.
Later I came up with that maybe I can kill it by port
, I find an article using PowerShell to kill process by port, so I start a PowerShell, then execute Stop-Process -Id (Get-NetTCPConnection -LocalPort 9200).OwningProcess -Force
, and it tells me:
Stop-Process : Cannot stop "java (22356)" process,Access Denied。 + Stop-Process -Id (Get-NetTCPConnection -LocalPort 9200).OwningProcess ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : CloseError: (System.Diagnostics.Process (java):Process) [Stop-Process],ProcessCommandException
it might caused by not run as Administrator, but from the information I can tell that the real process running ElasticSearch is java.exe
, and its process ID is 22356, after killing java.exe using Task Manager, I cannot connect to http://localhost:9200/
, that mean I successfully stopped ElasticSearch.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With