美文网首页
Elasticsearch开机启动脚本

Elasticsearch开机启动脚本

作者: Carlyle1993 | 来源:发表于2018-02-07 18:16 被阅读0次

/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 xingdu<<!
    cd /home/elasticsearch
    ./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 xingdu<<!
    cd /home/elasticsearch
    ./bin/elasticsearch -d
!
    echo "elasticsearch startup"
    ;;  
*)
    echo "start|stop|restart"
    ;;  
esac

exit $?

保存退出,赋予执行权限

chmod +x elasticsearch 

添加到开机启动任务

chkconfig -add elasticsearch

使用service elasticsearch start/stop/restart来操作

相关文章

网友评论

      本文标题:Elasticsearch开机启动脚本

      本文链接:https://www.haomeiwen.com/subject/coyazxtx.html