2

I have installed elasticsearch . This is how I am running it currently.

cd /elasticsearch-6.3.1/bin
./elasticsearch

It is working fine. But, I want to run this program as a service. Like, I want to run it like,

sudo service elasticsearch restart

It should run the elasticsearch. I have tried to create a script in /etc/init.d , but it is not working. This is what I did,

cd /etc/init.d
sudo vim elasticsearch

This is content in that file,

cd /elasticsearch-6.3.1/bin
./elasticsearch

What is the recommended way to achieve this ?

1 Answers1

0

Create an upstart script like the following

# ElasticSearch upstart script

description     "ElasticSearch service"

start on (net-device-up
          and local-filesystems
          and runlevel [2345])

stop on runlevel [016]

respawn

respawn limit 10 30

# NB: Upstart scripts do not respect
# /etc/security/limits.conf, so the open-file limits
# settings need to be applied here.
limit nofile 32000 32000

setuid elasticsearch
setgid elasticsearch
exec /path/to/elasticsearch/bin/elasticsearch -f -Des.default.config=/path/to/config/elasticsearch.yml -Des.default.path.home=/usr/share/elasticsearch/ -Des.default.path.logs=/var/log/elasticsearch/ -Des.default.path.data=/var/lib/elasticsearch/ -Des.default.path.work=/tmp/elasticsearch -Des.default.path.conf=/path/to/config/

Replace the paths with the absolute paths in your case. Save this as elasticsearch.conf in /etc/init/

Also note that you're best off running elasticsearch as it's own user (hence the setuid and setgid lines)

Amith KK
  • 13,412