What is wrong with the ones included in the deb/rpms?
On 26 February 2015 at 01:47, Peter Takac <[email protected]> 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 [email protected].
> 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 [email protected].
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.