libretime / start.sh
xTHExBEASTx's picture
Upload 5 files
dd0e65c verified
#!/bin/bash
set -e
PG_DATA="/var/lib/postgresql/data"
RABBIT_DATA="/var/lib/rabbitmq"
# Ensure directories exist
mkdir -p "$PG_DATA"
mkdir -p "$RABBIT_DATA"
mkdir -p /var/log/libretime /var/log/icecast2 /var/log/nginx /var/log/supervisor
mkdir -p /run/php
# 1. Config Generation
if [ ! -f /etc/libretime/config.yml ]; then
echo "Generating config.yml..."
cp /etc/libretime/config.yml.template /etc/libretime/config.yml
fi
# 2. Setup Postgres
if [ ! -s "$PG_DATA/PG_VERSION" ]; then
echo "Initializing PostgreSQL..."
/usr/lib/postgresql/13/bin/initdb -D "$PG_DATA"
echo "host all all 127.0.0.1/32 trust" >> "$PG_DATA/pg_hba.conf"
echo "host all all ::1/128 trust" >> "$PG_DATA/pg_hba.conf"
echo "Starting PG for setup..."
/usr/lib/postgresql/13/bin/pg_ctl -D "$PG_DATA" -w start
echo "Creating LibreTime DB and User..."
# Connect to 'postgres' db as current user (who is superuser due to initdb)
psql -h localhost -d postgres -c "CREATE DATABASE libretime;" || true
psql -h localhost -d postgres -c "CREATE USER libretime WITH PASSWORD 'libretime';" || true
psql -h localhost -d postgres -c "GRANT ALL PRIVILEGES ON DATABASE libretime TO libretime;" || true
psql -h localhost -d postgres -c "ALTER USER libretime CREATEDB;" || true
echo "Stopping PG..."
/usr/lib/postgresql/13/bin/pg_ctl -D "$PG_DATA" stop
fi
# 3. Setup RabbitMQ
export RABBITMQ_NODENAME=rabbit@localhost
export RABBITMQ_LOG_BASE=/var/log/rabbitmq
export RABBITMQ_MNESIA_BASE=/var/lib/rabbitmq/mnesia
mkdir -p /var/log/rabbitmq /var/lib/rabbitmq/mnesia
chown -R user:user /var/log/rabbitmq /var/lib/rabbitmq
echo "Starting RabbitMQ for setup..."
/usr/sbin/rabbitmq-server -detached
echo "Waiting for RabbitMQ to be ready..."
for i in {1..30}; do
if rabbitmqctl status >/dev/null 2>&1; then
echo "RabbitMQ is ready."
break
fi
echo "Waiting... ($i/30)"
sleep 2
done
echo "Configuring RabbitMQ users..."
rabbitmqctl add_user libretime libretime || true
rabbitmqctl set_permissions -p / libretime ".*" ".*" ".*" || true
rabbitmqctl add_vhost /libretime || true
rabbitmqctl set_permissions -p /libretime libretime ".*" ".*" ".*" || true
echo "Stopping RabbitMQ..."
rabbitmqctl stop
# 4. Migrations
echo "Starting PostgreSQL for migration..."
/usr/lib/postgresql/13/bin/pg_ctl -D "$PG_DATA" -w start
echo "Running LibreTime Migrations..."
export LIBRETIME_CONFIG_FILEPATH=/etc/libretime/config.yml
# Use python -m to be safe if the script isn't in PATH
python3 -m libretime_api collectstatic --noinput
python3 -m libretime_api migrate --noinput
echo "Stopping PostgreSQL..."
/usr/lib/postgresql/13/bin/pg_ctl -D "$PG_DATA" stop
echo "Setup complete. Starting Supervisor..."
exec supervisord -c /etc/supervisor/conf.d/supervisord.conf