Skip to content

Lifecycle Hooks

Lifecycle hooks run shell commands at fixed points in a single program’s start/stop pipeline. They are configured per program, not globally.

For reacting to system-wide events (crashes, recovery, daemon startup), see System Events — those use a different configuration model (notify.toml with the notify plugin; [[event_hooks]] in OSS).

Hook catalog

HookWhen it runsBlocks start/stop?ExecutionImplemented
pre_startAfter extension before_start, before spawnYes — non-zero exit aborts start; program → FatalAwaited (sync)
post_startAfter PID assigned, extension after_start, and process_started eventNoAsync (tokio::spawn)
pre_stopAfter user/API stop requested, before SIGTERM / SIGKILLDelays signal until hook returnsAwaited (sync)
post_stopAfter process has exitedNoAsync (tokio::spawn)

Execution details

  • Commands run via sh -c, so pipes, redirects, and $() work.
  • Empty or whitespace-only commands are skipped.
  • Hook stdout/stderr inherit superd’s logging stream.
  • pre_start failure emits a process_fatal system event with message "Pre-start hook failed".

Configuration

Hooks are stored on each program — in super.toml, stack JSON, or via the API / Dashboard.

[[programs]]
name = "my-app"
command = "./app"

[programs.hooks]
pre_start = "mkdir -p /tmp/app-data && chmod 700 /tmp/app-data"
post_start = "curl -X POST http://consul:8500/register -d '...'"
pre_stop = "curl -X POST http://consul:8500/deregister -d '...'"
post_stop = "if [ \"$SUPER_EXIT_CODE\" != \"0\" ]; then aws s3 cp logs/app.err s3://archive/; fi"

Equivalent in stack JSON:

{
  "name": "my-app",
  "command": "./app",
  "hooks": {
    "pre_start": "echo checking...",
    "post_start": "echo registered"
  }
}

Where this config lives

SourcePath / APIPersisted to
TOML file[[programs]][programs.hooks]Loaded into registry on daemon start
Stack applyPUT /api/v1/stack with "hooks": { ... }snapshot.json
CLIsuper add / super update --pre-start "..."snapshot.json
DashboardProgram create/edit formsnapshot.json

Hooks are not defined in super.toml at the global level — only under each [[programs]] block (or via API/stack).

Environment variables

Hook scripts receive context via environment variables (in addition to the program’s env / env_file):

Variablepre_startpost_startpre_stoppost_stop
SUPER_ID
SUPER_NAME
SUPER_HOSTNAME
SUPER_GROUP✅ if set✅ if set✅ if set✅ if set
SUPER_PID
SUPER_EXIT_CODE
SUPER_UPTIME_SECS

The managed child process also receives SUPER_ID, SUPER_NAME, SUPER_HOSTNAME, and optional SUPER_GROUP at spawn time (not the full hook set).

Lifecycle vs system events

Lifecycle hooksSystem events
PurposeSetup/teardown around one program’s start/stopObserve cluster-wide incidents
ConfigPer program [programs.hooks]Global ([[event_hooks]] in OSS; notify.toml with notify plugin)
Data to scriptEnvironment variablesJSON on stdin (OSS event hooks) or HTTP payload (licensed notify)
Examplesmkdir, Consul register, drain flagSlack alert, archive logs on crash

Related