https://www.cnblogs.com/two-bees/p/10801787.html
[root@localhost ~]# cat /etc/init.d/elasticsearch
#!/bin/sh
#chkconfig: 2345 80 05 #description: elasticsearch
export JAVA_HOME=/media/www/elasticsearch/jdk1.8.0_121
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
case "$1" in
start)
cd /media/www/elasticsearch/elasticsearch-2.3.3
./bin/elasticsearch -d
echo "elasticsearch startup";;
stop)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
kill -9 $es_pid
echo "elasticsearch stopped";;
restart)
es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
#echo $es_pid
for i in $es_pid
do
let j=j+1
#echo $j
#echo $i
if [ $j -eq 1 ] ;then
echo "ok";
kill -9 $i
fi
done
echo "elasticsearch stopped";
cd /media/www/elasticsearch/elasticsearch-2.3.3 && ./bin/elasticsearch -d
echo "elasticsearch startup";;
*)
echo "start|stop|restart";;
esac
exit $?
$sudo chmod +x /etc/init.d/elasticsearch
$sudo systemctl enable elasticsearch