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
12 # * http://www.apache.org/licenses/LICENSE-2.0
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.
22 usage
="Usage: chaos-daemon.sh (start|stop) chaosagent"
24 # if no args specified, show usage
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.
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
60 if [ "$HBASE_LOG_DIR" = "" ]; then
61 export HBASE_LOG_DIR
="$HBASE_HOME/logs"
64 if [ "$HBASE_PID_DIR" = "" ]; then
68 if [ "$HBASE_IDENT_STRING" = "" ]; then
69 export HBASE_IDENT_STRING
="$USER"
72 if [ "$JAVA_HOME" != "" ]; then
73 #echo "run java in $JAVA_HOME"
76 if [ "$JAVA_HOME" = "" ]; then
77 echo "Error: JAVA_HOME is not set."
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"
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} &"
108 echo ${PID} >${CHAOS_PID}
110 echo "Chaos ${1} process Started with ${PID} !"
112 echo "${now} Chaos ${1} process Started with ${PID} !" >>${CHAOS_LOGLOG}
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
127 echo no $command to stop because kill -0 of pid $pidToKill failed with status $retval
130 echo no $command to stop because no pid file $CHAOS_PID