Changeset f434294 in Klonkt for scripts


Ignore:
Timestamp:
07/31/2026 02:02:34 PM (6 weeks ago)
Author:
Robin <roboburr@…>
Branches:
main
Children:
0ca7e9a4
Parents:
5462bab
Message:

Maskeer de oude klonkt.service bij de split, hij stond op te staan uit de dood

Op boiert.eu verscheen na de update opnieuw een /opt/klonkt/storage. Oorzaak:
de migratie deed alleen systemctl disable op klonkt.service, maar disable
haalt uitsluitend de autostart weg. Een systemctl restart klonkt start zo'n
unit alsnog, en precies dat staat in elke updater die voor de split is
gegenereerd.

De opgestane klonkt.service heeft WorkingDirectory=/opt/klonkt en geen
EnvironmentFile, terwijl zijn .env met de data mee is verhuisd naar
/var/lib/klonkt/<slug>/. Hij start dus zonder enige config, valt terug op de
ingebouwde standaardpaden en schrijft een verse lege database in de checkout.
Afhankelijk van wie de poort pakt levert dat een lege site op, of een
crashende unit die bij elke herstart de map opnieuw aanmaakt.

Disable is dus niet genoeg: de unit wordt nu ook gemaskeerd, zodat elke
aanroep hard faalt in plaats van stilletjes een tweede proces te starten.
Omkeerbaar met systemctl unmask.

Changed files:
scripts/klonkt-migrate-data.sh

  • oude unit wordt gestopt, uitgezet en gemaskeerd
  • test op list-unit-files in plaats van is-enabled, zodat een al uitgezette unit niet wordt overgeslagen

scripts/klonkt-refresh-updater.sh

  • maskeert de oude unit alsnog op een gesplitste installatie, zodat al gemigreerde servers zichzelf repareren
  • waarschuwt als er een storage/ in de checkout staat, met het commando om te controleren of er iets in zit; verwijdert nooit zelf

deploy/MULTI-INSTANCE.md

  • rollback bijgewerkt: unmask hoort er nu bij, met de reden

-robo
Co-Authored-By: Claude Fable 5 <noreply@…>

Location:
scripts
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • scripts/klonkt-migrate-data.sh

    r5462bab rf434294  
    129129
    130130step "Switching to klonkt@$SLUG"
    131 if systemctl is-enabled --quiet "$OLD_UNIT" 2>/dev/null; then
     131if systemctl list-unit-files "$OLD_UNIT" >/dev/null 2>&1; then
    132132  run "systemctl disable --now $OLD_UNIT"
    133   say "disabled $OLD_UNIT (file kept, so you can roll back)"
     133  # Disable only removes the autostart link: `systemctl restart klonkt` would
     134  # still START it. That is not theoretical — an updater generated before the
     135  # split does exactly that, and the resurrected unit finds no .env (it moved
     136  # with the data), falls back to the built-in defaults and creates a FRESH
     137  # EMPTY database in the checkout. Masking makes any such call fail loudly.
     138  # Reversible: systemctl unmask klonkt.
     139  run "systemctl mask $OLD_UNIT"
     140  say "disabled and masked $OLD_UNIT (unmask to roll back)"
    134141fi
    135142run "systemctl enable --now 'klonkt@$SLUG'"
  • scripts/klonkt-refresh-updater.sh

    r5462bab rf434294  
    5858chmod +x /usr/local/bin/klonkt-update
    5959echo "klonkt-update rewritten: branch ${BRANCH}, code ${KLONKT_DIR}, instances under ${DATA_ROOT}"
     60
     61# On a split install the old single unit must not be startable. `disable` alone
     62# does not stop `systemctl restart klonkt` from starting it, and a resurrected
     63# klonkt.service has no .env (it moved with the data): it falls back to the
     64# defaults and writes a fresh empty database into the checkout.
     65SPLIT=0
     66for d in "${DATA_ROOT}"/*/; do [ -f "$d/.env" ] && SPLIT=1 && break; done
     67if [ "$SPLIT" = 1 ] && systemctl list-unit-files klonkt.service >/dev/null 2>&1; then
     68  if ! systemctl is-enabled klonkt.service 2>/dev/null | grep -q masked; then
     69    systemctl stop klonkt.service 2>/dev/null || true
     70    systemctl disable klonkt.service 2>/dev/null || true
     71    systemctl mask klonkt.service
     72    echo "retired klonkt.service: stopped, disabled and masked (unmask to roll back)"
     73  fi
     74fi
     75
     76# A leftover storage/ in the checkout means something ran without the instance
     77# config. Report it; never delete it unattended — only its owner can tell
     78# whether it holds anything.
     79if [ "$SPLIT" = 1 ] && [ -e "${KLONKT_DIR}/storage" ]; then
     80  echo
     81  echo "WARNING: ${KLONKT_DIR}/storage exists while instance data lives in ${DATA_ROOT}."
     82  echo "         Something ran without the instance .env and wrote here. Check with:"
     83  echo "             sqlite3 ${KLONKT_DIR}/storage/database.sqlite 'select count(*) from posts;'"
     84  echo "         If it is empty, it is a stray from a resurrected klonkt.service and"
     85  echo "         can be removed. If it is NOT empty, do not delete it: ask first."
     86fi
Note: See TracChangeset for help on using the changeset viewer.