mirror of
https://github.com/storytold/autocraft.git
synced 2026-11-24 00:11:08 +01:00
Two copies of the runner or of the periodic chores can run on one Postgres database: the copy that holds the role's session-level advisory lock leads, the other waits as a standby and takes over when the leader's session ends. A new leader moves the role's epoch and fences its writes, and those of its jobs, to it: every write transaction checks the epoch after the writer lock, so writes of a leader that lost its lock fail. The old leader kills its jobs and exits when its lock connection fails or a check of the lock fails. A standby runner answers /readyz with 503; /healthz/checks gains runner-leader and periodic-leader. The periodic loop moves to deploy/periodic.sh, run by autocraft-server periodic.
23 lines
957 B
Bash
Executable File
23 lines
957 B
Bash
Executable File
#!/bin/bash
|
|
# Container entrypoint: the first argument picks the process. The commands match the systemd units.
|
|
# dashboard autocraft-server dash serve
|
|
# runner autocraft-server runner serve (also serves the worker API)
|
|
# sync autocraft-server sync [args] one-shot
|
|
# backup deploy/backup.sh [PREFIX [KEEP]] one-shot, default "daily"
|
|
# periodic autocraft-server periodic sync every minute and the daily backup, while this copy leads them
|
|
# anything else is passed to the autocraft-server CLI.
|
|
set -euo pipefail
|
|
cd /app
|
|
mkdir -p "${HOME:?}"
|
|
cli=(node --no-warnings src/cli.ts)
|
|
cmd="${1:-dashboard}"
|
|
[ "$#" -gt 0 ] && shift
|
|
case "$cmd" in
|
|
dashboard) exec "${cli[@]}" dash serve "$@" ;;
|
|
runner) exec "${cli[@]}" runner serve "$@" ;;
|
|
sync) exec "${cli[@]}" sync "$@" ;;
|
|
backup) exec bash deploy/backup.sh "${@:-daily}" ;;
|
|
periodic) exec "${cli[@]}" periodic "$@" ;;
|
|
*) exec "${cli[@]}" "$cmd" "$@" ;;
|
|
esac
|