Archives of Support Questions (Read Only)

This is an archived board for historical reference. Information and links may no longer be available or relevant
Announcements
This board is archived and read-only for historical reference. To ask a new question, please post a new topic on the appropriate active board.

how to verify if name node is in safe mode

avatar

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

avatar
Super Guru

@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

View solution in original post

1 REPLY 1

avatar
Super Guru

@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