taosd 2.3 KB
Newer Older
H
hzcheng 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
#!/bin/bash 
#
# Modified from original source: Elastic Search
# https://github.com/elasticsearch/elasticsearch
# Thank you to the Elastic Search authors
#
# chkconfig: 2345 99 01
#
### BEGIN INIT INFO
# Provides:          TDEngine
# Required-Start:    $local_fs $network $syslog
# Required-Stop:     $local_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: Starts TDEngine taosd
# Description:       Starts TDEngine taosd, a time-series database engine
### END INIT INFO

set -e

PATH="/bin:/usr/bin:/sbin:/usr/sbin"
NAME="TDEngine"
USER="root"
GROUP="root"
H
huili 已提交
25
DAEMON="/usr/local/taos/bin/taosd"
H
hzcheng 已提交
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
DAEMON_OPTS=""
PID_FILE="/var/run/$NAME.pid"
APPARGS=""

# Maximum number of open files
MAX_OPEN_FILES=65535

. /lib/lsb/init-functions

case "$1" in
    start)

        log_action_begin_msg "Starting TDEngine..."
        if start-stop-daemon --test --start --chuid "$USER:$GROUP" --background --make-pidfile --pidfile "$PID_FILE" --exec "$DAEMON" -- $APPARGS &> /dev/null; then

            touch "$PID_FILE" && chown "$USER":"$GROUP" "$PID_FILE"

            if [ -n "$MAX_OPEN_FILES" ]; then
                ulimit -n $MAX_OPEN_FILES
            fi

            start-stop-daemon --start --chuid "$USER:$GROUP" --background --make-pidfile --pidfile "$PID_FILE" --exec "$DAEMON" -- $APPARGS

            log_end_msg $?
        fi
        ;;

    stop)
        log_action_begin_msg "Stopping TDEngine..."
        set +e
        if [ -f "$PID_FILE" ]; then
            start-stop-daemon --stop --pidfile "$PID_FILE" --user "$USER" --retry=TERM/120/KILL/5 > /dev/null
            if [ $? -eq 1 ]; then
                log_action_cont_msg "TSD is not running but pid file exists, cleaning up"
            elif [ $? -eq 3 ]; then
                PID="`cat $PID_FILE`"
                log_failure_msg "Failed to stop TDEngine (pid $PID)"
                exit 1
            fi
            rm -f "$PID_FILE"
        else
            log_action_cont_msg "TDEngine was not running"
        fi
        log_action_end_msg 0
        set -e
        ;;

    restart|force-reload)
        if [ -f "$PID_FILE" ]; then
            $0 stop
            sleep 1
        fi
        $0 start
        ;;
    status)
        status_of_proc -p "$PID_FILE" "$DAEMON" "$NAME"
        ;;
    *)
        exit 1
        ;;
esac

exit 0