Hooks
Hooks are the shell scripts that deploy, check, roll back, stream logs and clean up each service. muster runs them; they do the work.
Where hooks live
.muster/hooks/<service>/
├── deploy.sh
├── health.sh
├── rollback.sh
├── logs.sh
├── cleanup.sh
└── restart.sh optionalmuster setup generates them from templates for your stack. After that they are yours: edit them, then approve the change with muster hooks approve. Commit them with the project.
What runs each hook
| Hook | Run by |
|---|---|
deploy.sh | muster deploy, muster dev, fleet and group deploys |
health.sh | After every deploy, muster status, muster dev and the dashboard. Exit 0 = healthy. |
rollback.sh | muster rollback and the deploy failure menu |
logs.sh | muster logs |
cleanup.sh | muster cleanup, and muster dev on Ctrl+C |
restart.sh | muster restart (otherwise muster restarts through kubectl, compose or docker) |
A non-zero exit from deploy.sh or rollback.sh fails the service and opens the recovery menu in a terminal. Each hook gets deploy_timeout seconds (default 120).
Write or edit a hook
Hooks are plain bash. Read the service context from MUSTER_* variables instead of hard-coding names, so a change in muster.json updates every hook:
#!/usr/bin/env bash
set -euo pipefail
TAG="${MUSTER_DEPLOY_VERSION:-latest}"
docker build -t "registry.example.com/api:${TAG}" .
docker push "registry.example.com/api:${TAG}"
kubectl set image "deployment/${MUSTER_K8S_DEPLOYMENT}" \
api="registry.example.com/api:${TAG}" -n "${MUSTER_K8S_NAMESPACE}"muster hooks api deploy # print the current hook
muster hooks approve api # approve your edit on this machinePrefer a justfile? Put one in the hook folder with recipes named deploy, health, rollback, logs and cleanup; muster runs those instead (locally and on remotes) when just is installed.
What hooks receive
Every run gets the service context (MUSTER_SERVICE, MUSTER_K8S_DEPLOYMENT, MUSTER_K8S_NAMESPACE, MUSTER_DEPLOY_TIMEOUT…), git context (MUSTER_GIT_COMMIT, MUSTER_GIT_PREV_COMMIT…), one MUSTER_CRED_<KEY> per credential, and the values from .env or the muster env store. Existing environment variables are never overridden. Hooks get /dev/null as stdin when there is no terminal, so they can't hang waiting for input. The full list is in Environment variables.
Approval and safety checks
Before a hook runs, muster checks that this machine approved its current contents, and scans it for dangerous commands (rm -rf /, mkfs, dd if=, curl … | bash, chmod 777, reverse-shell listeners). Either problem blocks the hook. See Hook approvals & integrity.
Templates
| Stack | What the generated deploy.sh does |
|---|---|
k8s | Applies your manifests, builds and pushes the image, updates the deployment image (or restarts it when deploy_mode is restart), then waits for the rollout while watching pods for terminal errors (image pull, crash loop, OOM, config errors). |
k8s (blue-green, canary) | Points the candidate deployment ($MUSTER_TARGET_DEPLOYMENT) at the new image; muster's rollout engine does the rest. |
compose | docker compose build, pull and up. |
docker | docker build, then replaces the container. |
bare | Your commands on the host, e.g. a systemd restart. |
dev | Starts a background process and records its PID. |
infra variants | Pull-only: no build. On k8s, rollout restart instead of set image. |