Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

how to verify if name node is in safe mode

Solved Go to solution
Highlighted

how to verify if name node is in safe mode

how to verify if name node is in safe mode ?

goal - in case of name node in safe mode , then bash script will perform the following steps on one of the masters machines

# su - hdfs  
$ hdfs dfsadmin -safemode get 
$ hdfs dfsadmin -safemode leave 

second how to perform the steps as described in the bash script

is it ok to do the following :

su - hdfs -c "hdfs dfsadmin -safemode get"
su - hdfs -c "hdfs dfsadmin -safemode leave" 
Michael-Bronson
1 ACCEPTED SOLUTION

Accepted Solutions

Re: how to verify if name node is in safe mode

@Michael Bronson,

Yes. You can use the second way to achieve your task. You can also use the below to check if namenode is in SafeMode and leave conditionally.

su - hdfs -c "hdfs dfsadmin -safemode get" | grep ON
if [ $? -ne 0 ]
then
  su - hdfs -c "hdfs dfsadmin -safemode leave" 
fi

To run the above script, put the content in a file say xyz.sh

chmod +x xyz.sh
./xyz.sh

Thanks,

Aditya

1 REPLY 1

Re: how to verify if name node is in safe mode

@Michael Bronson,

Yes. You can use the second way to achieve your task. You can also use the below to check if namenode is in SafeMode and leave conditionally.

su - hdfs -c "hdfs dfsadmin -safemode get" | grep ON
if [ $? -ne 0 ]
then
  su - hdfs -c "hdfs dfsadmin -safemode leave" 
fi

To run the above script, put the content in a file say xyz.sh

chmod +x xyz.sh
./xyz.sh

Thanks,

Aditya