The main Bubble source repository. Contains the Bubble API server, the web UI, documentation and utilities. https://getbubblenow.com
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.
 
 
 
 

118 lines
3.7 KiB

  1. #!/bin/bash
  2. #
  3. # Run Bubble server or CLI commands. A wrapper for starting a JVM to run Bubble programs.
  4. #
  5. # Usage: run.sh [debug [debug-port]] [command] [args]
  6. #
  7. # All arguments are optional:
  8. #
  9. # debug : if the first argument is the literal string 'debug' then immediately after starting,
  10. # the Java process will wait for a debugger to attach. Default is not to enable debugging.
  11. # debug-port : the port that will be listened on for the debugger. Default port is 5005
  12. # command : the CLI command to run, or 'server' to run BUBBLE API server. Default is to run Bubble API server
  13. # args : depends on the command. Use '-h' to request help for a command
  14. #
  15. # Environment variables
  16. #
  17. # BUBBLE_ENV : env file to load, used when performing handlebars substitutions on entities marked
  18. # with `"_subst": true` JSON attribute. Default is ~/.bubble.env
  19. # BUBBLE_JVM_OPTS : Java options. Defaults to "-Xmx4096 -Xms4096"
  20. # BUBBLE_JAR : location of bubble uberjar. Default is to assume there is exactly one bubble-server*.jar file in a
  21. # directory named "target" that is in the same directory as this script
  22. #
  23. # Environment variables for API commands
  24. #
  25. # BUBBLE_API : which API to use. Default is local (http://127.0.0.1:PORT, where PORT is found in .bubble.env)
  26. # BUBBLE_USER : account to use. Default is root
  27. # BUBBLE_PASS : password for account. Default is root
  28. #
  29. #
  30. SCRIPT="${0}"
  31. SCRIPT_DIR=$(cd $(dirname ${SCRIPT}) && pwd)
  32. . ${SCRIPT_DIR}/bubble_common
  33. # fail on any command error
  34. set -e
  35. BASE=$(cd $(dirname $0) && pwd)
  36. if [[ $(basename ${BASE}) != "bubble-server" && -d "${BASE}/bubble-server" ]] ; then
  37. BASE="${BASE}/bubble-server"
  38. fi
  39. if [[ $(basename ${BASE}) == "bin" && -d "${BASE}/../bubble-server" ]] ; then
  40. BASE="$(cd ${BASE}/../bubble-server && pwd)"
  41. fi
  42. # save explicitly set key, if we have one
  43. SAVED_DB_KEY=""
  44. if [[ ! -z "${BUBBLE_DB_ENCRYPTION_KEY}" ]] ; then
  45. SAVED_DB_KEY="${BUBBLE_DB_ENCRYPTION_KEY}"
  46. fi
  47. if [[ -z "${BUBBLE_ENV}" ]] ; then
  48. BUBBLE_ENV="${HOME}/.bubble.env"
  49. if [[ ! -f "${BUBBLE_ENV}" ]] ; then
  50. BUBBLE_ENV="/home/bubble/current/bubble.env"
  51. fi
  52. fi
  53. if [[ -f ${BUBBLE_ENV} ]] ; then
  54. if [[ -z "${BUBBLE_QUIET}" || ${BUBBLE_QUIET} != 1 ]] ; then
  55. echo 1>&2 "Loading env: ${BUBBLE_ENV}"
  56. fi
  57. . ${BUBBLE_ENV}
  58. fi
  59. if [[ ! -z "${SAVED_DB_KEY}" ]] ; then
  60. export BUBBLE_DB_ENCRYPTION_KEY="${SAVED_DB_KEY}"
  61. fi
  62. debug="${1}"
  63. if [[ "x${debug}" == "xdebug" ]] ; then
  64. shift
  65. ARG_LEN=$(echo -n "${1}" | wc -c)
  66. ARG_NUMERIC_LEN=$(echo -n "${1}" | tr -dc [:digit:] | wc -c) # strip all non-digits
  67. if [[ ! -z "${ARG_NUMERIC_LEN}" && ${ARG_LEN} -eq ${ARG_NUMERIC_LEN} ]] ; then
  68. # Second arg is the debug port
  69. DEBUG_PORT="${1}"
  70. shift || :
  71. fi
  72. if [[ -z "${DEBUG_PORT}" ]] ; then
  73. DEBUG_PORT=5005
  74. fi
  75. debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${DEBUG_PORT}"
  76. else
  77. debug=""
  78. fi
  79. command="${1}"
  80. server=0
  81. DEFAULT_JVM_OPTS=""
  82. if [[ -z "${command}" ]] ; then
  83. server=1
  84. CLASS=bubble.server.BubbleServer
  85. DEFAULT_JVM_OPTS="-Xmx512m -Xms512m"
  86. else
  87. CLASS=bubble.main.BubbleMain
  88. DEFAULT_JVM_OPTS="-Xmx256m -Xms64m"
  89. shift
  90. fi
  91. if [[ -z "${BUBBLE_JAR}" ]] ; then
  92. die "API jar file not found in ${BASE}/target"
  93. fi
  94. if [[ -z "${BUBBLE_JVM_OPTS}" ]] ; then
  95. BUBBLE_JVM_OPTS="${DEFAULT_JVM_OPTS}"
  96. fi
  97. BUBBLE_JVM_OPTS="${BUBBLE_JVM_OPTS} -Djava.net.preferIPv4Stack=true"
  98. # Choose appropriate log config
  99. if [[ ${server} -eq 1 ]] ; then
  100. LOG_CONFIG="-Dlogback.configurationFile=logback.xml"
  101. else
  102. LOG_CONFIG="-Dlogback.configurationFile=logback-client.xml"
  103. fi
  104. # Run!
  105. BUBBLE_JAR="${BUBBLE_JAR}" java ${LOG_CONFIG} ${BUBBLE_JVM_OPTS} ${debug} -server -cp ${BUBBLE_JAR} ${CLASS} ${command} "${@}"