Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

131 rader
3.3 KiB

  1. #!/bin/bash
  2. RUNNER_SCRIPT_DIR=$(cd ${0%/*} && pwd)
  3. RUNNER_BASE_DIR=${RUNNER_SCRIPT_DIR%/*}
  4. RUNNER_ETC_DIR=$RUNNER_BASE_DIR/etc
  5. RUNNER_LOG_DIR=$RUNNER_BASE_DIR/log
  6. PIPE_DIR=/tmp/$RUNNER_BASE_DIR/
  7. RUNNER_USER=
  8. # Make sure this script is running as the appropriate user
  9. if [ ! -z "$RUNNER_USER" ] && [ `whoami` != "$RUNNER_USER" ]; then
  10. exec sudo -u $RUNNER_USER -i $0 $@
  11. fi
  12. # Make sure CWD is set to runner base dir
  13. cd $RUNNER_BASE_DIR
  14. # Make sure log directory exists
  15. mkdir -p $RUNNER_LOG_DIR
  16. # Extract the target node name from node.args
  17. NAME_ARG=`grep -e '-[s]*name' $RUNNER_ETC_DIR/vm.args`
  18. if [ -z "$NAME_ARG" ]; then
  19. echo "vm.args needs to have either -name or -sname parameter."
  20. exit 1
  21. fi
  22. # Extract the target cookie
  23. COOKIE_ARG=`grep -e '-setcookie' $RUNNER_ETC_DIR/vm.args`
  24. if [ -z "$COOKIE_ARG" ]; then
  25. echo "vm.args needs to have a -setcookie parameter."
  26. exit 1
  27. fi
  28. # Identify the script name
  29. SCRIPT=`basename $0`
  30. # Parse out release and erts info
  31. START_ERL=`cat $RUNNER_BASE_DIR/releases/start_erl.data`
  32. ERTS_VSN=${START_ERL% *}
  33. APP_VSN=${START_ERL#* }
  34. # Add ERTS bin dir to our path
  35. ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
  36. # Setup command to control the node
  37. NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
  38. # Check the first argument for instructions
  39. case "$1" in
  40. start)
  41. # Make sure there is not already a node running
  42. RES=`$NODETOOL ping`
  43. if [ "$RES" == "pong" ]; then
  44. echo "Node is already running!"
  45. exit 1
  46. fi
  47. export HEART_COMMAND="$RUNNER_BASE_DIR/bin/$SCRIPT start"
  48. mkdir -p $PIPE_DIR
  49. # Note the trailing slash on $PIPE_DIR/
  50. $ERTS_PATH/run_erl -daemon $PIPE_DIR/ $RUNNER_LOG_DIR "exec $RUNNER_BASE_DIR/bin/$SCRIPT console" 2>&1
  51. ;;
  52. stop)
  53. # Wait for the node to completely stop...
  54. PID=`ps -ef|grep "$RUNNER_BASE_DIR/.*/[b]eam.smp|awk '{print $2}'"`
  55. $NODETOOL stop
  56. while `kill -0 $PID 2>/dev/null`;
  57. do
  58. sleep 1
  59. done
  60. ;;
  61. restart)
  62. ## Restart the VM without exiting the process
  63. $NODETOOL restart
  64. ;;
  65. reboot)
  66. ## Restart the VM completely (uses heart to restart it)
  67. $NODETOOL reboot
  68. ;;
  69. ping)
  70. ## See if the VM is alive
  71. $NODETOOL ping
  72. ;;
  73. attach)
  74. # Make sure a node IS running
  75. RES=`$NODETOOL ping`
  76. if [ "$RES" != "pong" ]; then
  77. echo "Node is not running!"
  78. exit 1
  79. fi
  80. shift
  81. $ERTS_PATH/to_erl $PIPE_DIR
  82. ;;
  83. console)
  84. # Setup beam-required vars
  85. ROOTDIR=$RUNNER_BASE_DIR
  86. BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
  87. EMU=beam
  88. PROGNAME=`echo $0 | sed 's/.*\\///'`
  89. CMD="$BINDIR/erlexec -boot $RUNNER_BASE_DIR/releases/$APP_VSN/$SCRIPT -embedded -config $RUNNER_ETC_DIR/app.config -args_file $RUNNER_ETC_DIR/vm.args -- ${1+"$@"}"
  90. export EMU
  91. export ROOTDIR
  92. export BINDIR
  93. export PROGNAME
  94. # Dump environment info for logging purposes
  95. echo "Exec: $CMD"
  96. echo "Root: $ROOTDIR"
  97. # Log the startup
  98. logger -t "$SCRIPT[$$]" "Starting up"
  99. # Start the VM
  100. exec $CMD
  101. ;;
  102. *)
  103. echo "Usage: $SCRIPT {start|stop|restart|reboot|ping|console|attach}"
  104. exit 1
  105. ;;
  106. esac
  107. exit 0