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.
 
 
 
 

90 regels
2.3 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. THISDIR=$(cd $(dirname ${0}) && pwd)
  6. WORKSPACE_DIR=$(cd ${THISDIR}/../.. && pwd)
  7. WORKSPACE_NAME=$(basename ${WORKSPACE_DIR})
  8. function die {
  9. echo 1>&2 "$0: ${1}"
  10. exit 1
  11. }
  12. function redis_port() {
  13. if [[ -z "${BUBBLE_REDIS_PORT}" ]] ; then
  14. # pick port based on hash of workspace name; there is a 1-in-4096 chance of collision
  15. # if you get a collision, just define BUBBLE_REDIS_PORT in jenkins to be < 6800 or > 10895 in the job's build config
  16. BUBBLE_REDIS_PORT=$(expr 6800 + $(echo $((16#$(echo -n ${WORKSPACE_NAME} | sha256sum | awk '{print $1}' | tail -c 4)))))
  17. fi
  18. echo ${BUBBLE_REDIS_PORT}
  19. }
  20. function start_redis() {
  21. port=$(redis_port)
  22. REDIS_DIR=/tmp/redis-${port}
  23. REDIS_CONF=${REDIS_DIR}/redis.conf
  24. echo "Creating redis dir: ${REDIS_DIR}"
  25. mkdir -p ${REDIS_DIR} || die "Error creating redis dir: ${REDIS_DIR}"
  26. echo "Writing redis config: ${REDIS_CONF}"
  27. cat ${THISDIR}/redis.conf.hbs | sed -e "s/{{BUBBLE_REDIS_PORT}}/${port}/g" > ${REDIS_CONF} || die "Error writing redis configuration to ${REDIS_CONF}"
  28. echo "Starting redis..."
  29. redis-server ${REDIS_CONF} || die "Error starting redis"
  30. }
  31. function stop_redis_by_dir() {
  32. REDIS_DIR=${1}
  33. PID_FILE=${REDIS_DIR}/redis.pid
  34. if [[ ! -f ${PID_FILE} ]] ; then
  35. echo "Redis pid file not found: ${PID_FILE}"
  36. else
  37. echo "Stopping redis on port ${port}"
  38. kill $(cat ${PID_FILE}) || die "Error killing redis using pid file: ${PID_FILE}"
  39. fi
  40. if [[ -d ${REDIS_DIR} ]] ; then
  41. echo "Removing redis dir: ${REDIS_DIR}"
  42. rm -rf ${REDIS_DIR} || die "Error removing redis dir: ${REDIS_DIR}"
  43. fi
  44. }
  45. function stop_redis() {
  46. port=$(redis_port)
  47. REDIS_DIR=/tmp/redis-${port}
  48. stop_redis_by_dir ${REDIS_DIR}
  49. }
  50. function redis_clean() {
  51. for REDIS_DIR in $(find /tmp -maxdepth 1 -type d -name "redis-*") ; do
  52. stop_redis_by_dir ${REDIS_DIR}
  53. done
  54. }
  55. if [[ -z ${1} ]] ; then
  56. die "expected one of: start stop clean port"
  57. fi
  58. case ${1} in
  59. "start")
  60. stop_redis
  61. start_redis
  62. echo "Redis successfully started"
  63. ;;
  64. "stop")
  65. stop_redis
  66. echo "Redis stopped and cleaned up"
  67. ;;
  68. "port")
  69. redis_port
  70. ;;
  71. "clean")
  72. redis_clean
  73. ;;
  74. *)
  75. die "invalid argument: ${1}"
  76. ;;
  77. esac