Initial commit of Keila Cloudron package
This commit is contained in:
109
start.sh
109
start.sh
@ -1,81 +1,48 @@
|
||||
#!/bin/bash
|
||||
set -eu
|
||||
|
||||
echo "Starting Keila on Cloudron"
|
||||
set -euo pipefail
|
||||
|
||||
# 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"
|
||||
# Create user content directory
|
||||
mkdir -p /app/data/uploads
|
||||
chown cloudron:cloudron /app/data/uploads
|
||||
chown -R cloudron:cloudron /app/data
|
||||
|
||||
# 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
|
||||
# Generate secret key on first run
|
||||
if [ ! -f /app/data/secret_key.txt ]; then
|
||||
echo "=> Generating new secret key"
|
||||
head -c 48 /dev/urandom | base64 > /app/data/secret_key.txt
|
||||
fi
|
||||
|
||||
# Create complete Erlang runtime structure to fix paths
|
||||
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 at both possible locations
|
||||
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
|
||||
|
||||
# Create symlink in the releases directory for relative path resolution
|
||||
mkdir -p /app/data/keila/releases/0.14.11/erts-14.2.5
|
||||
rm -rf /app/data/keila/releases/0.14.11/erts-14.2.5
|
||||
ln -sf ../../../erts-14.2.5 /app/data/keila/releases/0.14.11/erts-14.2.5
|
||||
|
||||
# Also ensure the bin directory is accessible
|
||||
ln -sf /usr/local/bin/erl /app/data/keila/erts-14.2.5/bin/dyn_erl
|
||||
|
||||
echo "Created Erlang symlinks for path resolution"
|
||||
# Export environment variables for Keila
|
||||
export PORT=4000
|
||||
export DB_URL=$CLOUDRON_POSTGRESQL_URL
|
||||
export SECRET_KEY_BASE=$(cat /app/data/secret_key.txt)
|
||||
|
||||
# Configure URLs from Cloudron environment variables
|
||||
export URL_HOST=$CLOUDRON_APP_DOMAIN
|
||||
export URL_PATH="/"
|
||||
if [[ "$CLOUDRON_APP_ORIGIN" == https://* ]]; then
|
||||
export URL_SCHEMA="https"
|
||||
export URL_PORT="443"
|
||||
else
|
||||
export URL_SCHEMA="http"
|
||||
export URL_PORT="80"
|
||||
fi
|
||||
|
||||
echo "==> Running database migrations"
|
||||
sudo -u cloudron -E /app/data/keila/bin/keila eval "Keila.Release.migrate()"
|
||||
# Configure email settings
|
||||
export MAILER_TYPE=smtp
|
||||
export MAILER_SMTP_FROM_EMAIL=$CLOUDRON_MAIL_FROM
|
||||
export MAILER_SMTP_HOST=$CLOUDRON_MAIL_SMTP_SERVER
|
||||
export MAILER_SMTP_PORT=$CLOUDRON_MAIL_SMTP_PORT
|
||||
export MAILER_SMTP_USER=$CLOUDRON_MAIL_SMTP_USERNAME
|
||||
export MAILER_SMTP_PASSWORD=$CLOUDRON_MAIL_SMTP_PASSWORD
|
||||
export MAILER_ENABLE_STARTTLS=true
|
||||
|
||||
echo "==> Starting supervisor"
|
||||
exec /usr/bin/supervisord --configuration /etc/supervisor/supervisord.conf --nodaemon
|
||||
# Configure user content directory
|
||||
export USER_CONTENT_DIR=/app/data/uploads
|
||||
|
||||
# Set the initial admin user
|
||||
export KEILA_USER="admin@cloudron.local"
|
||||
export KEILA_PASSWORD="changeme123"
|
||||
|
||||
echo "=> Starting Keila"
|
||||
exec gosu cloudron:cloudron /app/code/bin/keila start
|
||||
|
Reference in New Issue
Block a user