Skip to content

v2.2.0: Lifecycle hooks for stop and exit, scoped daemon startup

Choose a tag to compare

@jdx jdx released this 24 Mar 22:44
· 186 commits to main since this release
Immutable release. Only release title and notes can be modified.
d433bb2

Pitchfork v2.2.0 adds two new lifecycle hooks (on_stop and on_exit) for running cleanup or notification commands when daemons terminate, and introduces --local / --global flags on pitchfork start so you can selectively start only project-level or system-level daemons.

Highlights

  • on_stop and on_exit hooks: Run custom commands when a daemon is explicitly stopped by pitchfork or when it terminates for any reason (stop, crash, or clean exit). New PITCHFORK_EXIT_REASON environment variable lets hooks distinguish the cause.
  • Scoped start flags: pitchfork start --local starts only daemons from your project's pitchfork.toml, while --global targets only daemons from ~/.config/pitchfork/config.toml and /etc/pitchfork/config.toml. The existing --all flag now explicitly means "both local and global."

Added

  • on_stop and on_exit lifecycle hooks -- Two new hook types let you react to daemon termination. on_stop fires when a daemon is explicitly stopped by pitchfork (via pitchfork stop, auto = ["stop"] directory exit, or supervisor shutdown). on_exit fires on any termination -- intentional stop, clean exit, or crash. For daemons with retries, on_exit fires only after all retries are exhausted. Both hooks receive PITCHFORK_EXIT_CODE and PITCHFORK_EXIT_REASON environment variables. Hook tasks are now tracked during supervisor shutdown so they complete reliably instead of being silently dropped. (#291) - @gaojunran

    [daemons.infra]
    run = "docker compose up"
    
    [daemons.infra.hooks]
    on_stop = "./scripts/notify-stopped.sh"
    on_exit = "docker compose down --volumes"

    The PITCHFORK_EXIT_REASON variable is set to "stop", "exit", or "fail" depending on why the daemon terminated. Also available via pitchfork config add --on-stop and --on-exit.

  • pitchfork start --local and pitchfork start --global -- New -l/--local and -g/--global flags allow starting only project-level or only global daemons, respectively. Previously --all was the only batch option and it started everything. The --all flag continues to work and now explicitly means "both local and global." (#282) - @gaojunran

    pitchfork start -l   # Start all daemons from local pitchfork.toml
    pitchfork start -g   # Start all daemons from global config
    pitchfork start -a   # Start all daemons (both local and global)

Full Changelog: v2.1.0...v2.2.0