The main Bubble source repository. Contains the Bubble API server, the web UI, documentation and utilities. https://getbubblenow.com
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 

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