fix(tubearchivist): use startup wrapper script like Docker
Move Django management commands (migrate, collectstatic, ta_envcheck, ta_connection, ta_startup) into run.sh startup wrapper that: - Waits up to 60s for ElasticSearch to be healthy - Runs all init commands before starting uvicorn - Matches Docker's run.sh approach This fixes ta_startup failing during install because ES wasn't ready. The commands now run at every service start with ES readiness check.
This commit is contained in:
@@ -59,15 +59,6 @@ function update_script() {
|
|||||||
mv /opt/tubearchivist_env.bak /opt/tubearchivist/.env
|
mv /opt/tubearchivist_env.bak /opt/tubearchivist/.env
|
||||||
msg_ok "Restored Configuration"
|
msg_ok "Restored Configuration"
|
||||||
|
|
||||||
msg_info "Running Migrations"
|
|
||||||
set -a
|
|
||||||
source /opt/tubearchivist/.env
|
|
||||||
set +a
|
|
||||||
cd /opt/tubearchivist/backend
|
|
||||||
$STD /opt/tubearchivist/.venv/bin/python manage.py migrate
|
|
||||||
$STD /opt/tubearchivist/.venv/bin/python manage.py collectstatic --noinput -c
|
|
||||||
msg_ok "Ran Migrations"
|
|
||||||
|
|
||||||
msg_info "Starting Services"
|
msg_info "Starting Services"
|
||||||
systemctl start tubearchivist tubearchivist-celery tubearchivist-beat
|
systemctl start tubearchivist tubearchivist-celery tubearchivist-beat
|
||||||
systemctl reload nginx
|
systemctl reload nginx
|
||||||
|
|||||||
@@ -182,19 +182,30 @@ EOF
|
|||||||
systemctl enable -q --now nginx
|
systemctl enable -q --now nginx
|
||||||
msg_ok "Configured Nginx"
|
msg_ok "Configured Nginx"
|
||||||
|
|
||||||
msg_info "Initializing Application"
|
|
||||||
set -a
|
|
||||||
source /opt/tubearchivist/.env
|
|
||||||
set +a
|
|
||||||
cd /opt/tubearchivist/backend
|
|
||||||
$STD /opt/tubearchivist/.venv/bin/python manage.py migrate
|
|
||||||
$STD /opt/tubearchivist/.venv/bin/python manage.py collectstatic --noinput -c
|
|
||||||
$STD /opt/tubearchivist/.venv/bin/python manage.py ta_envcheck
|
|
||||||
$STD /opt/tubearchivist/.venv/bin/python manage.py ta_connection
|
|
||||||
$STD /opt/tubearchivist/.venv/bin/python manage.py ta_startup
|
|
||||||
msg_ok "Initialized Application"
|
|
||||||
|
|
||||||
msg_info "Creating Services"
|
msg_info "Creating Services"
|
||||||
|
cat <<'RUNEOF' >/opt/tubearchivist/backend/run.sh
|
||||||
|
#!/bin/bash
|
||||||
|
set -e
|
||||||
|
cd /opt/tubearchivist/backend
|
||||||
|
PYTHON=/opt/tubearchivist/.venv/bin/python
|
||||||
|
|
||||||
|
echo "Waiting for ElasticSearch..."
|
||||||
|
for i in $(seq 1 30); do
|
||||||
|
if curl -sf http://localhost:9200/_cluster/health >/dev/null 2>&1; then
|
||||||
|
break
|
||||||
|
fi
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
|
$PYTHON manage.py migrate
|
||||||
|
$PYTHON manage.py collectstatic --noinput -c
|
||||||
|
$PYTHON manage.py ta_envcheck
|
||||||
|
$PYTHON manage.py ta_connection
|
||||||
|
$PYTHON manage.py ta_startup
|
||||||
|
|
||||||
|
exec $PYTHON backend_start.py
|
||||||
|
RUNEOF
|
||||||
|
chmod +x /opt/tubearchivist/backend/run.sh
|
||||||
cat <<EOF >/etc/systemd/system/tubearchivist.service
|
cat <<EOF >/etc/systemd/system/tubearchivist.service
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Tube Archivist Backend
|
Description=Tube Archivist Backend
|
||||||
@@ -206,9 +217,9 @@ User=root
|
|||||||
WorkingDirectory=/opt/tubearchivist/backend
|
WorkingDirectory=/opt/tubearchivist/backend
|
||||||
EnvironmentFile=/opt/tubearchivist/.env
|
EnvironmentFile=/opt/tubearchivist/.env
|
||||||
Environment=PATH=/opt/tubearchivist/.venv/bin:/usr/local/bin:/usr/bin:/bin
|
Environment=PATH=/opt/tubearchivist/.venv/bin:/usr/local/bin:/usr/bin:/bin
|
||||||
ExecStart=/opt/tubearchivist/.venv/bin/python backend_start.py
|
ExecStart=/opt/tubearchivist/backend/run.sh
|
||||||
Restart=on-failure
|
Restart=on-failure
|
||||||
RestartSec=5
|
RestartSec=10
|
||||||
|
|
||||||
[Install]
|
[Install]
|
||||||
WantedBy=multi-user.target
|
WantedBy=multi-user.target
|
||||||
|
|||||||
Reference in New Issue
Block a user