elasticsearch设置执行脚本并添加开机启动 (转)
elasticsearch设置执行脚本并添加开机启动
在/etc/init.d
目录下新建文件elasticsearch
#!/bin/sh
#chkconfig: 2345 80 05
#description: elasticsearch
export JAVA_HOME=/usr/java/jdk1.8.0_112
export JAVA_BIN=/usr/java/jdk1.8.0_112/bin
export PATH=$PATH:$JAVA_HOME/bin
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME JAVA_BIN PATH CLASSPATH
case "$1" in
start)
su lyt<<!
cd /home/lyt/dev-repo/elk5/elasticsearch-5.6.9
./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}'`
kill -9 $es_pid
echo "elasticsearch stopped"
su lyt<<!
cd /home/lyt/dev-repo/elk5/elasticsearch-5.6.9
./bin/elasticsearch -d
!
echo "elasticsearch startup"
;;
*)
echo "start|stop|restart"
;;
esac
exit $?
保存退出,赋予执行权限
chmod +x elasticsearch
添加到开机启动任务
chkconfig -add elasticsearch
如果不设置开机启动的话,也可以使用service elasticsearch start/stop/restart
来操作
在/etc/init.d
目录下新建文件elasticsearch
保存退出,赋予执行权限
chmod +x elasticsearch
添加到开机启动任务
chkconfig -add elasticsearch
如果不设置开机启动的话,也可以使用service elasticsearch start/stop/restart
来操作
原文:https://my.oschina.net/liuyuantao/blog/1798724