systemg

Search docs

/
Install

How It Works

Hooks

Run any shell command after a successful service start, an unsuccessful service exit, a cron run killed at its timeout, or a cron boundary skipped because the previous run was still going.

Events

HookWhen
onstartService reaches readiness or a one-shot completes successfully
onerrService exits unsuccessfully before or after readiness, a cron run is killed at its cron.timeout, or a cron boundary is skipped because the previous run is still going

Configuration

services:
  postgres:
    command: "postgres -D /var/lib/postgres"
    hooks:
      onstart:
        command: "echo 'Postgres started'"
        timeout: "10s"
      onerr:
        command: "/usr/local/bin/report-crash postgres"

Hooks inherit service environment variables, plus these, which say why the hook ran. A variable that doesn't apply to the event is unset, never empty, and a service's own env can't set any of them.

VariableSet forValue
SYSG_HOOK_EVENTevery hookonstart, service_exit, cron_exit, cron_timeout or cron_overlap
SYSG_EXIT_CODEservice_exit, cron_exitThe exit code, unset when there was none (killed by a signal, or never started)
SYSG_SCHEDULED_ATcron_exit, cron_timeout, cron_overlapThe schedule boundary the run was for, RFC 3339 UTC
SYSG_RUNNING_SINCEcron_overlapWhen the run that is still going started, RFC 3339 UTC

Execution

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

Behavior

ScenarioHooks
Start and readiness successonstart
Successful one-shot completiononstart
Spawn or readiness failure while runningNone
Clean exitNone
Manual stopNone
Unsuccessful exit before or after readinessonerr
Cron run killed at its cron.timeoutonerr
Cron boundary skipped while the previous run is still goingonerr
Successful automatic restartonstart

Tips

  • Keep commands short
  • Use env vars for secrets
  • Make repeated actions idempotent
← CronProcess Trees →