码迷,mamicode.com
首页 > 其他好文 > 详细

将服务变为系统服务

时间:2018-09-07 11:08:04      阅读:181      评论:0      收藏:0      [点我收藏+]

标签:rem   var   --   ast   code   sevice   tin   store   chkconfig   

[root@bd043 init.d]# cat elasticsearch
#!/bin/sh

# elasticsearch        Startup script for the elasticsearch
#
# chkconfig: 2345 80 05
# description: The elasticsearch will store data
# processname: elasticsearch
### BEGIN INIT INFO
# Provides:          elasticsearch
# Required-Start:    $all
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Start elasticsearch at boot time
### END INIT INFO

DESC="ES"
SEVICE_NAME=elasticsearch
PIDFILE=/var/run/$NAME.pid
RUN_AS=es
COMMAND="/home/es/es_for_cmdb/elasticsearch/bin/elasticsearch"

es_start() {
    if [ -e $PIDFILE ]
        then echo "$SEVICE_NAME is running..."
    else
        start-stop-daemon --start --quiet --background --make-pidfile --pidfile $PIDFILE --chuid $RUN_AS --exec $COMMAND
        echo  "Starting $DESC: $SEVICE_NAME"
    fi
}

es_stop() {
    start-stop-daemon --stop --quiet --pidfile $PIDFILE
    if [ -e $PIDFILE ]
        then rm $PIDFILE
    fi
}
es_status() {
    if [ -e $PIDFILE ]
        then echo "$SEVICE_NAME is running..."
    else
        echo "$SEVICE_NAME not run!"
    fi
}

case $1 in
    start)
    es_start
    echo "ok!"
    ;;
    stop)
    echo  "Stopping $DESC: $SEVICE_NAME"
    es_stop
    echo "ok!"
    ;;
    restart)
    echo  "Restarting $DESC: $SEVICE_NAME"
    es_stop
    sleep 1
    es_start
    echo "ok!"
    ;;
    status)
    es_status
    ;;
    *)
    echo "usage: /etc/init.d/$SEVICE_NAME {start|stop|status|restart}"
    exit 1
    ;;
esac

exit 0

 

将服务变为系统服务

标签:rem   var   --   ast   code   sevice   tin   store   chkconfig   

原文地址:https://www.cnblogs.com/wt11/p/9602473.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!