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  //重启

    这个脚本是从别人那里借鉴过来,原来的重启好像有点问题,改好之后应该没问题了。

posted @ 2016-11-14 20:11  一碗豆浆  阅读(2185)  评论(0编辑  收藏  举报