Files
wekan/snap-src/bin/wekan-maintenance
T
Lauri Ojansivu 0ebf34aedc Snap: add wekan.migrate + wekan.maintenance commands and a maintenance page
wekan.migrate (bin/wekan-force-migrate): force a fresh MongoDB -> FerretDB migration,
ignoring the database setting and the migration marker. Removes any partial FerretDB SQLite +
resume checkpoint, sets database=mongodb, and starts wekan.mongodb so migration-control
re-reads the existing MongoDB (3 or 7) data and migrates again. Source MongoDB data untouched.

wekan.maintenance on|off (bin/wekan-maintenance): toggles a $SNAP_COMMON/.wekan-maintenance
marker. While present, mongodb-control / ferretdb-control do NOT auto-migrate or auto-disable,
so `snap start wekan.mongodb` or `snap start wekan.ferretdb` stays up and you can reach the
data over the MongoDB wire protocol on port 27019 (one at a time - they share the port).

Maintenance page (bin/wekan-maintenance-page.mjs): in maintenance mode wekan-control execs
this instead of WeKan; it serves an "under maintenance" page (HTTP 503) on the web port for
ALL URLs. It shows the Admin Panel product name if set (not "WeKan"), read from
$SNAP_COMMON/.productname.txt, which is cached while a database is running by wekan-control
(new db-eval `product-name` command) and by both migration importers - so it is available even
when both databases are stopped.

Registered `migrate` and `maintenance` apps in snapcraft.yaml.

Thanks to xet7.
2026-07-15 07:32:58 +03:00

46 lines
2.2 KiB
Bash
Executable File

#!/bin/bash
# wekan-maintenance — turn maintenance mode on/off. `snap run wekan.maintenance on|off`
#
# Maintenance mode (a $SNAP_COMMON/.wekan-maintenance marker) makes the DB control scripts
# NOT auto-disable/auto-migrate, so you can run MongoDB OR FerretDB by hand to reach the data
# over the MongoDB wire protocol (port 27019), and makes WeKan serve an "under maintenance"
# page on the web port instead of starting. MongoDB and FerretDB share port 27019, so run
# only one of them at a time.
set -u
COMMON="${SNAP_COMMON:-/var/snap/${SNAP_INSTANCE_NAME:-${SNAP_NAME:-wekan}}/common}"
svc="${SNAP_INSTANCE_NAME:-${SNAP_NAME:-wekan}}"
MARKER="$COMMON/.wekan-maintenance"
case "${1:-}" in
on)
touch "$MARKER"
echo "Maintenance mode ENABLED."
# Stop both databases so YOU control them by hand; (re)start WeKan so it serves the
# maintenance page on the web port.
snapctl stop "${svc}.mongodb" 2>/dev/null || true
snapctl stop "${svc}.ferretdb" 2>/dev/null || true
snapctl restart "${svc}.wekan" 2>/dev/null || true
echo ""
echo "The web port now shows an 'under maintenance' page for all URLs."
echo "Run ONE database by hand to access its data on the MongoDB wire protocol (port 27019):"
echo " snap start ${svc}.mongodb # the old MongoDB data"
echo " snap start ${svc}.ferretdb # the migrated FerretDB (SQLite) data"
echo " (only one at a time — they share port 27019)"
echo "When finished: snap run ${svc}.maintenance off"
;;
off)
rm -f "$MARKER"
echo "Maintenance mode DISABLED. Returning to normal operation."
# Stop any hand-started database, then let the normal startup logic pick the right one
# (mongodb-control disables itself and hands off to FerretDB if the SQLite data exists).
snapctl stop "${svc}.mongodb" 2>/dev/null || true
snapctl stop "${svc}.ferretdb" 2>/dev/null || true
snapctl start --enable "${svc}.mongodb" 2>/dev/null || true
snapctl restart "${svc}.wekan" 2>/dev/null || true
;;
*)
if [ -f "$MARKER" ]; then echo "Maintenance mode is currently: ON"; else echo "Maintenance mode is currently: OFF"; fi
echo "Usage: snap run ${svc}.maintenance on|off"
;;
esac