Some install bugs - probably there is solution, not yet found by me

Hi,
I have tested instalation of elastic search on SLES 11SP3 x64 and also on
DEBIAN 7.8 x64.

But have some issues:
SLES 11SP3

  1. After installation ( from rpm or tgz ) the service/daemon is not created
    in correct folder, but in :
    /etc/init.d/init.d/
    instead of
    /etc/init.d/

  2. I have copied/moved from the wrong to the correct path, but still
    receive the error messages at execution of service with several parameters:
    .... start :
    Starting elasticsearch: /etc/init.d/elasticsearch: line 89: daemon: command
    not found

daemon --user $ES_USER --pidfile $pidfile $exec -p $pidfile -d
-Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR
-Des.default.path.data=$DATA_DIR -Des.default.path.work=$WORK_DIR
-Des.default.path.conf=$CONF_DIR

daemon --user elasticsearch --pidfile
/var/run/elasticsearch/elasticsearch.pid
/usr/share/elasticsearch/bin/elasticsearch -p
/var/run/elasticsearch/elasticsearch.pid -d
-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

.... status:
/etc/init.d/elasticsearch: line 121: status: command not found

status -p $pidfile $prog
status -p /var/run/elasticsearch/elasticsearch.pid elasticsearch

.... restart/force-reload:
Stopping elasticsearch: killproc: Usage:
killproc [-v] [-q] [-L] [-g|-G] [-N] [-p pid_file] [-i ingnore_file]
[-c root] [-t] [-SIG] /full/path/to/executable
killproc -l

Starting elasticsearch: /etc/init.d/elasticsearch: line 89: daemon: command
not found

killproc -p $pidfile -d 20 $prog
killproc -p /var/run/elasticsearch/elasticsearch.pid -d 20 elasticsearch

It looks like the compilation and service/daemon script is not correctly
configured.

daemon: is not declared in script, command does not exists in OS
status: is not declared in script, command does not exists in OS

what should be the right declaration of daemon and status?
for daemon I suppose that it should be the executable of application (
/usr/share/elasticsearch/bin/elasticsearch ) but I am not sure regarding
status

DEBIAN 7.8:
Currently I have found no issue. Need to check and walk thrue the scripts
and configurations

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/25a24045-67b3-4e5d-9253-89a0b5f833ba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

one fix:
2. ...start:
start_daemon -u $ES_USER -p $pidfile $exec -p $pidfile -d
-Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR
-Des.default.path.data=$DATA_DIR -Des.default.path.work=$WORK_DIR
-Des.default.path.conf=$CONF_DIR

start_daemon -u elasticsearch -p /var/run/elasticsearch/elasticsearch.pid
/usr/share/elasticsearch/bin/elasticsearch -p
/var/run/elasticsearch/elasticsearch.pid -d
-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

Do not forget to change owner and group on:
/var/run/elasticsearch
/var/log/elasticsearch
/var/lib/elasticsearch
/tmp/elasticsearch

chown -R elasticsearch /var/log/elasticsearch
chown -R elasticsearch /var/lib/elasticsearch
chown -R elasticsearch /tmp/elasticsearch
chgrp -R elasticsearch /var/lib/elasticsearch
chgrp -R elasticsearch /tmp/elasticsearch
chgrp -R elasticsearch /var/log/elasticsearch
chmod -R 755 /tmp/elasticsearch /var/log/elasticsearch
/var/lib/elasticsearch

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/317b103b-6921-4720-83ad-a864c637c6cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

one fix:
2. ...start:
start_daemon -u $ES_USER -p $pidfile $exec -p $pidfile -d
-Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR
-Des.default.path.data=$DATA_DIR -Des.default.path.work=$WORK_DIR
-Des.default.path.conf=$CONF_DIR

start_daemon -u elasticsearch -p /var/run/elasticsearch/
elasticsearch.pid /usr/share/elasticsearch/bin/elasticsearch -p
/var/run/elasticsearch/elasticsearch.pid -d
-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

Do not forget to change owner and group on:
/var/run/elasticsearch
/var/log/elasticsearch
/var/lib/elasticsearch
/tmp/elasticsearch

chown -R elasticsearch /var/log/elasticsearch
chown -R elasticsearch /var/lib/elasticsearch
chown -R elasticsearch /tmp/elasticsearch
chgrp -R elasticsearch /var/lib/elasticsearch
chgrp -R elasticsearch /tmp/elasticsearch
chgrp -R elasticsearch /var/log/elasticsearch
chmod -R 775 /tmp/elasticsearch /var/log/elasticsearch
/var/lib/elasticsearch

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/9edd8e18-7c6f-4999-a07a-635175a8be41%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

