Search code examples
ubuntuelasticsearchjava-homesystemd

How to run Elasticsearch as a service on Ubuntu 15.04


I'm trying to setup Elasticsearch.

Everything's running fine on Ubuntu 14.10 but when I upgrade OS to Ubuntu 15.04, it always failed to start Elasticsearch as a service. (but I can still run it directly by command: sudo /usr/share/elasticsearch/bin/elasticsearch -Des.default.config=...)

The logs say that elasticsearch can't find any executable java binary.

systemd[1]: Starting Starts and stops a single elasticsearch instance on this system...
sudo[4906]: pam_unix(sudo:session): session closed for user root
elasticsearch[4912]: Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME...
systemd[1]: elasticsearch.service: main process exited, code=exited, status=1/FAILURE
systemd[1]: Unit elasticsearch.service entered failed state.
systemd[1]: elasticsearch.service failed.

I thought the environment variables might be different among users so I tried to add JAVA_HOME in /etc/environment and /etc/default/elasticsearch but it didn't work though.

So any ideas what might be the problem?


Solution

  • The difference most likely is that Ubuntu 15.04 uses systemd which runs services in a different context.

    Have a look at for example https://serverfault.com/questions/413397/how-to-set-environment-variable-in-systemd-service for how to set up environment variables for systemd. You should set them in an EnvironmentFile, see https://wiki.ubuntu.com/SystemdForUpstartUsers