The main Bubble source repository. Contains the Bubble API server, the web UI, documentation and utilities. https://getbubblenow.com
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.
 
 
 
 

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