one fix:
2. ...start:
start_daemon -u $ES_USER -p $pidfile $exec -p $pidfile -d
-Des.default.path.home=$ES_HOME -Des.default.path.logs=$LOG_DIR
-Des.default.path.data=$DATA_DIR -Des.default.path.work=$WORK_DIR
-Des.default.path.conf=$CONF_DIR

start_daemon -u elasticsearch -p /var/run/elasticsearch/
elasticsearch.pid /usr/share/elasticsearch/bin/elasticsearch -p
/var/run/elasticsearch/elasticsearch.pid -d
-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

Do not forget to change owner and group on:
/var/run/elasticsearch
/var/log/elasticsearch
/var/lib/elasticsearch
/tmp/elasticsearch

chown -R elasticsearch /var/log/elasticsearch
chown -R elasticsearch /var/lib/elasticsearch
chown -R elasticsearch /tmp/elasticsearch
chgrp -R elasticsearch /var/lib/elasticsearch
chgrp -R elasticsearch /tmp/elasticsearch
chgrp -R elasticsearch /var/log/elasticsearch
chmod -R 775 /tmp/elasticsearch /var/log/elasticsearch
/var/lib/elasticsearch

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/8dc53345-cff5-4d6b-badc-4c5dd73f9fba%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

I have finaly recreated from scratch the whole startup script for SLES. so
in case that someone is interested, please let me known, I will send the
daemon script. After some tests and some approvals I will put it here also.

It is standard start stop with feature which chceck if the ES service is
running in the BG with the same CONF_DIR.
In case that it is running, it will not allow you to start the service and
provide som information regarding that process.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/2fa3f128-8177-41de-baeb-d4f4df4853c8%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi, bellow is service script, it has some small bugs but works fine for me:

#!/bin/sh

ElastiSearch daemon start/stop script.

Comments to support chkconfig on RedHat Linux

chkconfig: 2345 64 36

#title : elasticsearch
#description : This script is used such a damon/service start/stop script.
#author : Peter TAKAC / AssmodeuS
#date : 20150210
#version : 0.15
#usage : service elasticsearch
#notes : service start/stop script, also check the conf path. if
proces with the same path runs, it will not start it
#bash_version : 3.2.51(1)

BEGIN INIT INFO

Provides: ElasticSearch

Required-Start: $network $named

Required-Stop: $network $named

Should-Start: ypbind nscd ldap ntpd xntpd

Default-Start: 2 3 4 5

Default-Stop: 0 1 6

Short-Description: This service manages the ElasticSearch daemon

Description: Elasticsearch is a very scalable, schema-free and

high-performance search solution supporting multi-tenancy and near realtime
search.

END INIT INFO

Basic variables and settings

es_home="/SIP/elasticsearch/es-int-inst"
es_bindir="$es_home/bin"
es_exec="elasticsearch"
es_prog="$es_bindir/$es_exec"
es_pidpath="/var/run/elasticsearch"
es_pidfile="$es_pidpath/${es_exec}.pid"
es_lockdir="/var/lock/subsys"
es_lockfile="$es_lockdir/$es_exec"
es_user=elasticsearch
es_group=elasticsearch

Heap size defaults to 256m min, 1g max

Set ES_HEAP_SIZE to 50% of available RAM, but no more than 31g

#ES_HEAP_SIZE=2g

Heap new generation

#ES_HEAP_NEWSIZE=

max direct memory

#ES_DIRECT_SIZE=

Additional Java OPTS

#ES_JAVA_OPTS=

Maximum number of open files

MAX_OPEN_FILES=65535

Maximum amount of locked memory

#MAX_LOCKED_MEMORY=

#More application related settings

Elasticsearch log directory

es_logdir="$es_home/logs/$es_exec"

Elasticsearch data directory

es_datadir="/SIP/elasticsearch/es-int-data"

Elasticsearch work directory

es_workdir="$es_home/work"

Elasticsearch configuration directory

#es_confdir=/etc/$es_exec
es_confdir="$es_home/config"

Elasticsearch configuration file (elasticsearch.yml)

es_confile="$es_confdir/elasticsearch.yml"

Maximum number of VMA (Virtual Memory Areas) a process can own

