75 lines
2.6 KiB
Bash
75 lines
2.6 KiB
Bash
#!/bin/bash
|
|
set -eu
|
|
|
|
echo "Starting Keila on Cloudron"
|
|
|
|
# Initialize Keila data directory by copying from /app/pkg
|
|
if [[ ! -d "/app/data/keila" ]]; then
|
|
echo "==> Initializing Keila installation"
|
|
cp -r /app/pkg /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 for supervisor
|
|
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"
|
|
|
|
# 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
|
|
export DISABLE_REGISTRATION="true"
|
|
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
|
|
|
|
# Create complete Erlang runtime structure
|
|
echo "==> Setting up Erlang runtime"
|
|
ERTS_DIR=$(find /usr/local/lib/erlang -name "erts-*" -type d | head -1)
|
|
if [[ -n "$ERTS_DIR" ]]; then
|
|
echo "Setting up Erlang from: $ERTS_DIR"
|
|
# Create the exact structure Keila expects
|
|
rm -rf /app/data/keila/erts-14.2.5
|
|
cp -r "$ERTS_DIR" /app/data/keila/erts-14.2.5
|
|
chown -R cloudron:cloudron /app/data/keila/erts-14.2.5
|
|
|
|
# Also create symlink from the releases directory
|
|
cd /app/data/keila/releases/0.14.11
|
|
ln -sf ../../erts-14.2.5 ./erts-14.2.5
|
|
cd /app/code
|
|
fi
|
|
|
|
echo "==> Running database migrations"
|
|
sudo -u cloudron -E /app/data/keila/bin/keila eval "Keila.Release.migrate()"
|
|
|
|
echo "==> Starting supervisor"
|
|
exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon |