| #!/bin/bash |
| set -e |
|
|
| |
| echo "Starting Redis..." |
| redis-server --daemonize yes |
|
|
| |
| echo "Starting PostgreSQL..." |
| service postgresql start |
|
|
| |
| until pg_isready -h localhost; do |
| echo "Waiting for PostgreSQL..." |
| sleep 1 |
| done |
|
|
| |
| if ! su - postgres -c "psql -lqt" | cut -d \| -f 1 | grep -qw "postiz-db-local"; then |
| echo "Creating PostgreSQL user and database..." |
| su - postgres -c "psql -c \"CREATE USER \\\"postiz-user\\\" WITH PASSWORD 'postiz-password' SUPERUSER;\"" |
| su - postgres -c "psql -c \"CREATE DATABASE \\\"postiz-db-local\\\" OWNER \\\"postiz-user\\\";\"" |
| fi |
|
|
| |
| if [ -n "$GITHUB_PAT" ] && [ -n "$GITHUB_REPO" ] && [ -n "$GITHUB_BRANCH" ]; then |
| echo "GitHub backup configuration found. Restoring..." |
| BACKUP_DIR="/tmp/backup_repo" |
| rm -rf "$BACKUP_DIR" |
| git clone --depth 1 --branch "$GITHUB_BRANCH" "https://${GITHUB_PAT}@github.com/${GITHUB_REPO}.git" "$BACKUP_DIR" || { |
| echo "Could not clone branch $GITHUB_BRANCH. Trying to clone repository root..." |
| git clone --depth 1 "https://${GITHUB_PAT}@github.com/${GITHUB_REPO}.git" "$BACKUP_DIR" || true |
| } |
|
|
| if [ -d "$BACKUP_DIR" ] && [ -f "$BACKUP_DIR/backup.sql" ]; then |
| echo "Restoring database from backup..." |
| su - postgres -c "psql -d postiz-db-local -f $BACKUP_DIR/backup.sql" || echo "Restore from backup failed." |
| else |
| echo "No backup.sql found. Starting with a fresh database." |
| fi |
| else |
| echo "GitHub backup configuration not provided. Skipping restore." |
| fi |
|
|
| |
| echo "Starting Nginx..." |
| nginx |
|
|
| |
| if [ -n "$GITHUB_PAT" ] && [ -n "$GITHUB_REPO" ] && [ -n "$GITHUB_BRANCH" ]; then |
| echo "Starting GitHub backup daemon..." |
| chmod +x /app/var/docker/backup.sh |
| /app/var/docker/backup.sh & |
| fi |
|
|
| |
| echo "Starting Postiz via PM2..." |
| exec pnpm run pm2 |
|
|