Problem using ES as a service on W10

I saw this question from 2021. But for one thing my system doesn't have an "elastic-agent.exe" file.

I was using ES 7.10.2 up until about 3 years ago. Then I decided to upgrade to 8.x ... and eventually settled on 8.13.1. This was a huge effort (!) not least because I switched to using https instead of http, with all the complications entailed by passwords and the like.

But I have only ever run this 8.13.1 installation manually to date. I have a .bat file like this:

cd D:\apps\ElasticSearch\elasticsearch-8.13.1\bin
set ES_PATH_CONF=D:/apps/ElasticSearch/elasticsearch-8.13.1/config
REM -d --> "daemonize"
start /min cmd.exe /c elasticsearch.bat -d

This works fine ... but it means I have a command prompt window where I see ES server output. Maybe there's a way of hiding this?
So today I thought it might be nice to delete the 7.10.2 service and install 8.13.1 as a service.

I used "elasticsearch-service.bat install" (and also changed the ES_PATH_CONF environment var to the above...).

Unfortunately I'm getting this 1067 error, full message:
"Windows could not start the service Elasticsearch 8.13.1 (elastic-search-x64) service on Local Computer.
Error 1067: The process terminated unexpectedly"

I had a pretty good look at W10 system error logs ("Event Viewer"): there are some mysterious errors reported there but nothing which I could see which might throw light on things.

Things are fine in the sense that I can carry on running the above script to crank up the ES server till Hell freezes over if necessary. But has anyone got any suggestions about what might be going wrong?

Anyone who has this problem: I found a solution which works on my system.

Get hold of nssm.exe (service manager app).

  • in an ELEVATED command prompt, run this:

> nssm install

  • fill in the the path to ES elasticsearch.bat. In my case "D:\apps\Elasticsearch\elasticsearch-8.13.1\bin\elasticsearch.bat"

  • give it a "service name".

... seems to work. No messy command prompt window for the ES server. But it's running.

May or may not start up automatically. My D: drive is bitlocked so after I boot I have to unlock this first and then run a script (in an elevated prompt) which, among other things, runs this:

sc start es8

PS remember to set your ES_PATH_CONF env var permanently to point to the right "config" directory.

I have never used nssm for ES, only for Kibana and LS.
Only you have to run in the bin directory:
elasticsearch-service.bat install Elasticsearch
I you need to change the name or other the service pararameters, edit:
elasticsearch-service.bat manager Elasticsearch

When you have issues with the ES service start-up, check elastic log.
By default in: elasticsearch\logs<clustername>.log