Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a problem with an init.d script



PID=$(ps ax | grep elasticsearch | grep $ES_HOME | grep -v grep | awk '{print $1}')

#echo $PID
#exit 0
case "$1" in
        if [ -z "$PID" ]; then
            echo "Starting Elasticsearch"
            echo "Starting Elasticsearch" >> /var/tmp/elasticsearch
            su -m elasticsearch -c "${ES_HOME}/bin/elasticsearch"
            exit 0;
            echo "Elasticsearch already running"
            echo "Elasticsearch already running" >> /var/tmp/elasticsearch
            exit 0;
        if [ -n "$PID" ]; then
            echo "Stopping Elasticsearch"
            kill ${PID}
            echo "Stopped Elasticsearch"
            exit 0;
            echo "Elasticsearch is not running"
            exit 0;

The scripts runs just file, as I can see in /var/tmp/elasticsearch a new line is added after every boot, but if I run:

/etc/init.d/elasticsearch stop

Just after the server is booted, I get "Elasticsearch is not running", ergo somehow the process does not stay alive. My question is why? and what am I doing wrong?

Thanks in advance.

share|improve this question
If you execute the script manually with start parameter, will it work? Can you see the process running in process list? –  Khaled Apr 3 '12 at 7:04
Why are you not following the install instructions for this program? elasticsearch.org/tutorials/2010/07/01/… I think that would help enormously rather than rolling your own script. –  webtoe Apr 3 '12 at 9:55

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.