flink-init.j2 1.59 KB
Newer Older
1 2
#!/bin/bash

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

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

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

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

# The command that will start Apache Flink.
START_COMMAND="$INSTALLATION_PATH/flink/bin/yarn-session.sh -n {{ number_of_taskmanagers }} -tm {{ ram_per_task_manager }}"

18 19 20
# The command that will stop Apache Flink. Note that, HADOOP_HOME home variable should be set outside from this script and
# before Flink's deployment.
STOP_COMMAND="$HADOOP_HOME/bin/yarn application --kill"
21

22
start(){
23
  sudo -E -u $SCRIPT_USER nohup $START_COMMAND > /dev/null &
24
  RETVAL=$?
25
  [ $RETVAL -eq 0 ] && $(sudo -u $SCRIPT_USER touch $LOCKFILE)
26 27 28 29
  return $RETVAL
}

stop(){
30 31
  id=$(sudo -u $SCRIPT_USER $HADOOP_HOME/bin/yarn application --list | grep "Flink session" | cut -f1)
  sudo -E -u $SCRIPT_USER nohup $STOP_COMMAND $id > /dev/null &
32
  RETVAL=$?
33
  [ $RETVAL -eq 0 ] && $(sudo -u $SCRIPT_USER rm -f $LOCKFILE)
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
  return $RETVAL
}

restart(){
  stop
  start
}

RETVAL=0

case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  restart|reload|force-reload)
    restart
    ;;
  condrestart)
    [ -f $LOCKFILE ] && restart || :
    ;;
  status)
58
    [ -f $LOCKFILE ] && echo "Apache Flink is running." || echo "Apache Flink is not running."
59 60 61 62 63 64 65 66 67
    RETVAL=$?
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart|reload|force-reload|condrestart}"
    RETVAL=1
esac

exit $RETVAL