Can not start elasticsearch as a service in ubuntu 16.04
Asked Answered
F

6

19

I have recently upgraded my machine from Ubuntu 14.04 to 16.04. I am facing problem of using the elasticsearch as a service. I installed elasticsearch using:

sudo apt-get install elasticsearch

Now sudo service elasticsearch status command shows me this result:

elasticsearch.service - LSB: Starts elasticsearch
   Loaded: loaded (/etc/init.d/elasticsearch; bad; vendor preset: enabled)
   Active: active (exited) since Sat 2016-07-30 18:28:13 BDT; 1h 19min ago
     Docs: man:systemd-sysv-generator(8)
 Main PID: 7988 (code=exited, status=1/FAILURE)
   CGroup: /system.slice/elasticsearch.service

Jul 30 18:28:13 dimik elasticsearch[10266]: [warning] /etc/init.d/elasticsearch: No java runtime was found
Jul 30 18:28:13 dimik systemd[1]: Started LSB: Starts elasticsearch.
Jul 30 18:28:46 dimik systemd[1]: Started LSB: Starts elasticsearch.
Jul 30 18:35:30 dimik systemd[1]: Started LSB: Starts elasticsearch.
Jul 30 19:04:36 dimik systemd[1]: Started A search engine.
Jul 30 19:07:48 dimik systemd[1]: Started A search engine.
Jul 30 19:27:01 dimik systemd[1]: Started A search engine.
Jul 30 19:27:51 dimik systemd[1]: Started A search engine.
Jul 30 19:28:54 dimik systemd[1]: Started A search engine.
Jul 30 19:29:18 dimik systemd[1]: Started LSB: Starts elasticsearch.

Although Java is installed in my machine and I can start the server using this command.

sudo /usr/share/elasticsearch/bin/elasticsearch

I am kind of stuck here. Any help will be appreciated.

Edit

After setting up JAVA_HOME for root the error:

elasticsearch.service - LSB: Starts elasticsearch
   Loaded: loaded (/etc/init.d/elasticsearch; bad; vendor preset: enabled)
   Active: active (exited) since Sat 2016-07-30 18:28:13 BDT; 3h 32min ago
     Docs: man:systemd-sysv-generator(8)
 Main PID: 7988 (code=exited, status=1/FAILURE)
   CGroup: /system.slice/elasticsearch.service

Jul 30 18:35:30 dimik systemd[1]: Started LSB: Starts elasticsearch.
Jul 30 19:04:36 dimik systemd[1]: Started A search engine.
Jul 30 19:07:48 dimik systemd[1]: Started A search engine.
Jul 30 19:27:01 dimik systemd[1]: Started A search engine.
Jul 30 19:27:51 dimik systemd[1]: Started A search engine.
Jul 30 19:28:54 dimik systemd[1]: Started A search engine.
Jul 30 19:29:18 dimik systemd[1]: Started LSB: Starts elasticsearch.
Jul 30 20:02:07 dimik systemd[1]: Started LSB: Starts elasticsearch.
Jul 30 20:20:21 dimik systemd[1]: Started LSB: Starts elasticsearch.
Jul 30 21:59:21 dimik systemd[1]: Started LSB: Starts elasticsearch.
Fulcrum answered 30/7, 2016 at 13:55 Comment(5)
Lokks like the javapath is not set for rootChandelle
Java path is set as I can see. echo $JAVA_HOME yields the pathFulcrum
Also if you do sudo echo $JAVA_HOME?Chandelle
No. not for root. I shall check this. Thank you for the hint.Fulcrum
Still it doesn't start. I am editing my question to show the output after start commandFulcrum
F
40

I found the solution for this issue. The solution comes from this discussion thread- Can’t start elasticsearch with Ubuntu 16.04 on elastic's website.

It seems that to get Elasticsearch to run on 16.04 you have to set START_DAEMON to true on /etc/default/elasticsearch. It comes commented out by default, and uncommenting it makes Elasticsearch start again just fine.

Be sure to use systemctl restart instead of just start because the service is started right after installation, and apparently there's some socket/pidfile/something that systemd keeps that must be released before being able to start the service again.

