Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.

155 righe
4.2 KiB

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