What are all the hook types I can use in app.yml

Hello, Trying to setup a hook to automatically connect to my docker network when discourse restarts or boots back up after building. This is so I can use the admin web updater when I can but trying to figure out the best way to go about this. Docs don’t really say all the hook types I can use and Looking up hooks such as after_post_boot and after_restart does nothing. Do these hooks no longer work and if so, why? Here’s my hooks code.

hooks:

begin custom network hook

after_restart:

  • exec:
    cmd:
  • bash
  • “-c”
  • |

Connect Discourse to the custom Docker network if not already connected

NETWORK_NAME=“proxy”
CONTAINER_NAME=$(hostname)

        # Create the network if it doesn't exist
        if ! docker network inspect "$NETWORK_NAME" >/dev/null 2>&1; then
          echo "Creating Docker network: $NETWORK_NAME"
          docker network create "$NETWORK_NAME"
        fi

        # Connect container to the network (ignore if already connected)
        echo "Connecting $CONTAINER_NAME to $NETWORK_NAME..."
        docker network connect "$NETWORK_NAME" "$CONTAINER_NAME" 2>/dev/null || true

        echo "Network connection complete."

END custom network hook

There isn’t actually a fixed global list of hook types in app.yml.
Hooks are provided dynamically by Pups, and you can only attach to the ones that exist inside the templates you include.


:magnifying_glass_tilted_left: How it works

When you see something like:

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git

that works because the templates contain a step like:

- hook: code
  run:
    - exec: ...

Pups lets you attach commands before or after any of those defined hook points.
So if a template defines hook: code, you can use before_code: or after_code:.
If it defines hook: assets_precompile, you can use before_assets_precompile: or after_assets_precompile: — and so on.

If there’s no hook: restart (for example), then after_restart: simply won’t fire.


:white_check_mark: Hooks known to exist in the stock templates

From the default templates/*.yml shipped with Discourse Docker:

Hook name Common usage Works with
code Main setup stage for plugin clones, custom file edits, etc. before_code: / after_code:
assets_precompile After Rails assets are compiled (e.g., upload to S3, clean up) after_assets_precompile:
web For last-minute tweaks before the web process boots before_web:

You’ll often see after_code: and before_code: used in plugin-install examples — these are the only ones needed in most setups.


:cross_mark: Hooks that don’t exist by default

Names like after_restart or after_post_boot don’t correspond to any hook: inside the standard templates, so Pups doesn’t know where to attach them.
They won’t trigger unless you add a matching hook: restart step in a custom template.


:toolbox: How to find all hooks available on your system

From your /var/discourse folder, run:

grep -R "hook:" -n templates/ samples/

That’ll list every hook name supported by the templates you currently include.
Anything you find there can be used as before_<name>: or after_<name>: inside your hooks: block.


:blue_book: Reference

This behaviour is explained briefly in the Pups README (the config-management tool used by Discourse’s Docker setup):

“Hooks are points in templates that allow commands to be injected before or after a step labelled with hook:.”


:puzzle_piece: In practice

  • Use after_code: for most custom shell commands (like plugin installs).
  • For things that should happen at container boot or restart, use a small startup script or supervisord task instead of inventing new hook names.
  • To add your own hook type, make a new template with a custom hook: something entry, then target it from app.yml.

TL;DR:
Only the hook names that actually appear as hook: entries in your templates exist.
In stock Discourse Docker, that’s basically code, assets_precompile, and web.