Fulcrum answered 30/7, 2016 at 16:23 Comment(3)
Doesn't work for us. We can run it manually with /usr/share/elasticsearch/bin/elasticsearch, though. Hm.Eleanor
Something's just broken about the Ubuntu package. Even with enabling the daemon and setting up permissions, it doesn't start through systemd. You have to go to elastic.co to get working packages. No log file, and an empty pid file, and no journalctl output, makes it very hard to debug.Tereus
Tried uncommenting the START_DAEMON line, still does not start up after making the change. Manually running it works fine, however, using systemctl it does not start, no logs, no process running, etc.Arty
C
9

The problem lies on log files, "No java runtime was found."

Jul 30 18:28:13 dimik elasticsearch[10266]: [warning] /etc/init.d/elasticsearch: No java runtime was found

Here's my solution to the problem.

  1. Check elasticsearch init file

    sudo nano /etc/init.d/elasticsearch

search for

. /usr/share/java-wrappers/java-wrappers.sh
find_java_runtime openjdk8 oracle8 openjdk7 oracle7 openjdk6 sun6 default
export JAVA_HOME
  1. Check java-wrappers.sh file

    sudo nano /usr/share/java-wrappers/java-wrappers.sh

Now you could see the warning comes from

#Displays a warning
java_warning() {
    echo "[warning] $0: $@" >&2;
}
  1. Somehow, java directories are not listed in jvm-list.sh files

Now edit the jvm-list.sh file

sudo nano /usr/lib/java-wrappers/jvm-list.sh

Edit the line add your java directories files, in my case add /usr/lib/jvm/java-8-oracle*

__jvm_oracle8="/usr/lib/jvm/jdk-8-oracle-* /usr/lib/jvm/jre-8-oracle-* /usr/lib/jvm/java-8-oracle*"
  1. Now restart the service and check elasticsearch services

    sudo systemctl restart elasticsearch
    sudo systemctl elasticsearch status
    curl -X GET "http://localhost:9200"

Hopes this would help

Consignee answered 15/10, 2017 at 11:1 Comment(2)
This helped. I'm not sure why /usr/lib/jvm/java-8-oracle wasn't in my jvm-list.sh file either, but that's what caused my issues.Knickerbocker
Thanks, that helpedLactiferous
S
4

My problem was different, I started elasticsearch manually as root user, so some files were created with wrong ownership, so elasticsearch user cannot write on them.

You can try to start elasticsearch from console to see errors:

sudo -u elasticsearch /usr/share/elasticsearch/bin/elasticsearch \
 -Des.default.config=/etc/elasticsearch/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=/etc/elasticsearch

To fix on my machine I had to do:

rm -rf /var/log/elasticsearch/*
rm -rf /var/lib/elasticsearch/*
Sagesagebrush answered 14/2, 2018 at 9:11 Comment(3)
Extremely helpful. Thanks! This should really be a part of the set-up, even when there isn't a problem, if only to verify something in the configs wasn't mistyped.Oospore
This worked for me. Took me hours to discover one little file. Thanks.Canvas
this helped me a lotWorsham
G
2
  1. Open /etc/init.d/elasticsearch file in editor, Comment below lines

    . /usr/share/java-wrappers/java-wrappers.sh
    find_java_runtime openjdk8 oracle8 openjdk7 oracle7 openjdk6 sun6 default
    

    Set JAVA_HOME manually like so:

    export JAVA_HOME="/usr"
    
  2. service elasticsearch start

Gavrah answered 21/3, 2017 at 7:35 Comment(3)
Besides bulletpoint instructions, you should also elaborate how that is going to help solve the problem.Bureau
I've already posted a solution. Your answer does not elaborate that or give a better alternative.Fulcrum
Nah. See avalla's answer, below. the init.d script can and should be able to find any of the normally-installed jvm's.Oospore
J
0

Remove unnecessary java packages using

sudo apt autoremove

Then install elasticsearch again and start it as

sudo apt install elasticsearch
service elasticsearch status
Jessalyn answered 27/7, 2022 at 11:0 Comment(0)
O
0

Have you enabled the service ?

systemctl enable elasticsearch

Osculation answered 17/1, 2023 at 8:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.