A new user interface for you! Read more...

File elasticsearch.init of Package elasticsearch

#!/bin/sh
# Init script for elasticsearch
# Created by Thomas Neuburger
# Implemented based on SLE11_3 /etc/init.d/skeleton file
#
### BEGIN INIT INFO
# Provides:          elasticsearch
# Required-Start:    $syslog $remote_fs
# Should-Start:      $time ypbind smtp
# Required-Stop:     $syslog $remote_fs
# Should-Stop:       ypbind smtp
# Default-Start:     3 5
# Default-Stop:      0 1 2 6
# Short-Description: Starts Elasticsearch as Daemon
# Description:       Starts Elasticsearch as Daemon. ElasticSearch is a distributed, RESTful, free/open source search server based on Apache Lucene.
### END INIT INFO

# Sets the default values for elasticsearch variables used in this script
ES_USER="elasticsearch"
ES_GROUP="elasticsearch"
ES_HOME="/usr/share/elasticsearch"
LOG_DIR="/var/log/elasticsearch"
DATA_DIR="/var/lib/elasticsearch"
CONF_DIR="/etc/elasticsearch"
PID_DIR="/var/run/elasticsearch"

# Check for missing binaries (stale symlinks should not happen)
# Note: Special treatment of stop for LSB conformance
ELASTICSEARCH_BIN=/usr/share/elasticsearch/bin/elasticsearch
test -x $ELASTICSEARCH_BIN || { echo "$ELASTICSEARCH_BIN not installed"; 
        if [ "$1" = "stop" ]; then exit 0;
        else exit 5; fi; }

# Check for existence of needed config file and read it
ELASTICSEARCH_CONFIG=/etc/sysconfig/elasticsearch
test -r $ELASTICSEARCH_CONFIG || { echo "$ELASTICSEARCH_CONFIG not existing";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }

# Read config        
. $ELASTICSEARCH_CONFIG

# Check for existence of needed environment script
ELASTICSEARCH_ENV=/usr/share/elasticsearch/bin/elasticsearch.env.sh
test -r $ELASTICSEARCH_ENV || { echo "$ELASTICSEARCH_ENV not existing";
        if [ "$1" = "stop" ]; then exit 0;
        else exit 6; fi; }

# Exec environment script	
$ELASTICSEARCH_ENV

name=elasticsearch
pidfile="$PID_DIR/$name.pid"

# Ensure that the PID_DIR exists (it is cleaned at OS startup time)
if [ -n "$PID_DIR" ] && [ ! -e "$PID_DIR" ]; then
    mkdir -p "$PID_DIR" && chown "$ES_USER":"$ES_GROUP" "$PID_DIR"
fi
if [ -n "$pidfile" ] && [ ! -e "$pidfile" ]; then
    touch "$pidfile" && chown "$ES_USER":"$ES_GROUP" "$pidfile"
fi

# Create PID file with correct rights
touch $pidfile
chown ${ES_USER}: $pidfile

# Shell functions sourced from /etc/rc.status:
#      rc_check         check and set local and overall rc status
#      rc_status        check and set local and overall rc status
#      rc_status -v     be verbose in local rc status and clear it afterwards
#      rc_status -v -r  ditto and clear both the local and overall rc status
#      rc_status -s     display "skipped" and exit with status 3
#      rc_status -u     display "unused" and exit with status 3
#      rc_failed        set local and overall rc status to failed
#      rc_failed <num>  set local and overall rc status to <num>
#      rc_reset         clear both the local and overall rc status
#      rc_exit          exit appropriate to overall rc status
#      rc_active        checks whether a service is activated by symlinks
. /etc/rc.status

# Reset status of this service
rc_reset

case "$1" in
    start)
        echo -n "Starting $name "
        if [ -s $pidfile -a -d /proc/$(<$pidfile) ]; then
                echo "pid $(<$pidfile) still running"
                rc_failed
        else
                > $pidfile
                #/bin/su -p -s /bin/bash $ES_USER $ELASTICSEARCH_BIN -p $pidfile -d -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.conf=$CONF_DIR &> $LOG_PATH/elasticsearch-init.log &
                /sbin/startproc -u $ES_USER -g $ES_GROUP $ELASTICSEARCH_BIN -p $pidfile -d -Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR -Des.default.path.data=$DATA_DIR -Des.default.path.conf=$CONF_DIR
        fi

        # Remember status and be verbose
        rc_status -v
        ;;
    stop)
        echo -n "Shutting down $name "
        pid=$(<$pidfile)
        rm $pidfile 2>/dev/null
        kill -TERM $pid 2>/dev/null

        # Remember status and be verbose
        rc_status -v
        ;;
    restart)
        ## Stop the service and regardless of whether it was
        ## running or not, start it again.
        $0 stop
        $0 start

        # Remember status and be quiet
        rc_status
        ;;
    reload)
        echo -n "Reload $name "
        ## service does not support reload:
        rc_failed 3
        rc_status -v
        ;;
    status)
        echo -n "Checking for $name "
        if ! [ -f $pidfile ]; then
                # not running
                rc_failed 3
        elif [ -s $pidfile -a -d /proc/$(<$pidfile) ]; then
                # running
                :
        else
                # stale pid file
                rc_failed 1
                #rm -f $pidfile
        fi
        rc_status -v
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart|reload}"
        exit 1
        ;;
esac
rc_exit