#!/bin/bash function check_service_running() { lxc exec "$container" -- bash -c "docker ps --format '{{.Names}},{{.Ports}}' | grep $1 | grep $2" } function _read() { disable_trace check_db_postgres_exists "$longname" check_container "$container" check_service_running "$longname" "$port" enable_trace return 0 } function _create() { echo "creating discourse instance for <$shortname> ... " echo "initialize discourse $shortname $longname ... OK" mkdir -p "$MIAOU_CONFIGDIR/apps/discourse" 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" echo "creating templates ... OK" echo "copying files to container <$container> ... " lxc file push --uid 0 --gid 0 "$MIAOU_CONFIGDIR/apps/discourse/$longname.yml" "$container/var/discourse/containers/$longname.yml" echo "copying files over container <$container> ... OK" if ! (db-psql list | grep -q "$longname"); then echo "create empty database <$longname> ... " db-psql create "$longname" echo "create empty database <$longname> ... OK" else echo "database already exists!" fi echo "build docker container $longname ..." lxc exec "$container" -- bash <" exit 1 ;; esac done [[ "$action" != unset && "$port" != unset && "$container" != unset && "$fqdn" != unset && "$domain" != unset && "$subdomain" != unset && "$shortname" != unset ]] || usage . "$MIAOU_BASEDIR/lib/init.sh" $action