Pre-Start Hooks
Pre-start hooks are in-container shell scripts executed automatically by the Runtime Broker before an agent’s main harness process launches. They give you a powerful way to customize the agent’s filesystem and environment at the very last moment of provisioning — such as installing custom packages, writing specialized configuration files, or verifying external connectivity.
Execution Model and Precedence
Section titled “Execution Model and Precedence”Every pre-start hook runs inside the agent container under the fixed prefix:
$HOME/.scion/hooks/pre-start.d/30-project-customBecause of this single-slot model, exactly one pre-start hook can execute per agent container. When an agent is provisioned, Scion resolves the active hook using a simple fallback/override ordering:
- Project-Scoped Hook (Project Settings): Checked first. If the project contains an active project-scoped hook, it is staged and executed.
- Hub-Scoped Hook (Hub Resources): Checked second as a fallback. If there is no active project-scoped hook, the active hub-scoped default hook (if configured by an administrator) is staged and executed instead.
- No Hook: If neither scope has an active hook, no script is staged, and the container proceeds to start normally.
Crucial Execution Rules:
Section titled “Crucial Execution Rules:”- Failure is Fatal: If the pre-start hook script exits with a non-zero status, the agent’s startup sequence is immediately aborted, and the agent transitions to the
errorphase. - Idempotency: Pre-start hooks execute on every container start or resume. Scripts must be idempotent (safe to run multiple times on persistent filesystems).
- Size Limit: Hook scripts are stored directly in the Hub database and are capped at 64 KB at the API layer.
Managing Hooks via CLI
Section titled “Managing Hooks via CLI”You can manage pre-start hooks using two command trees depending on your permission scope:
scion project hook(for project-scoped hooks; available to project owners)scion hub hook(for hub-scoped hooks; requires hub-admin privileges)
Project-Scoped Hooks (scion project hook)
Section titled “Project-Scoped Hooks (scion project hook)”Project-scoped hooks let project owners attach customization scripts to a single project. The CLI infers the target project from your current directory’s Hub link, or you can specify it explicitly.
# List all pre-start hooks for the current projectscion project hook list
# Create a new active pre-start hook from a local filescion project hook create --name "Setup Python Packages" --script setup.sh
# Show the details and content of a specific hookscion project hook show setup-python-packages
# Update an existing hook scriptscion project hook update setup-python-packages --script setup-v2.sh
# Activate an archived hook (automatically archives the currently active hook)scion project hook activate setup-python-packages
# Delete an archived hook (active hooks cannot be deleted)scion project hook delete setup-python-packagesHub-Scoped Default Hooks (scion hub hook)
Section titled “Hub-Scoped Default Hooks (scion hub hook)”Hub administrators can define a global default pre-start hook that applies to all projects as a baseline fallback.
# List all hub-scoped pre-start hooksscion hub hook list
# Create a new active hub default hook from standard inputcat global-bootstrap.sh | scion hub hook create --name "Baseline Tools" --script -
# Show details of a hub-scoped hookscion hub hook show baseline-tools
# Update an existing hub hookscion hub hook update baseline-tools --script new-bootstrap.sh
# Activate a hub hookscion hub hook activate baseline-tools
# Delete an archived hub hookscion hub hook delete baseline-toolsManaging Hooks via the Web UI
Section titled “Managing Hooks via the Web UI”Pre-start hooks are also fully supported in the Scion Web Dashboard, matching existing resource-management patterns:
For Project Owners (Project Settings)
Section titled “For Project Owners (Project Settings)”- Navigate to the project page on the Web UI.
- Go to the Project Settings tab.
- Under the Resources section, select the Pre-Start Hooks tab.
- Here you can view, create, activate, or archive project-scoped hooks. You can also view the inherited Hub-scoped default hook (if any) and see whether it is currently active or overridden.
For Hub Administrators (Hub Resources)
Section titled “For Hub Administrators (Hub Resources)”- Go to the global Hub Settings or Resources section (
/settings). - Select the Pre-Start Hooks tab.
- Hub administrators can create, update, activate, and archive hub-scoped fallback scripts here.
Example Customization Scripts
Section titled “Example Customization Scripts”Here are typical use cases for pre-start hooks:
1. Installing Custom OS Packages
Section titled “1. Installing Custom OS Packages”If your template image is missing utility CLI tools, you can install them on the fly:
#!/usr/bin/env bashset -euo pipefail
echo "==> Installing system utilities..."if ! command -v jq &> /dev/null; then sudo apt-get update && sudo apt-get install -y jqfi2. Seeding Configuration Files
Section titled “2. Seeding Configuration Files”Pre-populate configuration files or environment overrides for your agent:
#!/usr/bin/env bashset -euo pipefail
echo "==> Setting up local config overrides..."mkdir -p "$HOME/.config/app"cat << 'EOF' > "$HOME/.config/app/settings.json"{ "api_endpoint": "https://api.internal.yourcompany.com", "debug": true}EOF3. Pre-flight Network Verification
Section titled “3. Pre-flight Network Verification”Ensure mandatory internal endpoints are reachable before the agent attempts to run:
#!/usr/bin/env bashset -euo pipefail
echo "==> Verifying database connectivity..."if ! nc -z -w5 db.internal.yourcompany.com 5432; then echo "ERROR: Internal database is unreachable. Aborting startup." exit 1fi