🔒 Repository is read-only – file editing is disabled.

pagan-web/restart-build-after-kernel.sh main

40 linii Raw ← Powrót
12345678910111213141516171819202122232425262728293031323334353637383940
#!/bin/bash
# /opt/pagan-web-v2/restart-build-after-kernel.sh
# Czeka na koniec bieżącego builda kernela (starego pagsync z wadliwym
# instalowaniem do rootfs), potem kończy starą instancję pagsync i startuje
# świeży przebieg z naprawionym kodem.
LOG=/var/log/pagan-restart.log
echo "===== RESTART $(date '+%F %T') =====" >> "$LOG"

# 1) Czekaj aż kernel (pagbuild na utils/kernel) zakończy się – max 6h
for i in $(seq 1 720); do
    if ! pgrep -f "pagbuild .*recipes/utils/kernel/PAGBUILD.yaml" >/dev/null; then
        echo "kernel skończony po ${i}0s" >> "$LOG"
        break
    fi
    sleep 10
done
sleep 20

# 2) Zakończ starą instancję pagsync (SIGTERM – handler ubija child buildy)
OLD=$(pgrep -f "/opt/pagan-web-v2/pagsync --once --missing" | head -1)
if [ -n "$OLD" ]; then
    echo "kończę starą instancję pagsync: $OLD" >> "$LOG"
    kill -TERM "$OLD" 2>>"$LOG"
    for i in $(seq 1 30); do
        kill -0 "$OLD" 2>/dev/null || break
        sleep 2
    done
    kill -9 "$OLD" 2>>"$LOG" || true
fi
# ewentualne osierocone pagbuild
pkill -f "pagbuild " 2>>"$LOG" || true
sleep 5

# 3) Świeży przebieg z nowym kodem
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
. /etc/pagan/build.conf 2>/dev/null
export PAGAN_DO_SIGN PAGAN_GPG_KEY
echo "start nowego pagsync --once --missing" >> "$LOG"
nohup /opt/pagan-web-v2/pagsync --once --missing >> /var/log/pagan-auto-build.log 2>&1 &
echo "PID: $!" >> "$LOG"