es服务

#!/bin/bash

#chkconfig:2345 20 90

#description: elastic service

#processname: elastic

ROOT_PATH=/es5/install

case "$1" in

start)

su es5 -c "nohup /es5/esinstall/elasticsearch-5.4.0/bin/elasticsearch >> /dev/null &"

;;

stop)

psid=0

checkpid(){

javaps=`jps -l | grep elasticsearch`

if [ -n "$javaps"]; then

psid=`echo $javaps |awk '{print $1}'`

else

psid=0

fi}

checkpid

if [ $psid -ne 0]; then

  echo -n "Stopping elasticsearch   (pid=$psid)"

  kill -9 psid

  if[ $? -eq 0 ];then

    echo "[OK]"

  else

    echo "Failed"

  fi

  checkpid

  if [ $psid -ne 0 ]; then

  kill -9 $psid

  fi

else

echo"elasticsearch is not running"

fi

;;

*)

echo '参数错误'

echo 'service esserver start|stop'

;;

esac

exit 0

}

原文地址:https://www.cnblogs.com/nicebaby/p/8066607.html