Skip to main content

Webhooks

Run commands on service lifecycle events.

Events

StageWhenOutcomes
on_startService spawnsuccess, error
on_stopService exitsuccess, error
on_restartAuto-restart after crashsuccess, error
  • Manual stops = success
  • Crashes = error
  • Only auto-restarts trigger on_restart

Configuration

services:
postgres:
command: "postgres -D /var/lib/postgres"
hooks:
on_start:
success:
command: "curl --request POST https://api.example.com/start"
timeout: "10s"
error:
command: "curl --request POST https://api.example.com/failed"
on_stop:
error:
command: "curl --request POST https://api.example.com/crashed"

Hooks inherit service environment variables.

Execution

  • Run via sh -c
  • Fire-and-forget (no retries)
  • Timeout kills with SIGKILL
  • Failures logged but don't affect service

Behavior

ScenarioHooks
Start successon_start.success
Start failureon_start.error
Manual stopon_stop.success
Crashon_stop.error → restart
Restart after crashon_stop.error, on_start.success, on_restart.success

Tips

  • Keep commands short
  • Use env vars for secrets
  • Make endpoints idempotent