Preparing hbase release 2.4.2RC0; tagging and updates to CHANGES.md and RELEASENOTES.md
[hbase.git] / bin / chaos-daemon.sh
blob084e519321a224206a5bad20fd6ba496078061ed
1 #!/usr/bin/env bash
3 #/**
4 # * Licensed to the Apache Software Foundation (ASF) under one
5 # * or more contributor license agreements. See the NOTICE file
6 # * distributed with this work for additional information
7 # * regarding copyright ownership. The ASF licenses this file
8 # * to you under the Apache License, Version 2.0 (the
9 # * "License"); you may not use this file except in compliance
10 # * with the License. You may obtain a copy of the License at
11 # *
12 # * http://www.apache.org/licenses/LICENSE-2.0
13 # *
14 # * Unless required by applicable law or agreed to in writing, software
15 # * distributed under the License is distributed on an "AS IS" BASIS,
16 # * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 # * See the License for the specific language governing permissions and
18 # * limitations under the License.
19 # */
22 usage="Usage: chaos-daemon.sh (start|stop) chaosagent"
24 # if no args specified, show usage
25 if [ $# -le 1 ]; then
26 echo "$usage"
27 exit 1
30 # get arguments
31 startStop=$1
32 shift
34 command=$1
35 shift
37 check_before_start(){
38 #ckeck if the process is not running
39 mkdir -p "$HBASE_PID_DIR"
40 if [ -f "$CHAOS_PID" ]; then
41 if kill -0 "$(cat "$CHAOS_PID")" > /dev/null 2>&1; then
42 echo "$command" running as process "$(cat "$CHAOS_PID")". Stop it first.
43 exit 1
48 bin=`dirname "${BASH_SOURCE-$0}"`
49 bin=$(cd "$bin">/dev/null || exit; pwd)
51 . "$bin"/hbase-config.sh
52 . "$bin"/hbase-common.sh
54 CLASSPATH=$HBASE_CONF_DIR
55 for f in ../lib/*.jar; do
56 CLASSPATH=${CLASSPATH}:$f
57 done
59 # get log directory
60 if [ "$HBASE_LOG_DIR" = "" ]; then
61 export HBASE_LOG_DIR="$HBASE_HOME/logs"
64 if [ "$HBASE_PID_DIR" = "" ]; then
65 HBASE_PID_DIR=/tmp
68 if [ "$HBASE_IDENT_STRING" = "" ]; then
69 export HBASE_IDENT_STRING="$USER"
72 if [ "$JAVA_HOME" != "" ]; then
73 #echo "run java in $JAVA_HOME"
74 JAVA_HOME=$JAVA_HOME
76 if [ "$JAVA_HOME" = "" ]; then
77 echo "Error: JAVA_HOME is not set."
78 exit 1
81 export HBASE_LOG_PREFIX=hbase-$HBASE_IDENT_STRING-$command-$HOSTNAME
82 export CHAOS_LOGFILE=$HBASE_LOG_PREFIX.log
84 if [ -z "${HBASE_ROOT_LOGGER}" ]; then
85 export HBASE_ROOT_LOGGER=${HBASE_ROOT_LOGGER:-"INFO,RFA"}
88 if [ -z "${HBASE_SECURITY_LOGGER}" ]; then
89 export HBASE_SECURITY_LOGGER=${HBASE_SECURITY_LOGGER:-"INFO,RFAS"}
92 CHAOS_LOGLOG=${CHAOS_LOGLOG:-"${HBASE_LOG_DIR}/${CHAOS_LOGFILE}"}
93 CHAOS_PID=$HBASE_PID_DIR/hbase-$HBASE_IDENT_STRING-$command.pid
95 if [ -z "$CHAOS_JAVA_OPTS" ]; then
96 CHAOS_JAVA_OPTS="-Xms1024m -Xmx4096m"
99 case $startStop in
101 (start)
102 check_before_start
103 echo running $command
104 CMD="${JAVA_HOME}/bin/java -Dapp.home=${HBASE_CONF_DIR}/../ ${CHAOS_JAVA_OPTS} -cp ${CLASSPATH} org.apache.hadoop.hbase.chaos.ChaosService -$command start &>> ${CHAOS_LOGLOG} &"
106 eval $CMD
107 PID=$(echo $!)
108 echo ${PID} >${CHAOS_PID}
110 echo "Chaos ${1} process Started with ${PID} !"
111 now=$(date)
112 echo "${now} Chaos ${1} process Started with ${PID} !" >>${CHAOS_LOGLOG}
115 (stop)
116 echo stopping $command
117 if [ -f $CHAOS_PID ]; then
118 pidToKill=`cat $CHAOS_PID`
119 # kill -0 == see if the PID exists
120 if kill -0 $pidToKill > /dev/null 2>&1; then
121 echo -n stopping $command
122 echo "`date` Terminating $command" >> $CHAOS_LOGLOG
123 kill $pidToKill > /dev/null 2>&1
124 waitForProcessEnd $pidToKill $command
125 else
126 retval=$?
127 echo no $command to stop because kill -0 of pid $pidToKill failed with status $retval
129 else
130 echo no $command to stop because no pid file $CHAOS_PID
132 rm -f $CHAOS_PID
136 echo $usage
137 exit 1
140 esac