Changes in scripts/klonkt-refresh-updater.sh [12bed59:5861849] in Klonkt
- File:
-
- 1 edited
-
scripts/klonkt-refresh-updater.sh (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
scripts/klonkt-refresh-updater.sh
r12bed59 r5861849 30 30 D="${KLONKT_DIR}" 31 31 B=\$(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. 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} 33 42 runuser -u ${KLONKT_USER} -- git -C "\$D" checkout -qf -B ${BRANCH} FETCH_HEAD 34 43 A=\$(runuser -u ${KLONKT_USER} -- git -C "\$D" rev-parse HEAD) … … 55 64 echo "Klonkt updated (\$A) + restarted \$N instance(s)." 56 65 fi 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 57 75 EOF 58 76 chmod +x /usr/local/bin/klonkt-update 59 77 echo "klonkt-update rewritten: branch ${BRANCH}, code ${KLONKT_DIR}, instances under ${DATA_ROOT}" 60 78 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. 67 83 SPLIT=0 68 84 for 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}." 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)" 80 91 fi 81 92 fi
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)