摘要:#!/bin/bashsource ~/.bash_profileWORK_HOME=$(cd "$(dirname "$0")"; pwd)cd $WORK_HOMEumask 077script_name=`echo $0 | awk -F '/' '{p
#!/bin/bash
source ~/.bash_profile
WORK_HOME=$(cd "$(dirname "$0")"; pwd)
cd $WORK_HOME
umask 077
script_name=`echo $0 | awk -F '/' '{print $NF}'`
run {
$INSTALL_DIR/zookeeper/zookeeper/bin/zkServer.sh start-foreground
}
start {
$INSTALL_DIR/zookeeper/zookeeper/bin/zkServer.sh start
}
stop {
$INSTALL_DIR/zookeeper/zookeeper/bin/zkServer.sh stop
if [[ -n "$(ps aux | grep 'org.apache.zookeeper.server.quorum.QuorumPeerMain' | grep -v grep)" ]]; then
pkill -f 'org.apache.zookeeper.server.quorum.QuorumPeerMain'
sleep 3
fi
}
status {
pid=`ps -ef | grep 'QuorumPeerMain' | grep -vE "grep|$script_name" | awk '{print $2}'`
if [[ ! -z "$pid" ]]; then
stat=`$INSTALL_DIR/zookeeper/zookeeper/bin/zkServer.sh status 2>/dev/null | grep 'Mode' | awk '{print $2}' | sed 's/^ //g;s/ $//g'`
if [[ "$stat" = "leader" ]] || [[ "$stat" = "follower" ]] || [[ "$stat" = "standalone" ]]; then
echo "zookeeper service available!"
exit 0
else
echo "zookeeper service unavailable!"
exit 1
fi
else
echo "zookeeper not running!"
exit 3
fi
}
case "$1" in
'run')
run
;;
'start')
start
;;
'stop')
stop
;;
'restart')
stop
start
;;
'status')
status
;;
*)
echo "Usage: $0 {run|start|stop|restart|status|info}"
exit 1
esac
来源:小唐科技频道