| #!/bin/bash |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| set -euo pipefail |
|
|
| log() { |
| printf '[%s] aether-entrypoint: %s\n' "$(date -u +%FT%TZ)" "$*" |
| } |
|
|
| |
| log "step 1: restore SQLite db from HF Dataset (if exists)" |
| if [[ -n "${HF_TOKEN:-}" && -n "${AETHER_BACKUP_REPO:-}" ]]; then |
| python3 /usr/local/bin/aether_restore.py || \ |
| log "restore failed (will start with fresh db)" |
| else |
| log "HF_TOKEN or AETHER_BACKUP_REPO unset; skip restore" |
| fi |
| mkdir -p "${AETHER_BACKUP_DIR}" |
|
|
| |
| log "step 2: setup backup cron (every ${AETHER_BACKUP_INTERVAL_MIN}m)" |
| mkdir -p /var/log/aether /etc/cron.d |
| cat > /etc/cron.d/aether-backup <<EOFCRON |
| SHELL=/bin/bash |
| PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin |
| HF_TOKEN=${HF_TOKEN:-} |
| AETHER_BACKUP_REPO=${AETHER_BACKUP_REPO} |
| AETHER_BACKUP_DIR=${AETHER_BACKUP_DIR} |
| */${AETHER_BACKUP_INTERVAL_MIN} * * * * root /usr/local/bin/aether-backup.sh >> /var/log/aether/backup.log 2>&1 |
| EOFCRON |
| chmod 0644 /etc/cron.d/aether-backup |
| touch /var/log/aether/backup.log |
|
|
| |
| if [[ "${AETHER_AUTO_UPDATE:-true}" == "true" ]]; then |
| log "step 3: setup auto-update cron (every ${AETHER_AUTO_UPDATE_INTERVAL_HOURS}h)" |
| cat > /etc/cron.d/aether-auto-update <<EOFCRON |
| SHELL=/bin/bash |
| PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin |
| HF_TOKEN=${HF_TOKEN:-} |
| AETHER_HF_SPACE_REPO=${AETHER_HF_SPACE_REPO:-iiioooo1/aether-hf} |
| AETHER_IMAGE=${AETHER_IMAGE:-ghcr.io/fawney19/aether:latest} |
| 0 */${AETHER_AUTO_UPDATE_INTERVAL_HOURS} * * * root /usr/local/bin/aether-auto-update.sh >> /var/log/aether/auto-update.log 2>&1 |
| EOFCRON |
| chmod 0644 /etc/cron.d/aether-auto-update |
| touch /var/log/aether/auto-update.log |
|
|
| log "step 4: start non-blocking auto-update check" |
| ( |
| /usr/local/bin/aether-auto-update.sh || true |
| ) >> /var/log/aether/auto-update.log 2>&1 & |
| else |
| log "auto-update disabled" |
| fi |
|
|
| cron |
|
|
| |
| shutdown_backup() { |
| log "received signal, flushing final backup" |
| /usr/local/bin/aether-backup.sh || log "final backup failed" |
| if [[ -n "${AETHER_PID:-}" ]] && kill -0 "$AETHER_PID" 2>/dev/null; then |
| kill -TERM "$AETHER_PID" || true |
| wait "$AETHER_PID" || true |
| fi |
| exit 0 |
| } |
| trap shutdown_backup TERM INT |
|
|
| |
| log "step 5: launch aether-gateway on port ${APP_PORT}" |
| cd /opt/aether |
|
|
| |
| |
| exec_bin="/opt/aether/current/bin/aether-gateway" |
| if [[ ! -x "$exec_bin" ]]; then |
| log "ERROR: $exec_bin not found or not executable" |
| ls -la /opt/aether/current/bin/ || true |
| exit 1 |
| fi |
|
|
| "$exec_bin" & |
| AETHER_PID=$! |
| log "aether-gateway started (pid=${AETHER_PID})" |
| wait "$AETHER_PID" |
| EXIT_CODE=$? |
| log "aether-gateway exited (code=${EXIT_CODE})" |
| shutdown_backup |
| exit $EXIT_CODE |
|
|