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

  1.  
    #!/bin/sh
  2.  
    #chkconfig: 2345 80 05
  3.  
    #description: elasticsearch
  4.  
     
  5.  
    export JAVA_HOME=/usr/java/jdk1.8.0_112
  6.  
    export JAVA_BIN=/usr/java/jdk1.8.0_112/bin
  7.  
    export PATH=$PATH:$JAVA_HOME/bin
  8.  
    export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
  9.  
    export JAVA_HOME JAVA_BIN PATH CLASSPATH
  10.  
     
  11.  
    case "$1" in
  12.  
    start)
  13.  
    su lyt<<!
  14.  
    cd /home/lyt/dev-repo/elk5/elasticsearch-5.6.9
  15.  
    ./bin/elasticsearch -d
  16.  
    !
  17.  
    echo "elasticsearch startup"
  18.  
    ;;
  19.  
    stop)
  20.  
    es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
  21.  
    kill -9 $es_pid
  22.  
    echo "elasticsearch stopped"
  23.  
    ;;
  24.  
    restart)
  25.  
    es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'`
  26.  
    kill -9 $es_pid
  27.  
    echo "elasticsearch stopped"
  28.  
    su lyt<<!
  29.  
    cd /home/lyt/dev-repo/elk5/elasticsearch-5.6.9
  30.  
    ./bin/elasticsearch -d
  31.  
    !
  32.  
    echo "elasticsearch startup"
  33.  
    ;;
  34.  
    *)
  35.  
    echo "start|stop|restart"
  36.  
    ;;
  37.  
    esac
  38.  
     
  39.  
    exit $?

保存退出,赋予执行权限

chmod +x elasticsearch 

添加到开机启动任务

chkconfig -add elasticsearch

如果不设置开机启动的话,也可以使用service elasticsearch start/stop/restart来操作

原文:https://my.oschina.net/liuyuantao/blog/1798724

posted @ 2019-05-15 19:37  少时不知贵  阅读(1187)  评论(0编辑  收藏  举报