taosd 2.5 KB
Newer Older
1
#!/bin/bash
H
hzcheng 已提交
2 3 4 5 6 7 8 9
#
# 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
10
# Provides:          TDengine
H
hzcheng 已提交
11 12 13 14
# Required-Start:    $local_fs $network $syslog
# Required-Stop:     $local_fs $network $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
15 16
# Short-Description: Starts TDengine taosd
# Description:       Starts TDengine taosd, a time-series database engine
H
hzcheng 已提交
17 18 19 20 21
### END INIT INFO

set -e

PATH="/bin:/usr/bin:/sbin:/usr/sbin"
22
NAME="TDengine"
H
hzcheng 已提交
23 24
USER="root"
GROUP="root"
H
huili 已提交
25
DAEMON="/usr/local/taos/bin/taosd"
H
hzcheng 已提交
26
DAEMON_OPTS=""
27

28
HTTPD_NAME="taosadapter"
29 30 31
DAEMON_HTTPD_NAME=$HTTPD_NAME
DAEMON_HTTPD="/usr/local/taos/bin/$HTTPD_NAME"

H
hzcheng 已提交
32 33 34 35 36 37 38 39 40 41 42
PID_FILE="/var/run/$NAME.pid"
APPARGS=""

# Maximum number of open files
MAX_OPEN_FILES=65535

. /lib/lsb/init-functions

case "$1" in
    start)

43
        log_action_begin_msg "Starting TDengine..."
44
        $DAEMON_HTTPD &
H
hzcheng 已提交
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
        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)
60
        log_action_begin_msg "Stopping TDengine..."
61
        pkill -9 $DAEMON_HTTPD_NAME
H
hzcheng 已提交
62 63 64 65 66 67 68
        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`"
69
                log_failure_msg "Failed to stop TDengine (pid $PID)"
H
hzcheng 已提交
70 71 72 73
                exit 1
            fi
            rm -f "$PID_FILE"
        else
74
            log_action_cont_msg "TDengine was not running"
H
hzcheng 已提交
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
        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