cassandra自啓動服務器腳本

  1. 新建一個文件。
    1 vi /etc/rc.d/init.d/vi cassandra2
    #!/bin/sh
    # chkconfig: 2345 60 60
    # description: service for cassandra 2.1.x from arges 2016-06-22
    # processname: casandra2
    
    echo "welcome to use cassandra 2.1.x's service script from zxj"
    
    CASSANDRA_DIR="/opt/cassandra/apache-cassandra-2.1.14"
    
    case "$1" in
            start)
                    echo "starting cassandra******"
                    nohup -c "$CASSANDRA_DIR/bin/cassandra" >> $CASSANDRA_DIR/logs/system.log 2>&1 &
                    echo "cassandra started"
                    ;;
            stop)
                    echo "stopping cassandra******"
                    PID_COUNT=`ps aux |grep CassandraDaemon |grep -v grep | wc -l`
                    PID=`ps aux |grep CassandraDaemon |grep -v grep | awk {'print $2'}`
                    if [ $PID_COUNT -gt 0 ];then
                            echo "*********try stop cassandra***********"
                            kill -9 $PID
                            echo "*********kill cassandra SUCCESS!***********"
                    else
                            echo "*********there is no cassandra!***********"
                    fi
                    ;;
            restart)
                    echo "restarting cassandra******"
                    $0 stop
                    $0 start
                    ;;
        status)
            -c "$CASSANDRA_DIR/bin/nodetool status"
            ;;
        *)
            echo "Usage:$0 {start|stop|restart|status}"
            exit 1
    esac
  2. 設置服務自啓動
    1 chmod 755 /etc/rc.d/init.d/cassandra2
    2 chkconfig --add cassandra2
  3. 測試
    1 service cassandra2 start  //啓動
    2 service cassandra2 stop  //關閉
    3 service cassandra2 restart  //重啓

    這個腳本是從別人那裏借鑑過來,原來的重啓好像有點問題,改好以後應該沒問題了。node

相關文章
相關標籤/搜索