5
votes

I am trying to setup elasticsearch on my system.I installed it but it seems the process is not starting. I cant get response via curl. I read about some problem regarding pid owner not correctly setup, tried the steps but it still isnt working. If i put "set -x" in /etc/init.d/elasticsearch and try

/etc/init.d/elasticsearch restart

I get this output

root@sid-laptop:/etc/init.d# /etc/init.d/elasticsearch restart
+ id -u
+ [ 0 -ne 0 ]
+ . /lib/lsb/init-functions
+ run-parts --lsbsysinit --list /lib/lsb/init-functions.d
+ [ -r /lib/lsb/init-functions.d/01-upstart-lsb ]
+ . /lib/lsb/init-functions.d/01-upstart-lsb
+ unset UPSTART_SESSION
+ _RC_SCRIPT=/etc/init.d/elasticsearch
+ [ -r /etc/init//etc/init.d/elasticsearch.conf ]
+ _UPSTART_JOB=elasticsearch
+ [ -r /etc/init/elasticsearch.conf ]
+ [ -r /lib/lsb/init-functions.d/20-left-info-blocks ]
+ . /lib/lsb/init-functions.d/20-left-info-blocks
+ [ -r /lib/lsb/init-functions.d/40-systemd ]
+ . /lib/lsb/init-functions.d/40-systemd
+ _use_systemctl=0
+ [ -d /run/systemd/system ]
+ [ -n  ]
+ [ 6714 -ne 1 ]
+ [ -z  ]
+ [ -z  ]
+ readlink -f /etc/init.d/elasticsearch
+ _use_systemctl=1
+ prog=elasticsearch
+ service=elasticsearch.service
+ systemctl -p CanReload show elasticsearch.service
+ [ CanReload=no = CanReload=no ]
+ [ restart = reload ]
+ [ 1 = 1 ]
+ set +e
+ set +u
+ [ xrestart = xstart -o xrestart = xstop -o xrestart = xrestart -o xrestart = xreload -o xrestart = xforce-reload -o xrestart = xstatus ]
+ systemctl_redirect /etc/init.d/elasticsearch restart
+ local s
+ local rc
+ local prog=elasticsearch
+ local command=restart
+ s=Restarting elasticsearch (via systemctl)
+ service=elasticsearch.service
+ systemctl -p LoadState show elasticsearch.service
+ state=LoadState=loaded
+ [ LoadState=loaded = LoadState=masked ]
+ systemctl is-system-running
+ OUT=running
+ [ restart = status ]
+ log_daemon_msg Restarting elasticsearch (via systemctl) elasticsearch.service
+ [ -z Restarting elasticsearch (via systemctl) ]
+ log_daemon_msg_pre Restarting elasticsearch (via systemctl) elasticsearch.service
+ log_use_fancy_output
+ TPUT=/usr/bin/tput
+ EXPR=/usr/bin/expr
+ [ -t 1 ]
+ [ xxterm-256color != x ]
+ [ xxterm-256color != xdumb ]
+ [ -x /usr/bin/tput ]
+ [ -x /usr/bin/expr ]
+ /usr/bin/tput hpa 60
+ /usr/bin/tput setaf 1
+ [ -z ]
+ FANCYTTY=1
+ true
+ /bin/echo -n [....] 
[....] + [ -z elasticsearch.service ]
+ echo -n Restarting elasticsearch (via systemctl): elasticsearch.service
Restarting elasticsearch (via systemctl): elasticsearch.service+ log_daemon_msg_post Restarting elasticsearch (via systemctl) elasticsearch.service
+ :
+ /bin/systemctl restart elasticsearch.service
Warning: elasticsearch.service changed on disk. Run 'systemctl daemon-reload' to reload units.
+ rc=0
+ [ restart = status ]
+ log_end_msg 0
+ [ -z 0 ]
+ local retval
+ retval=0
+ log_end_msg_pre 0
+ log_use_fancy_output
+ TPUT=/usr/bin/tput
+ EXPR=/usr/bin/expr
+ [ -t 1 ]
+ [ xxterm-256color != x ]
+ [ xxterm-256color != xdumb ]
+ [ -x /usr/bin/tput ]
+ [ -x /usr/bin/expr ]
+ /usr/bin/tput hpa 60
+ /usr/bin/tput setaf 1
+ [ -z 1 ]
+ true
+ true
+ /usr/bin/tput setaf 1
+ RED=
+ /usr/bin/tput setaf 2
+ GREEN=
+ /usr/bin/tput setaf 3
+ YELLOW=
+ /usr/bin/tput op
+ NORMAL=
+ /usr/bin/tput civis
+ /usr/bin/tput sc
+ /usr/bin/tput hpa 0
+ [ 0 -eq 0 ]
+ /bin/echo -ne [ ok 
[ ok + /usr/bin/tput rc
+ /usr/bin/tput cnorm
+ log_use_fancy_output
+ TPUT=/usr/bin/tput
+ EXPR=/usr/bin/expr
+ [ -t 1 ]
+ [ xxterm-256color != x ]
+ [ xxterm-256color != xdumb ]
+ [ -x /usr/bin/tput ]
+ [ -x /usr/bin/expr ]
+ /usr/bin/tput hpa 60
+ /usr/bin/tput setaf 1
+ [ -z 1 ]
+ true
+ true
+ /usr/bin/tput setaf 1
+ RED=
+ /usr/bin/tput setaf 3
+ YELLOW=
+ /usr/bin/tput op
+ NORMAL=
+ [ 0 -eq 0 ]
+ echo .
.
+ log_end_msg_post 0
+ :
+ return 0
+ return 0
+ exit 0

Been trying whole day and still cant figure this out.
Also "ps -A" shows no elasticsearch process. Please help.

More info:
I tried

sudo -u elasticsearch /usr/share/elasticsearch/bin/elasticsearch -d -p /var/run/elasticsearch.pid --default.config=/etc/elasticsearch/elasticsearch.yml --default.path.home=/usr/share/elasticsearch --default.path.logs=/var/log/elasticsearch --default.path.data=/var/lib/elasticsearch --default.path.work=/tmp/elasticsearch --default.path.conf=/etc/elasticsearch
/
It gives:

    sid@sid-laptop:/etc/init.d$ sudo -u elasticsearch /usr/share/elasticsearch/bin/elasticsearch -d -p /var/run/elasticsearch.pid --default.config=/etc/elasticsearch/elasticsearch.yml --default.path.home=/usr/share/elasticsearch --default.path.logs=/var/log/elasticsearch --default.path.data=/var/lib/elasticsearch --default.path.work=/tmp/elasticsearch --default.path.conf=/etc/elasticsearch
    [sudo] password for sid: 
    sid@sid-laptop:/etc/init.d$ {1.6.2}: pid Failed ...
    - FileNotFoundException[/var/run/elasticsearch.pid (Permission denied)]
    java.io.FileNotFoundException: /var/run/elasticsearch.pid (Permission denied)
        at java.io.FileOutputStream.open0(Native Method)
        at java.io.FileOutputStream.open(FileOutputStream.java:270)
        at java.io.FileOutputStream.(FileOutputStream.java:213)
        at java.io.FileOutputStream.(FileOutputStream.java:162)
        at org.elasticsearch.bootstrap.Bootstrap.main(Bootstrap.java:194)
        at org.elasticsearch.bootstrap.Elasticsearch.main(Elasticsearch.java:32

1
Most likely permissions issue: trying to run with user elasticsearch after having run and crashed with other user. What shows sudo ls -la /var/run/elasticsearch.pid ? Also reload systemd sudo systemctl daemon-reload and please paste pure text (not the terminal output, since it cannot be read)Gonfva
Result of "ls: cannot access /var/run/elasticsearch.pid: No such file or directory ":"ls: cannot access /var/run/elasticsearch.pid: No such file or directory"Swapnil Devesh
i didnt understand what you meant by pure text?Swapnil Devesh
I meant the output to /etc/init.d/elasticsearch restartdidn´t look like a typical text output, but more like a problem with $TERMor pasting directly the full output, not the text output. Anyway, it isn´t relevant right now. OK. Could you please check if /var/run exists, is in fact a directory (not a symlink or a file) and that the user elasticsearch has permissions to write to that directory (Something like sudo -u elasticsearch ls -la /var/run sudo -u elasticsearch touch /var/run/testelasticsearch and afterwards sudo -u elasticsearch rm /var/run/testelasticsearchGonfva
var/run is symlink i think...it shows an arrow over folder icon of run...Swapnil Devesh

1 Answers

13
votes

Ubuntu don't allow other users than admins to write to /var/run and this happen for good reasons.

Has you can notice elasticsearch is launched by a "elasticsearch" user that elasticsearch creates on install:

sudo -u elasticsearch....

So instead of change /var/run permissions to all users or try to give admin permissions to elasticsearch user i believe the best solution is created a new folder inside /var/run folder

sudo mkdir /var/run/elasticsearch/

and give elasticsearch user permissions to it

sudo chown elasticsearch:elasticsearch /var/run/elasticsearch 

After you need to change elasticsearch init script to write the pid file for this new folder

sudo vim /etc/init.d/elasticsearch 

updating the property PID_FILE to

PID_FILE=/var/run/elasticsearch/$NAME.pid

This has worked for me. I hope it works for you to ;)