org.apache.hadoop.ha

## Class ShellCommandFencer

- java.lang.Object
- - org.apache.hadoop.conf.Configured
  - - org.apache.hadoop.ha.ShellCommandFencer

- All Implemented Interfaces:
    Configurable, FenceMethod

      public class ShellCommandFencer
      extends Configured
      implements FenceMethod

  Fencing method that runs a shell command. It should be specified in the fencing configuration like:
  `shell(/path/to/my/script.sh arg1 arg2 ...)`
  The string between '(' and ')' is passed directly to a bash shell (cmd.exe on Windows) and may not include any closing parentheses.

  The shell command will be run with an environment set up to contain all of the current Hadoop configuration variables, with the '_' character replacing any '.' characters in the configuration keys.

  If the shell command returns an exit code of 0, the fencing is determined to be successful. If it returns any other exit code, the fencing was not successful and the next fencing method in the list will be attempted.

  Note: this fencing method does not implement any timeout. If timeouts are necessary, they should be implemented in the shell script itself (eg by forking a subshell to kill its parent in some number of seconds).

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `ShellCommandFencer()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `checkArgs(String args)` Verify that the given fencing method's arguments are valid.
    `boolean` | `tryFence(HAServiceTarget target, String args)` Attempt to fence the target node.

    - ### Methods inherited from class org.apache.hadoop.conf.Configured

      `getConf, setConf`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ShellCommandFencer

          public ShellCommandFencer()

  - ### Method Detail

    - #### checkArgs

          public void checkArgs(String args)
                         throws BadFencingConfigurationException

      Description copied from interface: `FenceMethod`
      Verify that the given fencing method's arguments are valid.
      Specified by:
        `checkArgs` in interface `FenceMethod`
      Parameters:
        `args` - the arguments provided in the configuration. This may be null if the operator did not configure any arguments.
      Throws:
        `BadFencingConfigurationException` - if the arguments are invalid

    - #### tryFence

          public boolean tryFence(HAServiceTarget target,
                                  String args)

      Description copied from interface: `FenceMethod`
      Attempt to fence the target node.
      Specified by:
        `tryFence` in interface `FenceMethod`
      Parameters:
        `target` - the target of the service to fence
        `args` - the configured arguments, which were checked at startup by `FenceMethod.checkArgs(String)`
      Returns:
        true if fencing was successful, false if unsuccessful or indeterminate

Copyright © 2008–2022 Apache Software Foundation. All rights reserved.