Ignore:
File:
1 edited

Legend:

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

    r5861849 r12bed59  
    3030D="${KLONKT_DIR}"
    3131B=\$(runuser -u ${KLONKT_USER} -- git -C "\$D" rev-parse HEAD 2>/dev/null || true)
    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.
    37 if [ "\$(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
    40 fi
    41 runuser -u ${KLONKT_USER} -- git -C "\$D" fetch origin ${BRANCH}
     32runuser -u ${KLONKT_USER} -- git -C "\$D" fetch --depth 1 origin ${BRANCH}
    4233runuser -u ${KLONKT_USER} -- git -C "\$D" checkout -qf -B ${BRANCH} FETCH_HEAD
    4334A=\$(runuser -u ${KLONKT_USER} -- git -C "\$D" rev-parse HEAD)
     
    6455  echo "Klonkt updated (\$A) + restarted \$N instance(s)."
    6556fi
    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.
    68 if [ -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@*')"
    74 fi
    7557EOF
    7658chmod +x /usr/local/bin/klonkt-update
    7759echo "klonkt-update rewritten: branch ${BRANCH}, code ${KLONKT_DIR}, instances under ${DATA_ROOT}"
    7860
    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.
     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.
    8367SPLIT=0
    8468for d in "${DATA_ROOT}"/*/; do [ -f "$d/.env" ] && SPLIT=1 && break; done
    85 if [ "$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)"
     69if [ "$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}."
    9180  fi
    9281fi
Note: See TracChangeset for help on using the changeset viewer.