You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

156 lines
4.3 KiB

преди 14 години
преди 14 години
преди 14 години
преди 14 години
преди 14 години
преди 14 години
преди 14 години
преди 14 години
преди 14 години
  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=`egrep -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. shift # remove $1
  54. $ERTS_PATH/run_erl -daemon $PIPE_DIR $RUNNER_LOG_DIR "exec $RUNNER_BASE_DIR/bin/$SCRIPT console $@" 2>&1
  55. ;;
  56. stop)
  57. # Wait for the node to completely stop...
  58. case `uname -s` in
  59. Linux|Darwin|FreeBSD|DragonFly|NetBSD|OpenBSD)
  60. # PID COMMAND
  61. PID=`ps ax -o pid= -o command=|\
  62. grep "$RUNNER_BASE_DIR/.*/[b]eam"|awk '{print $1}'`
  63. ;;
  64. SunOS)
  65. # PID COMMAND
  66. PID=`ps -ef -o pid= -o args=|\
  67. grep "$RUNNER_BASE_DIR/.*/[b]eam"|awk '{print $1}'`
  68. ;;
  69. CYGWIN*)
  70. # UID PID PPID TTY STIME COMMAND
  71. PID=`ps -efW|grep "$RUNNER_BASE_DIR/.*/[b]eam"|awk '{print $2}'`
  72. ;;
  73. esac
  74. $NODETOOL stop
  75. while `kill -0 $PID 2>/dev/null`;
  76. do
  77. sleep 1
  78. done
  79. ;;
  80. restart)
  81. ## Restart the VM without exiting the process
  82. $NODETOOL restart
  83. ;;
  84. reboot)
  85. ## Restart the VM completely (uses heart to restart it)
  86. $NODETOOL reboot
  87. ;;
  88. ping)
  89. ## See if the VM is alive
  90. $NODETOOL ping
  91. ;;
  92. attach)
  93. # Make sure a node IS running
  94. RES=`$NODETOOL ping`
  95. if [ "$RES" != "pong" ]; then
  96. echo "Node is not running!"
  97. exit 1
  98. fi
  99. shift
  100. $ERTS_PATH/to_erl $PIPE_DIR
  101. ;;
  102. console|console_clean)
  103. # .boot file typically just $SCRIPT (ie, the app name)
  104. # however, for debugging, sometimes start_clean.boot is useful:
  105. case "$1" in
  106. console) BOOTFILE=$SCRIPT ;;
  107. console_clean) BOOTFILE=start_clean ;;
  108. esac
  109. # Setup beam-required vars
  110. ROOTDIR=$RUNNER_BASE_DIR
  111. BINDIR=$ROOTDIR/erts-$ERTS_VSN/bin
  112. EMU=beam
  113. PROGNAME=`echo $0 | sed 's/.*\\///'`
  114. 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+"$@"}"
  115. export EMU
  116. export ROOTDIR
  117. export BINDIR
  118. export PROGNAME
  119. # Dump environment info for logging purposes
  120. echo "Exec: $CMD"
  121. echo "Root: $ROOTDIR"
  122. # Log the startup
  123. logger -t "$SCRIPT[$$]" "Starting up"
  124. # Start the VM
  125. exec $CMD
  126. ;;
  127. *)
  128. echo "Usage: $SCRIPT {start|stop|restart|reboot|ping|console|console_clean|attach}"
  129. exit 1
  130. ;;
  131. esac
  132. exit 0