Hooks

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

Hook folder
.muster/hooks/<service>/
├── deploy.sh
├── health.sh
├── rollback.sh
├── logs.sh
├── cleanup.sh
└── restart.sh     optional

muster 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

HookRun by
deploy.shmuster deploy, muster dev, fleet and group deploys
health.shAfter every deploy, muster status, muster dev and the dashboard. Exit 0 = healthy.
rollback.shmuster rollback and the deploy failure menu
logs.shmuster logs
cleanup.shmuster cleanup, and muster dev on Ctrl+C
restart.shmuster 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:

.muster/hooks/api/deploy.sh
#!/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}"
Terminal
muster hooks api deploy    # print the current hook
muster hooks approve api   # approve your edit on this machine

Prefer 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

StackWhat the generated deploy.sh does
k8sApplies 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.
composedocker compose build, pull and up.
dockerdocker build, then replaces the container.
bareYour commands on the host, e.g. a systemd restart.
devStarts a background process and records its PID.
infra variantsPull-only: no build. On k8s, rollout restart instead of set image.