yarn-init.j2 1.94 KB
Newer Older
1 2
#!/bin/bash

3 4 5
# Source environment file to make sure JAVA_HOME variable is available.
source /etc/environment

6 7 8
# Define the user that should run this script.
SCRIPT_USER=hduser

9 10 11 12 13 14 15 16
# The path where Apache Hadoop is installed.
INSTALLATION_PATH="{{ installation_path }}"

# The full path of the lock file to use.
LOCKFILE="$INSTALLATION_PATH/hadoop/yarn-lock"

# The command that will start Apache Yarn.
START_COMMAND="$INSTALLATION_PATH/hadoop/sbin/start-yarn.sh"
17 18

# The command that will stop Apache Yarn.
19
STOP_COMMAND="$INSTALLATION_PATH/hadoop/sbin/stop-yarn.sh"
20 21

start(){
22
  # Assert that there is no other Apache Yarn instance, created with this script, running.
23
  [ -f $LOCKFILE ] && return 0
24 25 26 27 28

  # Execute the command to start Apache Yarn. The command waits until Yarn has been started.
  sudo -u $SCRIPT_USER $START_COMMAND > /dev/null

  # Get the returned value of the executed command and create a lock file to prevent multiple instantiations.
29
  RETVAL=$?
30
  [ $RETVAL -eq 0 ] && $(sudo -u $SCRIPT_USER touch $LOCKFILE)
31 32 33 34
  return $RETVAL
}

stop(){
35 36 37 38 39 40 41
  # Assert that an Apache Yarn instance, created with this script, is running.
  [ ! -f $LOCKFILE ] && return 0

  # Execute the command to stop Apache Yarn. The command waits until Yarn has been stopped.
  sudo -u $SCRIPT_USER $STOP_COMMAND > /dev/null

  # Get the returned value of the executed command and delete the lock file.
42
  RETVAL=$?
43
  [ $RETVAL -eq 0 ] && $(sudo -u $SCRIPT_USER rm -f $LOCKFILE)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
  return $RETVAL
}

restart(){
  stop
  start
}

RETVAL=0

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart|reload|force-reload)
    restart
    ;;
  condrestart)
    [ -f $LOCKFILE ] && restart || :
    ;;
67
  status)
68
    # If the lock file exists, then Apache Yarn is running.
69
    [ -f $LOCKFILE ] && echo "Apache Yarn is running." || echo "Apache Yarn is not running."
70 71
    RETVAL=$?
    ;;
72
  *)
73
    echo "Usage: $0 {start|stop|restart|reload|force-reload|condrestart}"
74 75 76 77 78
    RETVAL=1
esac

exit $RETVAL