Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • scripts/klonkt-refresh-updater.sh

    r12bed59 r5861849  
    3030D="${KLONKT_DIR}"
    3131B=\$(runuser -u ${KLONKT_USER} -- git -C "\$D" rev-parse HEAD 2>/dev/null || true)
    32 runuser -u ${KLONKT_USER} -- git -C "\$D" fetch --depth 1 origin ${BRANCH}
     32# Deepen a shallow checkout ONCE. \`fetch --depth 1\` keeps only the newest commit
     33# and \`checkout -f\` throws away the tree that was there, so after an update the
     34# previous version existed nowhere on the machine: a bad release could not be
     35# undone without the network, and only if you knew which commit to ask for.
     36# One deepening buys back the history; every later fetch keeps it.
     37if [ "\$(runuser -u ${KLONKT_USER} -- git -C "\$D" rev-parse --is-shallow-repository 2>/dev/null)" = "true" ]; then
     38  echo "deepening the checkout once so updates can be rolled back..."
     39  runuser -u ${KLONKT_USER} -- git -C "\$D" fetch --unshallow origin ${BRANCH} || true
     40fi
     41runuser -u ${KLONKT_USER} -- git -C "\$D" fetch origin ${BRANCH}
    3342runuser -u ${KLONKT_USER} -- git -C "\$D" checkout -qf -B ${BRANCH} FETCH_HEAD
    3443A=\$(runuser -u ${KLONKT_USER} -- git -C "\$D" rev-parse HEAD)
     
    5564  echo "Klonkt updated (\$A) + restarted \$N instance(s)."
    5665fi
     66# History alone is not a rollback; at three in the morning you also need the
     67# command. Print it while the previous commit is still known.
     68if [ -n "\$B" ]; then
     69  echo
     70  echo "Previous version: \$B"
     71  echo "To go back:"
     72  echo "  runuser -u ${KLONKT_USER} -- git -C \$D checkout -qf -B ${BRANCH} \$B"
     73  echo "  then restart the instances (systemctl restart 'klonkt@*')"
     74fi
    5775EOF
    5876chmod +x /usr/local/bin/klonkt-update
    5977echo "klonkt-update rewritten: branch ${BRANCH}, code ${KLONKT_DIR}, instances under ${DATA_ROOT}"
    6078
    61 # On a split install the old single unit must not be startable at all.
    62 # `disable` is not enough (restart starts a disabled unit anyway) and `mask`
    63 # refuses while the real file sits in /etc/systemd/system, the highest-priority
    64 # directory. Moving the file aside is what actually works: systemd stops
    65 # knowing the unit, so any restart fails loudly instead of quietly starting a
    66 # second process that writes an empty database into the checkout.
     79# On a split install the old single unit must not be startable. `disable` alone
     80# does not stop `systemctl restart klonkt` from starting it, and a resurrected
     81# klonkt.service has no .env (it moved with the data): it falls back to the
     82# defaults and writes a fresh empty database into the checkout.
    6783SPLIT=0
    6884for d in "${DATA_ROOT}"/*/; do [ -f "$d/.env" ] && SPLIT=1 && break; done
    69 if [ "$SPLIT" = 1 ] && [ -f /etc/systemd/system/klonkt.service ]; then
    70   systemctl stop klonkt.service 2>/dev/null || true
    71   systemctl disable klonkt.service 2>/dev/null || true
    72   RETIRED="/etc/systemd/system/klonkt.service.retired-$(date +%Y%m%d%H%M%S)"
    73   if mv /etc/systemd/system/klonkt.service "$RETIRED"; then
    74     systemctl daemon-reload
    75     echo "retired klonkt.service → $RETIRED (move it back + daemon-reload to roll back)"
    76   else
    77     echo "WARNING: could not move /etc/systemd/system/klonkt.service aside."
    78     echo "         Until you do, any 'systemctl restart klonkt' starts a second"
    79     echo "         process that writes an empty database into ${KLONKT_DIR}."
     85if [ "$SPLIT" = 1 ] && systemctl list-unit-files klonkt.service >/dev/null 2>&1; then
     86  if ! systemctl is-enabled klonkt.service 2>/dev/null | grep -q masked; then
     87    systemctl stop klonkt.service 2>/dev/null || true
     88    systemctl disable klonkt.service 2>/dev/null || true
     89    systemctl mask klonkt.service
     90    echo "retired klonkt.service: stopped, disabled and masked (unmask to roll back)"
    8091  fi
    8192fi
Note: See TracChangeset for help on using the changeset viewer.