code: public void setSafeMode(String[] argv, int idx) throws IOException {
      DistributedFileSystem dfs = getDFS();
      if (dfs == null) {
        System.err.println("FileSystem is " + getFS().getUri());
        return;
      }
      if (idx != argv.length - 1) {
        printUsage("-safemode");
        return;
      }
      FSConstants.SafeModeAction action;
      Boolean waitExitSafe = false;
  
      if ("leave".equalsIgnoreCase(argv[idx])) {
        action = FSConstants.SafeModeAction.SAFEMODE_LEAVE;
      } else if ("enter".equalsIgnoreCase(argv[idx])) {
        action = FSConstants.SafeModeAction.SAFEMODE_ENTER;
      } else if ("get".equalsIgnoreCase(argv[idx])) {
        action = FSConstants.SafeModeAction.SAFEMODE_GET;
      } else if ("initqueues".equalsIgnoreCase(argv[idx])) {
        action = FSConstants.SafeModeAction.SAFEMODE_INITQUEUES;
      } else if ("wait".equalsIgnoreCase(argv[idx])) {
        action = FSConstants.SafeModeAction.SAFEMODE_GET;
        waitExitSafe = true;
      } else {
        printUsage("-safemode");
        return;
      }
      boolean inSafeMode = dfs.setSafeMode(action);
  
      //
      // If we are waiting for safemode to exit, then poll and
      // sleep till we are out of safemode.
      //
      if (waitExitSafe) {
        while (inSafeMode) {
          try {
            Thread.sleep(5000);
          } catch (java.lang.InterruptedException e) {
            throw new IOException("Wait Interrupted");
          }
          inSafeMode = dfs.setSafeMode(action);
        }
      }
  
      System.out.println("Safe mode is " + (inSafeMode ? "ON" : "OFF"));
    }
docs: Safe mode maintenance command.
  Usage: java DFSAdmin -safemode [enter | leave | get | wait | initqueues]
  @param argv List of of command line parameters.
  @param idx The index of the command that is being processed.
  @exception IOException if the filesystem does not exist.