MAX_MAP_COUNT=262144
es_daemon="$es_bindir/$es_exec"
es_daemon_opts="-d -p $es_pidfile -Des.default.path.home=$es_home
-Des.default.path.logs=$es_logdir -Des.default.path.data=$es_datadir
-Des.default.path.work=$es_workdir -Des.default.path.conf=$es_confdir"

PATH=$PATH:$es_home
export PATH
export JAVA_HOME
export ES_HEAP_SIZE
export ES_HEAP_NEWSIZE
export ES_DIRECT_SIZE
export ES_JAVA_OPTS

Default value, in seconds, after which the script should timeout waiting

for server start.

0 means do not wait at all

Negative numbers mean to wait indefinitely

service_startup_timeout=900

Use LSB init script functions for printing messages, if possible

lsb_functions="/lib/lsb/init-functions"
if test -f $lsb_functions ; then
. $lsb_functions
else
log_success_msg()
{
echo " SUCCESS! $@"
}
log_failure_msg()
{
echo " ERROR! $@"
}
fi

mode=$1 # start or stop

[ $# -ge 1 ] && shift

case echo "testing\c",echo -n testing in
c,-n*) echo_n= echo_c= ;;
c,*) echo_n=-n echo_c= ;;
*) echo_n= echo_c='\c' ;;
esac

wait_for_pid () {
verb="$1" # created | removed
pid="$2" # process ID of the program operating on
the pid-file
pid_file_path="$3" # path to the PID file.

i=0
avoid_race_condition="by checking again"

while test $i -ne $service_startup_timeout ; do

case "$verb" in
  'created')
    # wait for a PID-file to pop into existence.
    test -s "$pid_file_path" && i='' && break
  ;;
  'removed')
    # wait for this PID-file to disappear
    test ! -s "$pid_file_path" && i='' && break
  ;;
  *)
    echo "wait_for_pid () usage: wait_for_pid created|removed pid 

pid_file_path"
exit 1
;;
esac

# if server is not running, then pid-file will never be updated
if test -n "$pid"; then
  if kill -0 "$pid" 2>/dev/null; then
    :     # the server still runs
  else
    # The server may have exited between the last pid-file check and 

now.
if test -n "$avoid_race_condition"; then
avoid_race_condition=""
continue # Check again.
fi
# there is nothing that will affect the file.
log_failure_msg "The server quit without updating PID file
($pid_file_path)."
return 1 # not waiting any more.
fi
fi

echo $echo_n ".$echo_c"
i=`expr $i + 1`
sleep 1

done

if test -z "$i" ; then
log_success_msg
return 0
else
log_failure_msg
return 1
fi
}

Set pid file if not given

