./elasticsearch vs service elasticsearch start

I am a new user of elk whoa! So my knowledge is limited. But is there a difference running

./elasticsearch script

than running

service elasticsearch start

The reason being, I am following the installation guide for elasticsearch 2.X and when I come to the step of issuing the start up script I get errors such as the following:

asticsearchException[Failed to load logging configuration]; nested: NoSuchFileException[/usr/share/elasticsearch/config];
at org.elasticsearch.common.logging.log4j.LogConfigurator.resolveConfig(LogConfigurator.java:158)
at org.elasticsearch.common.logging.log4j.LogConfigurator.configure(LogConfigurator.java:103)
at org.elasticsearch.bootstrap.Bootstrap.setupLogging(Bootstrap.java:204)
at org.elasticsearch.bootstrap.Bootstrap.init(Bootstrap.java:258)
at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:35)
Caused by: java.nio.file.NoSuchFileException: /usr/share/elasticsearch/config
at sun.nio.fs.UnixException.translateToIOException(UnixException.java:86)
............

Well I can tell you there is no config file in /usr/share/elasticsearch. I have installed java 8. Maybe I am reading the output wrong.

So the issue seems to disappear when I run:

sudo service elasticsearch start

But elasticsearch is up and running successfully when tested with the curl command. Not sure what is going on. Any suggestions?

If you installed a package, then it will run as a service on your machine. Using service to start it is the right thing to do.

If you download the tar.gz, then use bin/elasticsearch

1 Like

That explains it! I used the .deb package instead of tar.gz file. Thank you.

The issue here comes down to permissions. When you start /path/to/elasticsearch from the script, you are attempting to run as your user. But since you installed Elasticsearch from a package, the config files are owned by the elasticsearch user and your user does not have permissions for them. However, when you run sudo service elasticsearch start, then you are starting the Elasticsearch process as the elasticsearch user which of course has permission to access the config files.

If you're curious, to fix the issue for running the script directly, you could either grant your user permissions to access the files (either by opening up the permissions for the others class, or adding your user to the elasticsearch group). An alternative is to run sudo -uelasticsearch /path/to/elasticsearch which would run the elasticsearch script as the elasticsearch user.

However, since you installed Elasticsearch from a package, you should just start Elasticsearch as a service.

Great explanation!