“Permission Denied” starting Elasticsearch-7.0

I'm getting a permission denied error for /etc/default/elasticsearch when starting Elasticsearch:

$ sudo systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: http://www.elastic.co
$ curl -s -O https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-7.0.1-amd64.deb && sudo dpkg -i --force-confnew elasticsearch-7.0.1-amd64.deb
(Reading database ... 124189 files and directories currently installed.)
Preparing to unpack elasticsearch-7.0.1-amd64.deb ...
Unpacking elasticsearch (7.0.1) over (5.5.0) ...
Setting up elasticsearch (7.0.1) ...
Installing new version of config file /etc/elasticsearch/elasticsearch.yml ...

Configuration file '/etc/elasticsearch/jvm.options'
 ==> Modified (by you or by a script) since installation.
 ==> Package distributor has shipped an updated version.
 ==> Using new file as you requested.
Installing new version of config file /etc/elasticsearch/jvm.options ...
Installing new version of config file /etc/elasticsearch/log4j2.properties ...
Installing new version of config file /etc/default/elasticsearch ...
Installing new version of config file /etc/init.d/elasticsearch ...
Created elasticsearch keystore in /etc/elasticsearch
Processing triggers for systemd (229-4ubuntu21.4) ...
Processing triggers for ureadahead (0.100.0-19) ...
$ sudo sed -i.old 's/-Xms1g/-Xms128m/' /etc/elasticsearch/jvm.options
$ sudo sed -i.old 's/-Xmx1g/-Xmx128m/' /etc/elasticsearch/jvm.options
$ cat <<-EOF | sudo tee -a /etc/elasticsearch/jvm.options
> -XX:+DisableExplicitGC
> -Djdk.io.permissionsUseCanonicalPath=true
> -Dlog4j.skipJansi=true
> -server
> EOF
-XX:+DisableExplicitGC
-Djdk.io.permissionsUseCanonicalPath=true
-Dlog4j.skipJansi=true
-server
$ sudo systemctl start elasticsearch
$ sudo systemctl status elasticsearch
● elasticsearch.service - Elasticsearch
   Loaded: loaded (/usr/lib/systemd/system/elasticsearch.service; disabled; vendor preset: enabled)
   Active: failed (Result: exit-code) since Thu 2019-05-02 10:23:59 UTC; 4s ago
     Docs: http://www.elastic.co
  Process: 3693 ExecStart=/usr/share/elasticsearch/bin/elasticsearch -p ${PID_DIR}/elasticsearch.pid --quiet (code=exited, status=1/FAILURE)
 Main PID: 3693 (code=exited, status=1/FAILURE)

May 02 10:23:59 travis-job-18530f44-821a-4a91-bc84-d996c0b09fe7 systemd[1]: Started Elasticsearch.
May 02 10:23:59 travis-job-18530f44-821a-4a91-bc84-d996c0b09fe7 elasticsearch[3693]: /usr/share/elasticsearch/bin/elasticsearch-env: line 73: /etc/default/elasticsearch: Permission denied
May 02 10:23:59 travis-job-18530f44-821a-4a91-bc84-d996c0b09fe7 systemd[1]: elasticsearch.service: Main process exited, code=exited, status=1/FAILURE
May 02 10:23:59 travis-job-18530f44-821a-4a91-bc84-d996c0b09fe7 systemd[1]: elasticsearch.service: Unit entered failed state.
May 02 10:23:59 travis-job-18530f44-821a-4a91-bc84-d996c0b09fe7 systemd[1]: elasticsearch.service: Failed with result 'exit-code'.
$ sudo cat /var/log/elasticsearch/elasticsearch.log
[2019-03-25T16:47:28,826][INFO ][o.e.n.Node               ] [HkYgs1K] stopping ...
[2019-03-25T16:47:28,904][INFO ][o.e.n.Node               ] [HkYgs1K] stopped
[2019-03-25T16:47:28,904][INFO ][o.e.n.Node               ] [HkYgs1K] closing ...
[2019-03-25T16:47:28,920][INFO ][o.e.n.Node               ] [HkYgs1K] closed

Environment: Ubuntu 16.04 Xenial (on Travis-CI, which is why I'm modifying the jvm.options - I'm trying to match the ones for the preinstalled Elasticsearch-5.5).

I've read similar threads on this forum but unfortunately didn't find anything to help me.

Can you do an ls -l on the directory and make sure it is owned by elasticsearch:elasticsearch?

1 Like

Thanks, John! Adding this before starting the service solved the problem:

sudo chown -R elasticsearch:elasticsearch /etc/default/elasticsearch
1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.