taosd 3.6 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 25 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 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145
#!/bin/bash
#
# taosd      This shell script takes care of starting and stopping TDEngine.
#
# chkconfig: 2345 99 01
# description: TDEngine is a districuted, scalable, high-performance Time Series Database
#              (TSDB). More than just a pure database, TDEngine also provides the ability
#              to do stream computing, aggregation etc.
#
#
### BEGIN INIT INFO
# Provides: taosd
# Required-Start: $network $local_fs $remote_fs
# Required-Stop: $network $local_fs $remote_fs
# Short-Description: start and stop taosd
# Description: TDEngine is a districuted, scalable, high-performance Time Series Database
#              (TSDB). More than just a pure database, TDEngine also provides the ability
#              to do stream computing, aggregation etc.
### END INIT INFO

# Source init functions
. /etc/init.d/functions

# Maximum number of open files
MAX_OPEN_FILES=65535

# Default program options
NAME=taosd
PROG=/usr/local/bin/taos/taosd
USER=root
GROUP=root

# Default directories
LOCK_DIR=/var/lock/subsys
PID_DIR=/var/run/$NAME

# Set file names
LOCK_FILE=$LOCK_DIR/$NAME
PID_FILE=$PID_DIR/$NAME.pid

[ -e $PID_DIR ] || mkdir -p $PID_DIR

PROG_OPTS=""

start() {
    echo -n "Starting ${NAME}: "
    # check identity
    curid="`id -u -n`"
    if [ "$curid" != root ] && [ "$curid" != "$USER" ] ; then
        echo "Must be run as root or $USER, but was run as $curid"
        return 1
    fi
    # Sets the maximum number of open file descriptors allowed.
    ulimit -n $MAX_OPEN_FILES
    curulimit="`ulimit -n`"
    if [ "$curulimit" -lt $MAX_OPEN_FILES ] ; then
        echo "'ulimit -n' must be greater than or equal to $MAX_OPEN_FILES, is $curulimit"
        return 1
    fi

    if [ "`id -u -n`" == root ] ; then
        # Changes the owner of the lock, and the pid files to allow
        # non-root OpenTSDB daemons to run /usr/share/opentsdb/bin/opentsdb_restart.py.
        touch $LOCK_FILE && chown $USER:$GROUP $LOCK_FILE
        touch $PID_FILE && chown $USER:$GROUP $PID_FILE
        daemon --user $USER --pidfile $PID_FILE "$PROG $PROG_OPTS &> /dev/null &"
    else
        # Don't have to change user.
        daemon --pidfile $PID_FILE "$PROG $PROG_OPTS &> /dev/null &"
    fi
    retval=$?
    sleep 2
    echo
    [ $retval -eq 0 ] && (findproc > $PID_FILE && touch $LOCK_FILE)
    return $retval
}

stop() {
    echo -n "Stopping ${NAME}: "
    killproc -p $PID_FILE $NAME
    retval=$?
    echo
    # Non-root users don't have enough permission to remove pid and lock files.
    # So, the opentsdb_restart.py cannot get rid of the files, and the command
    # "service opentsdb status" will complain about the existing pid file.
    # Makes the pid file empty.
    echo > $PID_FILE
    [ $retval -eq 0 ] && (rm -f $PID_FILE && rm -f $LOCK_FILE)
    return $retval
}

restart() {
    stop
    start
}

reload() {
    restart
}

force_reload() {
    restart
}

rh_status() {
    # run checks to determine if the service is running or use generic status
    status -p $PID_FILE -l $LOCK_FILE $NAME
}

rh_status_q() {
    rh_status >/dev/null 2>&1
}

case "$1" in
    start)
        rh_status_q && exit 0
        $1
        ;;
    stop)
        rh_status_q || exit 0
        $1
        ;;
    restart)
        $1
        ;;
    reload)
        rh_status_q || exit 7
        $1
        ;;
    force-reload)
        force_reload
        ;;
    status)
        rh_status
        ;;
    condrestart|try-restart)
        rh_status_q || exit 0
        restart
        ;;
    *)
        echo "Usage: $0 {start|stop|status|restart|condrestart|try-restart|reload|force-reload}"
        exit 2
esac

exit $?