@init

A top-level pipeline that executes when configuration is loaded or reloaded. Multiple @init{} blocks can be defined and they execute sequentially in the order they appear.

Note: The @ prefix is required for pipeline blocks. The legacy syntax without @ (e.g., init {}) is deprecated and emits warnings. Use @init {} for new configurations.

Execution: Runs on initial configuration load AND every configuration reload/restart.

Scope: Variables are isolated to each init block. Cache is shared across all init blocks within the same execution. Cache is cleared before init pipelines execute, so values from previous configurations are not available.

Use Cases

  • Logging configuration load/reload events
  • Pre-populating caches on configuration changes
  • Initializing shared resources
  • Running health checks after configuration updates

Example: Basic Configuration Logging

@init {
    log "SYSTEM" {
        json {
            "event" "configuration_loaded";
            "timestamp" datetime.timestamp;
        }
    }
}

Example: Multiple Init Blocks

You can define multiple @init{} blocks that execute in sequence:

caches {
    cache "CONFIG_CACHE" {
        timeout 1h;
    }
}

@init {
    # First init block: Set initial cache value
    cache {
        cache "CONFIG_CACHE";
        key "last_reload";
        value datetime.timestamp;
    }

    log "SYSTEM" {
        json {
            "event" "init_started";
            "timestamp" datetime.timestamp;
        }
    }
}

@init {
    # Second init block: Log completion
    # Note: Cache values from the first init block ARE visible here
    log "SYSTEM" {
        json {
            "event" "init_completed";
            "timestamp" datetime.timestamp;
        }
    }
}

Important: Cache Behavior

Cache is cleared once before init pipelines execute. This means:

  • Cache values from previous configuration are not available
  • Cache values set in one @init{} block ARE visible in subsequent @init{} blocks
  • All init blocks within the same execution share the same cache
  • Each init execution starts with a clean cache state

Important: Variable Behavior

Variables are isolated to each init block. This means:

  • Variables set in one @init{} block are NOT visible in subsequent @init{} blocks
  • Each init block starts with empty variables
  • Use cache for sharing data between init blocks

For persistent data storage across reloads, use:

  • Database backends (SQLite, MySQL, PostgreSQL)
  • JSONFile backends
  • External HTTP APIs

Execution Context

@init{} pipelines execute without AAA request context:

  • No aaa.* variables are available (no aaa.identity, aaa.result, etc.)
  • Use log, cache, backend, and modify actions to perform init tasks

See Also