PageRenderTime 39ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/rel/files/ucengine

http://github.com/AF83/ucengine
#! | 156 lines | 132 code | 24 blank | 0 comment | 0 complexity | b77d95aca89a58bcfa5e0064e93915ae MD5 | raw file
  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. PIPE_DIR=/tmp/$RUNNER_BASE_DIR/
  9. RUNNER_USER=
  10. # Make sure this script is running as the appropriate user
  11. if [ ! -z "$RUNNER_USER" ] && [ `whoami` != "$RUNNER_USER" ]; then
  12. exec sudo -u $RUNNER_USER -i $0 $@
  13. fi
  14. # Make sure CWD is set to runner base dir
  15. cd $RUNNER_BASE_DIR
  16. # Make sure log directory exists
  17. mkdir -p $RUNNER_LOG_DIR
  18. # Extract the target node name from node.args
  19. NAME_ARG=`grep -e '-[s]*name' $RUNNER_ETC_DIR/vm.args`
  20. if [ -z "$NAME_ARG" ]; then
  21. echo "vm.args needs to have either -name or -sname parameter."
  22. exit 1
  23. fi
  24. # Extract the target cookie
  25. COOKIE_ARG=`grep -e '-setcookie' $RUNNER_ETC_DIR/vm.args`
  26. if [ -z "$COOKIE_ARG" ]; then
  27. echo "vm.args needs to have a -setcookie parameter."
  28. exit 1
  29. fi
  30. # Identify the script name
  31. SCRIPT=`basename $0`
  32. # Parse out release and erts info
  33. START_ERL=`cat $RUNNER_BASE_DIR/releases/start_erl.data`
  34. ERTS_VSN=${START_ERL% *}
  35. APP_VSN=${START_ERL#* }
  36. # Add ERTS bin dir to our path
  37. ERTS_PATH=$RUNNER_BASE_DIR/erts-$ERTS_VSN/bin
  38. # Setup command to control the node
  39. NODETOOL="$ERTS_PATH/escript $ERTS_PATH/nodetool $NAME_ARG $COOKIE_ARG"
  40. # Check the first argument for instructions
  41. case "$1" in
  42. start)
  43. # Make sure there is not already a node running
  44. RES=`$NODETOOL ping`
  45. if [ "$RES" = "pong" ]; then
  46. echo "Node is already running!"
  47. exit 1
  48. fi
  49. HEART_COMMAND="$RUNNER_BASE_DIR/bin/$SCRIPT start"
  50. export HEART_COMMAND
  51. mkdir -p $PIPE_DIR
  52. # Note the trailing slash on $PIPE_DIR/
  53. $ERTS_PATH/run_erl -daemon $PIPE_DIR/ $RUNNER_LOG_DIR "exec $RUNNER_BASE_DIR/bin/$SCRIPT console" 2>&1
  54. echo "Node is started. Check status with $0 ping"
  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|attach}"
  129. exit 1
  130. ;;
  131. esac
  132. exit 0