if test -z "$es_pidfile"
then
es_pidfile=$es_datadir/hostname.pid
else
case "$es_pidfile" in
/* ) ;;
* ) es_pidfile="$es_datadir/$es_pidfile" ;;
esac
fi

case "$mode" in
'start')
# Start daemon
# Safeguard (relative paths, core dumps..)
cd $es_home
echo $echo_n "Starting $es_exec:"
if test -x "$es_bindir/$es_exec" ; then
es_pidc=$(ps axwwo pid,cmd|grep -v grep|grep $es_confdir -c -w)
#echo "start_daemon -u $es_user -p $es_pidfile $es_daemon
$es_daemon_opts >/dev/null 2>&1 &"
if [[ $es_pidc -ge "1" ]]; then
es_pid=$(ps axwwo pid,cmd|grep -v grep|grep $es_confdir|cut -c1-5)
echo " ${stat}${warn}failed! ${norm}"
if test -s "$es_pidfile" ; then
read es_pidf < "$es_pidfile"
else
es_pidf="0"
fi
if [[ $es_pid -eq $es_pidf ]]; then
echo "${attn}Already running with the same config file! ${norm}"
else
echo "${attn}Already running with the same config file but PID
and PID-file does not match! ${norm}"
fi
echo "PID: "$es_pid
echo "For details please type: ps -Flj --pid=PID#ABOVE"
else
chown -R $es_user $es_pidpath
chgrp -R $es_group $es_pidpath
#$es_daemon $es_daemon_opts >/dev/null 2>&1 &
#startproc -u $es_user -p $es_pidfile $es_daemon $es_daemon_opts

/dev/null 2>&1 &
start_daemon -u $es_user -p $es_pidfile $es_daemon $es_daemon_opts
/dev/null 2>&1 &
wait_for_pid created "$!" "$es_pidfile"; return_value=$?
# Make lock for RedHat / SuSE
if test -w "$es_lockdir"
then
touch "$es_lockfile"
fi
#echo
#exit $return_value
fi
else
log_failure_msg "Could not find ElasticSearch ($es_bindir/$es_exec)"
fi
;;

'stop')
# Stop daemon. We use a signal here to avoid having to know the
# root password.

if test -s "$es_pidfile"
then
  es_pid=`cat "$es_pidfile"`
  if (kill -0 $es_pid 2>/dev/null)
  then
    echo $echo_n "Shutting down ElasticSearch"
    kill $es_pid
    # elasticsearch should remove the pid file when it exits, so wait 

for it.
wait_for_pid removed "$es_pid" "$es_pidfile"; return_value=$?
else
log_failure_msg "ElasticSearch process #$es_pid is not running!"
rm "$es_pidfile"
fi
# Delete lock for RedHat / SuSE
if test -f "$es_lockfile"
then
rm -f "$es_lockfile"
fi
exit $return_value
else
log_failure_msg "ElasticSearch PID file could not be found!"
fi
;;

'restart')
# Stop the service and regardless of whether it was
# running or not, start it again.
if $0 stop; then
$0 start
else
log_failure_msg "Failed to stop running server, so refusing to try to
start."
exit 1
fi
;;
'status')
# First, check to see if pid file exists
if test -s "$es_pidfile" ; then
read es_pid < "$es_pidfile"
if kill -0 $es_pid 2>/dev/null ; then
log_success_msg "ElasticSearch running ($es_pid)"
exit 0
else
log_failure_msg "ElasticSearch is not running, but PID file exists"
exit 1
fi
else
# Try to find appropriate ElasticSearch process
es_pid=pidof -o $$ -x $es_prog
# test if multiple pids exist
pid_count=echo $es_pid | wc -w
if test $pid_count -gt 1 ; then
log_failure_msg "Multiple ElasticSearch running but PID file could
not be found ($es_pid)"
exit 5
elif test -z $es_pid ; then
if test -f "$es_lockfile" ; then
log_failure_msg "ElasticSearch is not running, but lock file
($es_lockfile) exists"
exit 2
fi
log_failure_msg "ElasticSearch is not running"
exit 3
else
log_failure_msg "ElasticSearch is running but PID file could not be
found"
exit 4
fi
fi
;;
*)
# usage
es_basename=basename "$0"
echo "Usage: $es_basename {start|stop|restart|status} [
ElasticSearch options ]"
exit 1
;;
esac
echo
exit 0

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/6d3a5baa-4cee-4a84-97a2-69512e5452b2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hi, bellow is my service/daemon startup/shutdown script. It has some bugs,
but works fine for me.

#!/bin/sh

ElastiSearch daemon start/stop script.

Comments to support chkconfig on RedHat Linux

chkconfig: 2345 64 36

#title : elasticsearch
#description : This script is used such a damon/service start/stop script.
#author : Peter TAKAC / AssmodeuS
#date : 20150210
#version : 0.15
#usage : service elasticsearch
#notes : service start/stop script, also check the conf path. if
proces with the same path runs, it will not start it
#bash_version : 3.2.51(1)

BEGIN INIT INFO

Provides: ElasticSearch

Required-Start: $network $named

Required-Stop: $network $named

Should-Start: ypbind nscd ldap ntpd xntpd

Default-Start: 2 3 4 5

Default-Stop: 0 1 6

Short-Description: This service manages the ElasticSearch daemon

Description: Elasticsearch is a very scalable, schema-free and

high-performance search solution supporting multi-tenancy and near realtime
search.

END INIT INFO

Basic variables and settings

es_home="/elasticsearch/es-int-inst"
es_bindir="$es_home/bin"
es_exec="elasticsearch"
es_prog="$es_bindir/$es_exec"
es_pidpath="/var/run/elasticsearch"
es_pidfile="$es_pidpath/${es_exec}.pid"
es_lockdir="/var/lock/subsys"
es_lockfile="$es_lockdir/$es_exec"
es_user=elasticsearch
es_group=elasticsearch

Heap size defaults to 256m min, 1g max

Set ES_HEAP_SIZE to 50% of available RAM, but no more than 31g

#ES_HEAP_SIZE=2g

Heap new generation

#ES_HEAP_NEWSIZE=

max direct memory

#ES_DIRECT_SIZE=

Additional Java OPTS

#ES_JAVA_OPTS=

Maximum number of open files

MAX_OPEN_FILES=65535

Maximum amount of locked memory

#MAX_LOCKED_MEMORY=

#More application related settings

Elasticsearch log directory

es_logdir="$es_home/logs/$es_exec"

Elasticsearch data directory

es_datadir="/elasticsearch/es-int-data"

Elasticsearch work directory

es_workdir="$es_home/work"

Elasticsearch configuration directory

#es_confdir=/etc/$es_exec
es_confdir="$es_home/config"

Elasticsearch configuration file (elasticsearch.yml)

es_confile="$es_confdir/elasticsearch.yml"

Maximum number of VMA (Virtual Memory Areas) a process can own

MAX_MAP_COUNT=262144
es_daemon="$es_bindir/$es_exec"
es_daemon_opts="-d -p $es_pidfile -Des.default.path.home=$es_home
-Des.default.path.logs=$es_logdir -Des.default.path.data=$es_datadir
-Des.default.path.work=$es_workdir -Des.default.path.conf=$es_confdir"

PATH=$PATH:$es_home
export PATH
export JAVA_HOME
export ES_HEAP_SIZE
export ES_HEAP_NEWSIZE
export ES_DIRECT_SIZE
export ES_JAVA_OPTS

Default value, in seconds, after which the script should timeout waiting

for server start.

0 means do not wait at all

Negative numbers mean to wait indefinitely

service_startup_timeout=900

Use LSB init script functions for printing messages, if possible

lsb_functions="/lib/lsb/init-functions"
if test -f $lsb_functions ; then
. $lsb_functions
else
log_success_msg()
{
echo " SUCCESS! $@"
}
log_failure_msg()
{
echo " ERROR! $@"
}
fi

mode=$1 # start or stop

[ $# -ge 1 ] && shift

case echo "testing\c",echo -n testing in
c,-n*) echo_n= echo_c= ;;
c,*) echo_n=-n echo_c= ;;
*) echo_n= echo_c='\c' ;;
esac

wait_for_pid () {
verb="$1" # created | removed
pid="$2" # process ID of the program operating on
the pid-file
pid_file_path="$3" # path to the PID file.

i=0
avoid_race_condition="by checking again"

while test $i -ne $service_startup_timeout ; do

case "$verb" in
  'created')
    # wait for a PID-file to pop into existence.
    test -s "$pid_file_path" && i='' && break
  ;;
  'removed')
    # wait for this PID-file to disappear
    test ! -s "$pid_file_path" && i='' && break
  ;;
  *)
    echo "wait_for_pid () usage: wait_for_pid created|removed pid 

pid_file_path"
exit 1
;;
esac

# if server is not running, then pid-file will never be updated
if test -n "$pid"; then
  if kill -0 "$pid" 2>/dev/null; then
    :     # the server still runs
  else
    # The server may have exited between the last pid-file check and 

now.
if test -n "$avoid_race_condition"; then
avoid_race_condition=""
continue # Check again.
fi
# there is nothing that will affect the file.
log_failure_msg "The server quit without updating PID file
($pid_file_path)."
return 1 # not waiting any more.
fi
fi

echo $echo_n ".$echo_c"
i=`expr $i + 1`
sleep 1

done

if test -z "$i" ; then
log_success_msg
return 0
else
log_failure_msg
return 1
fi
}

Set pid file if not given

if test -z "$es_pidfile"
then
es_pidfile=$es_datadir/hostname.pid
else
case "$es_pidfile" in
/* ) ;;
* ) es_pidfile="$es_datadir/$es_pidfile" ;;
esac
fi

case "$mode" in
'start')
# Start daemon
# Safeguard (relative paths, core dumps..)
cd $es_home
echo $echo_n "Starting $es_exec:"
if test -x "$es_bindir/$es_exec" ; then
es_pidc=$(ps axwwo pid,cmd|grep -v grep|grep $es_confdir -c -w)
#echo "start_daemon -u $es_user -p $es_pidfile $es_daemon
$es_daemon_opts >/dev/null 2>&1 &"
if [[ $es_pidc -ge "1" ]]; then
es_pid=$(ps axwwo pid,cmd|grep -v grep|grep $es_confdir|cut -c1-5)
echo " ${stat}${warn}failed! ${norm}"
if test -s "$es_pidfile" ; then
read es_pidf < "$es_pidfile"
else
es_pidf="0"
fi
if [[ $es_pid -eq $es_pidf ]]; then
echo "${attn}Already running with the same config file! ${norm}"
else
echo "${attn}Already running with the same config file but PID
and PID-file does not match! ${norm}"
fi
echo "PID: "$es_pid
echo "For details please type: ps -Flj --pid=PID#ABOVE"
else
chown -R $es_user $es_pidpath
chgrp -R $es_group $es_pidpath
#$es_daemon $es_daemon_opts >/dev/null 2>&1 &
#startproc -u $es_user -p $es_pidfile $es_daemon $es_daemon_opts

/dev/null 2>&1 &
start_daemon -u $es_user -p $es_pidfile $es_daemon $es_daemon_opts
/dev/null 2>&1 &
wait_for_pid created "$!" "$es_pidfile"; return_value=$?
# Make lock for RedHat / SuSE
if test -w "$es_lockdir"
then
touch "$es_lockfile"
fi
#echo
#exit $return_value
fi
else
log_failure_msg "Could not find ElasticSearch ($es_bindir/$es_exec)"
fi
;;

'stop')
# Stop daemon. We use a signal here to avoid having to know the
# root password.

if test -s "$es_pidfile"
then
  es_pid=`cat "$es_pidfile"`
  if (kill -0 $es_pid 2>/dev/null)
  then
    echo $echo_n "Shutting down ElasticSearch"
    kill $es_pid
    # elasticsearch should remove the pid file when it exits, so wait 

for it.
wait_for_pid removed "$es_pid" "$es_pidfile"; return_value=$?
else
log_failure_msg "ElasticSearch process #$es_pid is not running!"
rm "$es_pidfile"
fi
# Delete lock for RedHat / SuSE
if test -f "$es_lockfile"
then
rm -f "$es_lockfile"
fi
exit $return_value
else
log_failure_msg "ElasticSearch PID file could not be found!"
fi
;;

'restart')
# Stop the service and regardless of whether it was
# running or not, start it again.
if $0 stop; then
$0 start
else
log_failure_msg "Failed to stop running server, so refusing to try to
start."
exit 1
fi
;;
'status')
# First, check to see if pid file exists
if test -s "$es_pidfile" ; then
read es_pid < "$es_pidfile"
if kill -0 $es_pid 2>/dev/null ; then
log_success_msg "ElasticSearch running ($es_pid)"
exit 0
else
log_failure_msg "ElasticSearch is not running, but PID file exists"
exit 1
fi
else
# Try to find appropriate ElasticSearch process
es_pid=pidof -o $$ -x $es_prog
# test if multiple pids exist
pid_count=echo $es_pid | wc -w
if test $pid_count -gt 1 ; then
log_failure_msg "Multiple ElasticSearch running but PID file could
not be found ($es_pid)"
exit 5
elif test -z $es_pid ; then
if test -f "$es_lockfile" ; then
log_failure_msg "ElasticSearch is not running, but lock file
($es_lockfile) exists"
exit 2
fi
log_failure_msg "ElasticSearch is not running"
exit 3
else
log_failure_msg "ElasticSearch is running but PID file could not be
found"
exit 4
fi
fi
;;
*)
# usage
es_basename=basename "$0"
echo "Usage: $es_basename {start|stop|restart|status} [
ElasticSearch options ]"
exit 1
;;
esac
echo
exit 0

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/bc5fc589-15de-4863-b64e-2c0960ae8744%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

What is wrong with the ones included in the deb/rpms?

On 26 February 2015 at 01:47, Peter Takac assmodeus81sk@gmail.com wrote:

Hi, bellow is service script, it has some small bugs but works fine for me:

#!/bin/sh

ElastiSearch daemon start/stop script.

Comments to support chkconfig on RedHat Linux

chkconfig: 2345 64 36

#title : elasticsearch
#description : This script is used such a damon/service start/stop
script.
#author : Peter TAKAC / AssmodeuS
#date : 20150210
#version : 0.15
#usage : service elasticsearch
#notes : service start/stop script, also check the conf path. if
proces with the same path runs, it will not start it
#bash_version : 3.2.51(1)

BEGIN INIT INFO

Provides: ElasticSearch

Required-Start: $network $named

Required-Stop: $network $named

Should-Start: ypbind nscd ldap ntpd xntpd

Default-Start: 2 3 4 5

Default-Stop: 0 1 6

Short-Description: This service manages the ElasticSearch daemon

Description: Elasticsearch is a very scalable, schema-free and

high-performance search solution supporting multi-tenancy and near realtime
search.

END INIT INFO

Basic variables and settings

es_home="/SIP/elasticsearch/es-int-inst"
es_bindir="$es_home/bin"
es_exec="elasticsearch"
es_prog="$es_bindir/$es_exec"
es_pidpath="/var/run/elasticsearch"
es_pidfile="$es_pidpath/${es_exec}.pid"
es_lockdir="/var/lock/subsys"
es_lockfile="$es_lockdir/$es_exec"
es_user=elasticsearch
es_group=elasticsearch

Heap size defaults to 256m min, 1g max

Set ES_HEAP_SIZE to 50% of available RAM, but no more than 31g

#ES_HEAP_SIZE=2g

Heap new generation

#ES_HEAP_NEWSIZE=

max direct memory

#ES_DIRECT_SIZE=

Additional Java OPTS

#ES_JAVA_OPTS=

Maximum number of open files

MAX_OPEN_FILES=65535

Maximum amount of locked memory

#MAX_LOCKED_MEMORY=

#More application related settings

Elasticsearch log directory

es_logdir="$es_home/logs/$es_exec"

Elasticsearch data directory

es_datadir="/SIP/elasticsearch/es-int-data"

Elasticsearch work directory

es_workdir="$es_home/work"

Elasticsearch configuration directory

#es_confdir=/etc/$es_exec
es_confdir="$es_home/config"

Elasticsearch configuration file (elasticsearch.yml)

es_confile="$es_confdir/elasticsearch.yml"

Maximum number of VMA (Virtual Memory Areas) a process can own

MAX_MAP_COUNT=262144
es_daemon="$es_bindir/$es_exec"
es_daemon_opts="-d -p $es_pidfile -Des.default.path.home=$es_home
-Des.default.path.logs=$es_logdir -Des.default.path.data=$es_datadir
-Des.default.path.work=$es_workdir -Des.default.path.conf=$es_confdir"

PATH=$PATH:$es_home
export PATH
export JAVA_HOME
export ES_HEAP_SIZE
export ES_HEAP_NEWSIZE
export ES_DIRECT_SIZE
export ES_JAVA_OPTS

Default value, in seconds, after which the script should timeout waiting

for server start.

0 means do not wait at all

Negative numbers mean to wait indefinitely

service_startup_timeout=900

Use LSB init script functions for printing messages, if possible

lsb_functions="/lib/lsb/init-functions"
if test -f $lsb_functions ; then
. $lsb_functions
else
log_success_msg()
{
echo " SUCCESS! $@"
}
log_failure_msg()
{
echo " ERROR! $@"
}
fi

mode=$1 # start or stop

[ $# -ge 1 ] && shift

case echo "testing\c",echo -n testing in
c,-n*) echo_n= echo_c= ;;
c,*) echo_n=-n echo_c= ;;
*) echo_n= echo_c='\c' ;;
esac

wait_for_pid () {
verb="$1" # created | removed
pid="$2" # process ID of the program operating
on the pid-file
pid_file_path="$3" # path to the PID file.

i=0
avoid_race_condition="by checking again"

while test $i -ne $service_startup_timeout ; do

case "$verb" in
  'created')
    # wait for a PID-file to pop into existence.
    test -s "$pid_file_path" && i='' && break
  ;;
  'removed')
    # wait for this PID-file to disappear
    test ! -s "$pid_file_path" && i='' && break
  ;;
  *)
    echo "wait_for_pid () usage: wait_for_pid created|removed pid

pid_file_path"
exit 1
;;
esac

# if server is not running, then pid-file will never be updated
if test -n "$pid"; then
  if kill -0 "$pid" 2>/dev/null; then
    :     # the server still runs
  else
    # The server may have exited between the last pid-file check and

now.
if test -n "$avoid_race_condition"; then
avoid_race_condition=""
continue # Check again.
fi
# there is nothing that will affect the file.
log_failure_msg "The server quit without updating PID file
($pid_file_path)."
return 1 # not waiting any more.
fi
fi

echo $echo_n ".$echo_c"
i=`expr $i + 1`
sleep 1

done

if test -z "$i" ; then
log_success_msg
return 0
else
log_failure_msg
return 1
fi
}

Set pid file if not given

if test -z "$es_pidfile"
then
es_pidfile=$es_datadir/hostname.pid
else
case "$es_pidfile" in
/* ) ;;
* ) es_pidfile="$es_datadir/$es_pidfile" ;;
esac
fi

case "$mode" in
'start')
# Start daemon
# Safeguard (relative paths, core dumps..)
cd $es_home
echo $echo_n "Starting $es_exec:"
if test -x "$es_bindir/$es_exec" ; then
es_pidc=$(ps axwwo pid,cmd|grep -v grep|grep $es_confdir -c -w)
#echo "start_daemon -u $es_user -p $es_pidfile $es_daemon
$es_daemon_opts >/dev/null 2>&1 &"
if [[ $es_pidc -ge "1" ]]; then
es_pid=$(ps axwwo pid,cmd|grep -v grep|grep $es_confdir|cut -c1-5)
echo " ${stat}${warn}failed! ${norm}"
if test -s "$es_pidfile" ; then
read es_pidf < "$es_pidfile"
else
es_pidf="0"
fi
if [[ $es_pid -eq $es_pidf ]]; then
echo "${attn}Already running with the same config file! ${norm}"
else
echo "${attn}Already running with the same config file but PID
and PID-file does not match! ${norm}"
fi
echo "PID: "$es_pid
echo "For details please type: ps -Flj --pid=PID#ABOVE"
else
chown -R $es_user $es_pidpath
chgrp -R $es_group $es_pidpath
#$es_daemon $es_daemon_opts >/dev/null 2>&1 &
#startproc -u $es_user -p $es_pidfile $es_daemon $es_daemon_opts

/dev/null 2>&1 &
start_daemon -u $es_user -p $es_pidfile $es_daemon $es_daemon_opts
/dev/null 2>&1 &
wait_for_pid created "$!" "$es_pidfile"; return_value=$?
# Make lock for RedHat / SuSE
if test -w "$es_lockdir"
then
touch "$es_lockfile"
fi
#echo
#exit $return_value
fi
else
log_failure_msg "Could not find ElasticSearch ($es_bindir/$es_exec)"
fi
;;

'stop')
# Stop daemon. We use a signal here to avoid having to know the
# root password.

if test -s "$es_pidfile"
then
  es_pid=`cat "$es_pidfile"`
  if (kill -0 $es_pid 2>/dev/null)
  then
    echo $echo_n "Shutting down ElasticSearch"
    kill $es_pid
    # elasticsearch should remove the pid file when it exits, so wait

for it.
wait_for_pid removed "$es_pid" "$es_pidfile"; return_value=$?
else
log_failure_msg "ElasticSearch process #$es_pid is not running!"
rm "$es_pidfile"
fi
# Delete lock for RedHat / SuSE
if test -f "$es_lockfile"
then
rm -f "$es_lockfile"
fi
exit $return_value
else
log_failure_msg "ElasticSearch PID file could not be found!"
fi
;;

'restart')
# Stop the service and regardless of whether it was
# running or not, start it again.
if $0 stop; then
$0 start
else
log_failure_msg "Failed to stop running server, so refusing to try
to start."
exit 1
fi
;;
'status')
# First, check to see if pid file exists
if test -s "$es_pidfile" ; then
read es_pid < "$es_pidfile"
if kill -0 $es_pid 2>/dev/null ; then
log_success_msg "ElasticSearch running ($es_pid)"
exit 0
else
log_failure_msg "ElasticSearch is not running, but PID file exists"
exit 1
fi
else
# Try to find appropriate ElasticSearch process
es_pid=pidof -o $$ -x $es_prog
# test if multiple pids exist
pid_count=echo $es_pid | wc -w
if test $pid_count -gt 1 ; then
log_failure_msg "Multiple ElasticSearch running but PID file could
not be found ($es_pid)"
exit 5
elif test -z $es_pid ; then
if test -f "$es_lockfile" ; then
log_failure_msg "ElasticSearch is not running, but lock file
($es_lockfile) exists"
exit 2
fi
log_failure_msg "ElasticSearch is not running"
exit 3
else
log_failure_msg "ElasticSearch is running but PID file could not
be found"
exit 4
fi
fi
;;
*)
# usage
es_basename=basename "$0"
echo "Usage: $es_basename {start|stop|restart|status} [
ElasticSearch options ]"
exit 1
;;
esac
echo
exit 0

--
You received this message because you are subscribed to the Google Groups
"elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit
https://groups.google.com/d/msgid/elasticsearch/6d3a5baa-4cee-4a84-97a2-69512e5452b2%40googlegroups.com
https://groups.google.com/d/msgid/elasticsearch/6d3a5baa-4cee-4a84-97a2-69512e5452b2%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/CAEYi1X9Gg05MR2wsammSzvJ%2BM95ChKeNKC7geeb-z9RdLgZAHw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.