The main Bubble source repository. Contains the Bubble API server, the web UI, documentation and utilities. https://getbubblenow.com
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.
 
 
 
 

169 wiersze
5.6 KiB

  1. #!/bin/bash
  2. #
  3. # Copyright (c) 2020 Bubble, Inc. All rights reserved. For personal (non-commercial) use, see license: https://getbubblenow.com/bubble-license/
  4. #
  5. # Run Bubble server or CLI commands. A wrapper for starting a JVM to run Bubble programs.
  6. #
  7. # Usage: run.sh [debug [debug-port]] [command] [args]
  8. #
  9. # All arguments are optional:
  10. #
  11. # debug : if the first argument is the literal string 'debug' then immediately after starting,
  12. # the Java process will wait for a debugger to attach. Default is not to enable debugging.
  13. # debug-port : the port that will be listened on for the debugger. Default port is 5005
  14. # command : the CLI command to run, or 'server' to run BUBBLE API server. Default is to run Bubble API server
  15. # args : depends on the command. Use '-h' to request help for a command
  16. #
  17. # Environment variables
  18. #
  19. # BUBBLE_ENV : env file to load, used when performing handlebars substitutions on entities marked
  20. # with `"_subst": true` JSON attribute. Default is ~/.bubble.env
  21. # BUBBLE_JVM_OPTS : Java options. Defaults to either "-Xmx512m -Xms512m" when no command is set, else "-Xmx64m -Xms2m"
  22. # BUBBLE_JAR : location of bubble uberjar. Default is to assume there is exactly one bubble-server*.jar file in a
  23. # directory named "target" that is in the same directory as this script
  24. #
  25. # Environment variables for API commands
  26. #
  27. # BUBBLE_API : which API to use. Default is local (http://127.0.0.1:PORT, where PORT is found in .bubble.env)
  28. # BUBBLE_USER : account to use. Default is root@local.local
  29. # BUBBLE_PASS : password for account. Default is password
  30. #
  31. #
  32. SCRIPT="${0}"
  33. SCRIPT_DIR="$(cd "$(dirname "${SCRIPT}")" && pwd)"
  34. . "${SCRIPT_DIR}"/bubble_common
  35. # fail on any command error
  36. set -e
  37. BASE=$(cd $(dirname $0) && pwd)
  38. if [[ $(basename ${BASE}) != "bubble-server" && -d "${BASE}/bubble-server" ]] ; then
  39. BASE="${BASE}/bubble-server"
  40. fi
  41. if [[ $(basename ${BASE}) == "bin" && -d "${BASE}/../bubble-server" ]] ; then
  42. BASE="$(cd ${BASE}/../bubble-server && pwd)"
  43. fi
  44. # save explicitly set key, if we have one
  45. SAVED_DB_KEY=""
  46. if [[ -n "${BUBBLE_DB_ENCRYPTION_KEY}" ]] ; then
  47. SAVED_DB_KEY="${BUBBLE_DB_ENCRYPTION_KEY}"
  48. fi
  49. if [[ -z "${BUBBLE_ENV}" ]] ; then
  50. BUBBLE_ENV="${HOME}/.bubble.env"
  51. if [[ ! -f "${BUBBLE_ENV}" ]] ; then
  52. BUBBLE_ENV="/home/bubble/api/bubble.env"
  53. fi
  54. fi
  55. if [[ -f ${BUBBLE_ENV} ]] ; then
  56. if [[ -z "${BUBBLE_QUIET}" || ${BUBBLE_QUIET} != 1 ]] ; then
  57. echo 1>&2 "Loading env: ${BUBBLE_ENV}"
  58. fi
  59. . ${BUBBLE_ENV}
  60. fi
  61. if [[ -n "${SAVED_DB_KEY}" ]] ; then
  62. export BUBBLE_DB_ENCRYPTION_KEY="${SAVED_DB_KEY}"
  63. fi
  64. debug="${1}"
  65. if [[ "x${debug}" == "xdebug" ]] ; then
  66. shift
  67. ARG_LEN=$(echo -n "${1}" | wc -c)
  68. ARG_NUMERIC_LEN=$(echo -n "${1}" | tr -dc [:digit:] | wc -c) # strip all non-digits
  69. if [[ -n "${ARG_NUMERIC_LEN}" && ${ARG_LEN} -eq ${ARG_NUMERIC_LEN} ]] ; then
  70. # Second arg is the debug port
  71. DEBUG_PORT="${1}"
  72. shift || :
  73. fi
  74. if [[ -z "${DEBUG_PORT}" ]] ; then
  75. DEBUG_PORT=5005
  76. fi
  77. debug="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=${DEBUG_PORT}"
  78. else
  79. debug=""
  80. fi
  81. command="${1}"
  82. server=0
  83. DEFAULT_JVM_OPTS=""
  84. if [[ -z "${command}" ]] ; then
  85. server=1
  86. CLASS=bubble.server.BubbleServer
  87. DEFAULT_JVM_OPTS="-Xmx512m -Xms512m"
  88. else
  89. CLASS=bubble.main.BubbleMain
  90. DEFAULT_JVM_OPTS="-Xmx64m -Xms2m"
  91. shift
  92. fi
  93. if [[ -z "${BUBBLE_JAR}" ]] ; then
  94. die "API jar file not found"
  95. fi
  96. if [[ -z "${BUBBLE_JVM_OPTS}" ]] ; then
  97. BUBBLE_JVM_OPTS="${DEFAULT_JVM_OPTS}"
  98. fi
  99. BUBBLE_JVM_OPTS="${BUBBLE_JVM_OPTS} -Djava.net.preferIPv4Stack=true"
  100. # Choose appropriate log config
  101. if [[ ${server} -eq 1 ]] ; then
  102. LOG_CONFIG="-Dlogback.configurationFile=logback.xml"
  103. if [[ -f ${BUBBLE_ENV} ]] ; then
  104. command="${BUBBLE_ENV}"
  105. fi
  106. else
  107. LOG_CONFIG="-Dlogback.configurationFile=logback-client.xml"
  108. fi
  109. if [[ -z "${BUBBLE_ADDITIONAL_CLASSPATH}" ]] ; then
  110. BUBBLE_CP="${BUBBLE_JAR}"
  111. else
  112. BUBBLE_CP="${BUBBLE_JAR}:${BUBBLE_ADDITIONAL_CLASSPATH}"
  113. fi
  114. # Default user if none set
  115. if [[ -z "${BUBBLE_USER}" ]] ; then
  116. if [[ -n "${REQUIRE_BUBBLE_USER}" ]] ; then
  117. die "No BUBBLE_USER env var defined"
  118. fi
  119. BUBBLE_USER=root@local.local
  120. fi
  121. # Default password if none set
  122. if [[ -z "${BUBBLE_PASS}" ]] ; then
  123. # If BUBBLE_API is defined, we may have cached credentials
  124. BUBBLE_AUTH="${HOME}/.bubble_auth"
  125. if [[ -n "${BUBBLE_API}" && -d "${BUBBLE_AUTH}" ]] ; then
  126. if [[ -z "${BUBBLE_DISABLE_AUTH_CACHE}" || "${BUBBLE_DISABLE_AUTH_CACHE}" == "false" ]] ; then
  127. API_HOST="$(echo -n "${BUBBLE_API}" | awk -F '/' '{print $3}')"
  128. AUTH_DIR="${BUBBLE_AUTH}/${API_HOST}"
  129. PASS_FILE="${AUTH_DIR}/${BUBBLE_USER}"
  130. if [[ -n "${BUBBLE_USER}" && -f "${PASS_FILE}" ]] ; then
  131. if [[ -z "${BUBBLE_QUIET_AUTH_CACHE}" || "${BUBBLE_QUIET_AUTH_CACHE}" != "true" ]] ; then
  132. echo 1>&2 "Using cached password for user ${BUBBLE_USER} from ${AUTH_DIR}/${BUBBLE_USER}
  133. - Set env var BUBBLE_DISABLE_AUTH_CACHE=true to disable this behavior
  134. - Set env var BUBBLE_QUIET_AUTH_CACHE=true to hide this warning
  135. "
  136. fi
  137. BUBBLE_PASS="$(cat "${PASS_FILE}" | tr -d '[:space:]')"
  138. fi
  139. fi
  140. fi
  141. if [[ -n "${REQUIRE_BUBBLE_PASS}" ]] ; then
  142. die "No BUBBLE_PASS env var defined"
  143. fi
  144. echo 1>&2 "*** Warning: BUBBLE_PASS env var was not defined, using default password (probable authentication failure)"
  145. BUBBLE_PASS=password
  146. fi
  147. # Run!
  148. BUBBLE_JAR="${BUBBLE_JAR}" java ${LOG_CONFIG} ${BUBBLE_JVM_OPTS} \
  149. -Xlog:class+load=info:/tmp/bubble_classes_$(date +%s).txt \
  150. ${debug} -server -cp "${BUBBLE_CP}" ${CLASS} ${command} "${@}"