Can not start elasticsearch as a service in ubuntu 16.04

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


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.


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/*