#!/bin/bash set -eu echo "Starting Keila on Cloudron" # Copy Keila release to /app/data on first run if [[ ! -d "/app/data/keila" ]]; then echo "==> Initializing Keila installation" cp -r /tmp/keila-release /app/data/keila chown -R cloudron:cloudron /app/data/keila fi # Generate secret key base if not exists if [[ ! -f "/app/data/secret_key_base" ]]; then echo "==> Generating secret key base" openssl rand -hex 64 > /app/data/secret_key_base chown cloudron:cloudron /app/data/secret_key_base fi # Set environment variables export SECRET_KEY_BASE=$(cat /app/data/secret_key_base) export DB_URL="${CLOUDRON_POSTGRESQL_URL}" export URL_HOST="${CLOUDRON_APP_DOMAIN}" export URL_SCHEMA="https" export URL_PORT="443" export PORT="4000" # Configure SMTP export MAILER_SMTP_HOST="${CLOUDRON_MAIL_SMTP_SERVER}" export MAILER_SMTP_PORT="${CLOUDRON_MAIL_SMTP_PORT}" export MAILER_SMTP_USERNAME="${CLOUDRON_MAIL_SMTP_USERNAME}" export MAILER_SMTP_PASSWORD="${CLOUDRON_MAIL_SMTP_PASSWORD}" export MAILER_SMTP_FROM_EMAIL="${CLOUDRON_MAIL_FROM}" # Set user content directory export USER_CONTENT_DIR="/app/data/uploads" mkdir -p /app/data/uploads chown cloudron:cloudron /app/data/uploads # Disable registration for security (admin can create users) export DISABLE_REGISTRATION="true" # Set database pool size export DATABASE_POOL_SIZE="10" # Create root user credentials file if not exists if [[ ! -f "/app/data/root_credentials" ]]; then echo "==> Generating root user credentials" ROOT_PASSWORD=$(openssl rand -base64 32) echo "Email: admin@${CLOUDRON_APP_DOMAIN}" > /app/data/root_credentials echo "Password: ${ROOT_PASSWORD}" >> /app/data/root_credentials export ROOT_EMAIL="admin@${CLOUDRON_APP_DOMAIN}" export ROOT_PASSWORD="${ROOT_PASSWORD}" chown cloudron:cloudron /app/data/root_credentials chmod 600 /app/data/root_credentials fi echo "==> Starting nginx" nginx -t nginx echo "==> Running database migrations" cd /app/data/keila sudo -u cloudron -E /app/data/keila/bin/keila eval "Keila.Release.migrate()" echo "==> Starting Keila application" cd /app/data/keila # Change the internal port since nginx listens on 4000 export PORT="4001" exec sudo -u cloudron -E /app/data/keila/bin/keila start