2022-07-08 19:33:07 +02:00
|
|
|
#!/bin/bash
|
2022-08-11 13:08:56 +02:00
|
|
|
declare -a ENV_VARS=("COUCHDB_USER" "COUCHDB_PASSWORD" "DATA_DIR" "MINIO_ACCESS_KEY" "MINIO_SECRET_KEY" "INTERNAL_API_KEY" "JWT_SECRET" "REDIS_PASSWORD")
|
|
|
|
|
|
|
|
# Azure App Service customisations
|
|
|
|
if [[ "${TARGETBUILD}" = "aas" ]]; then
|
|
|
|
DATA_DIR=/home
|
|
|
|
/etc/init.d/ssh start
|
|
|
|
else
|
|
|
|
DATA_DIR=${DATA_DIR:-/data}
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ -f "${DATA_DIR}/.env" ]; then
|
|
|
|
export $(cat ${DATA_DIR}/.env | xargs)
|
2022-07-08 19:33:07 +02:00
|
|
|
fi
|
|
|
|
# first randomise any unset environment variables
|
|
|
|
for ENV_VAR in "${ENV_VARS[@]}"
|
|
|
|
do
|
|
|
|
temp=$(eval "echo \$$ENV_VAR")
|
|
|
|
if [[ -z "${temp}" ]]; then
|
|
|
|
eval "export $ENV_VAR=$(uuidgen | sed -e 's/-//g')"
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
if [[ -z "${COUCH_DB_URL}" ]]; then
|
|
|
|
export COUCH_DB_URL=http://$COUCHDB_USER:$COUCHDB_PASSWORD@localhost:5984
|
|
|
|
fi
|
2022-08-11 13:08:56 +02:00
|
|
|
if [ ! -f "${DATA_DIR}/.env" ]; then
|
|
|
|
touch ${DATA_DIR}/.env
|
2022-07-08 19:33:07 +02:00
|
|
|
for ENV_VAR in "${ENV_VARS[@]}"
|
|
|
|
do
|
|
|
|
temp=$(eval "echo \$$ENV_VAR")
|
2022-08-11 13:08:56 +02:00
|
|
|
echo "$ENV_VAR=$temp" >> ${DATA_DIR}/.env
|
2022-07-08 19:33:07 +02:00
|
|
|
done
|
2022-08-11 13:08:56 +02:00
|
|
|
echo "COUCH_DB_URL=${COUCH_DB_URL}" >> ${DATA_DIR}/.env
|
2022-07-08 19:33:07 +02:00
|
|
|
fi
|
|
|
|
|
2022-08-11 13:08:56 +02:00
|
|
|
export COUCH_DB_URL=http://$COUCHDB_USER:$COUCHDB_PASSWORD@localhost:5984
|
|
|
|
|
2022-07-08 19:33:07 +02:00
|
|
|
# make these directories in runner, incase of mount
|
2022-09-07 11:51:53 +02:00
|
|
|
mkdir -p ${DATA_DIR}/couch/{dbs,views}
|
2022-08-11 13:08:56 +02:00
|
|
|
mkdir -p ${DATA_DIR}/minio
|
|
|
|
mkdir -p ${DATA_DIR}/search
|
2022-09-07 11:51:53 +02:00
|
|
|
chown -R couchdb:couchdb ${DATA_DIR}/couch
|
2022-04-01 02:00:52 +02:00
|
|
|
redis-server --requirepass $REDIS_PASSWORD &
|
|
|
|
/opt/clouseau/bin/clouseau &
|
2022-08-11 13:08:56 +02:00
|
|
|
/minio/minio server ${DATA_DIR}/minio &
|
2022-04-01 02:00:52 +02:00
|
|
|
/docker-entrypoint.sh /opt/couchdb/bin/couchdb &
|
2022-06-22 14:38:33 +02:00
|
|
|
/etc/init.d/nginx restart
|
|
|
|
if [[ ! -z "${CUSTOM_DOMAIN}" ]]; then
|
2022-06-22 14:57:46 +02:00
|
|
|
# Add monthly cron job to renew certbot certificate
|
|
|
|
echo -n "* * 2 * * root exec /app/letsencrypt/certificate-renew.sh ${CUSTOM_DOMAIN}" >> /etc/cron.d/certificate-renew
|
|
|
|
chmod +x /etc/cron.d/certificate-renew
|
|
|
|
# Request the certbot certificate
|
2022-06-22 14:38:33 +02:00
|
|
|
/app/letsencrypt/certificate-request.sh ${CUSTOM_DOMAIN}
|
|
|
|
fi
|
|
|
|
|
2022-04-01 02:00:52 +02:00
|
|
|
/etc/init.d/nginx restart
|
|
|
|
pushd app
|
|
|
|
pm2 start --name app "yarn run:docker"
|
|
|
|
popd
|
|
|
|
pushd worker
|
|
|
|
pm2 start --name worker "yarn run:docker"
|
|
|
|
popd
|
|
|
|
sleep 10
|
2022-06-22 14:38:33 +02:00
|
|
|
curl -X PUT ${COUCH_DB_URL}/_users
|
|
|
|
curl -X PUT ${COUCH_DB_URL}/_replicator
|
2022-06-22 15:38:45 +02:00
|
|
|
sleep infinity
|