provisioning tool for building opinionated architecture
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.

154 lines
3.5 KiB

1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
1 month ago
  1. #!/bin/bash
  2. function check_service_running() {
  3. lxc exec "$container" -- bash -c "docker ps --format '{{.Names}},{{.Ports}}' | grep $1 | grep $2"
  4. }
  5. function _read() {
  6. disable_trace
  7. check_db_postgres_exists "$longname"
  8. check_container "$container"
  9. check_service_running "$longname" "$port"
  10. enable_trace
  11. return 0
  12. }
  13. function _create() {
  14. echo "creating discourse instance for <$shortname> ... "
  15. echo "initialize discourse $shortname $longname ... OK"
  16. mkdir -p "$MIAOU_CONFIGDIR/apps/discourse"
  17. APP_DOMAIN=$domain APP_SUBDOMAIN=$subdomain APP_FQDN=$fqdn APP_PORT=$port APP_NAME=$longname tera -e --env-key env -t "$MIAOU_BASEDIR/templates/apps/discourse/forum.yml.j2" -o "$MIAOU_CONFIGDIR/apps/discourse/$longname.yml" "$MIAOU_CONFIGDIR/miaou.expanded.yaml"
  18. echo "creating templates ... OK"
  19. echo "copying files to container <$container> ... "
  20. lxc file push --uid 0 --gid 0 "$MIAOU_CONFIGDIR/apps/discourse/$longname.yml" "$container/var/discourse/containers/$longname.yml"
  21. echo "copying files over container <$container> ... OK"
  22. if ! (db-psql list | grep -q "$longname"); then
  23. echo "create empty database <$longname> ... "
  24. db-psql create "$longname"
  25. echo "create empty database <$longname> ... OK"
  26. else
  27. echo "database already exists!"
  28. fi
  29. echo "build docker container $longname ..."
  30. lxc exec "$container" -- bash <<EOF
  31. set -Eeuo pipefail
  32. cd /var/discourse
  33. ./launcher rebuild $longname
  34. EOF
  35. echo "initialize discourse $longname ... OK"
  36. }
  37. function _update() {
  38. echo "update"
  39. }
  40. function _delete() {
  41. echo "delete"
  42. }
  43. function usage() {
  44. echo "Usage: $COMMAND_NAME -c|r|u|d --port PORT --container CONTAINER --name NAME"
  45. exit 2
  46. }
  47. ### MAIN
  48. # init_strict
  49. source "$(dirname "$0")/../base/common.sh"
  50. COMMAND_NAME=$(basename "$0")
  51. # read the options
  52. TEMP=$(getopt -n "$COMMAND_NAME" -o crud --long port:,container:,name:,fqdn:,domain:,subdomain:,data: -- "$@")
  53. # shellcheck disable=SC2181
  54. [[ "$?" -eq 0 ]] || usage
  55. eval set -- "$TEMP"
  56. action="unset"
  57. port="unset"
  58. container="unset"
  59. shortname="unset"
  60. longname="unset"
  61. fqdn="unset"
  62. domain="unset"
  63. subdomain="unset"
  64. # extract options and their arguments into variables.
  65. while true; do
  66. case "$1" in
  67. --port)
  68. port=$2
  69. shift 2
  70. ;;
  71. --fqdn)
  72. fqdn=$2
  73. shift 2
  74. ;;
  75. --container)
  76. container=$2
  77. shift 2
  78. ;;
  79. --name)
  80. shortname=$2
  81. longname="discourse-$shortname"
  82. shift 2
  83. ;;
  84. --domain)
  85. domain=$2
  86. shift 2
  87. ;;
  88. --subdomain)
  89. subdomain=$2
  90. shift 2
  91. ;;
  92. --data)
  93. # don't care
  94. shift 2
  95. ;;
  96. -c)
  97. [[ "$action" == "unset" ]] || usage
  98. action="_create"
  99. shift 1
  100. ;;
  101. -r)
  102. [[ "$action" == "unset" ]] || usage
  103. action="_read"
  104. shift 1
  105. ;;
  106. -u)
  107. [[ "$action" == "unset" ]] || usage
  108. action="_update"
  109. shift 1
  110. ;;
  111. -d)
  112. [[ "$action" == "unset" ]] || usage
  113. action="_delete"
  114. shift 1
  115. ;;
  116. --)
  117. shift
  118. break
  119. ;;
  120. *)
  121. echoerr "Internal error: unrecognized option: <$1>"
  122. exit 1
  123. ;;
  124. esac
  125. done
  126. [[
  127. "$action" != unset &&
  128. "$port" != unset &&
  129. "$container" != unset &&
  130. "$fqdn" != unset &&
  131. "$domain" != unset &&
  132. "$subdomain" != unset &&
  133. "$shortname" != unset ]] || usage
  134. . "$MIAOU_BASEDIR/lib/init.sh"
  135. $action