Skip to content

v2.37.0: Reusable daemon templates, stepped port bumping, and per-daemon proxy auto-start

Latest

Choose a tag to compare

@jdx jdx released this 02 Dec 00:40
· 12 commits to main since this release
Immutable release. Only release title and notes can be modified.
657b346

You can now define a set of daemons once and run several numbered or named copies of it. Port bumping can skip ports in fixed steps, and each daemon can override the proxy's global auto-start setting. Configs in a subdirectory of a git worktree now get a separate namespace in each worktree.

Added

  • Daemon templates with numbered or named instances (#1155). A new [daemon_templates] table defines a set of daemons once, and pitchfork adds a copy of the set for each instance. You no longer have to copy every [daemons.*] block by hand to run one backend per tenant or several worker/API pairs.

    [daemons.redis]
    run = "redis-server --port 6379"
    
    [daemon_templates.workers]
    instances = 2                      # or a list of names: ["acme", "globex"]
    
    [daemon_templates.workers.daemons.api]
    run = "./api --port $PORT"
    port = { expect = [3000], bump = 10 }
    
    [daemon_templates.workers.daemons.worker]
    run = "./worker --api http://127.0.0.1:{{ daemons.api.port }} --id {{ instance }}"
    depends = ["api", "redis"]

    This config defines the daemons workers.0.api, workers.0.worker, workers.1.api and workers.1.worker. It also defines one group per instance (workers.0, workers.1) and a workers group that contains every instance. For example, pitchfork start --group workers.1 starts a single instance.

    • Inside a copy, depends entries and {{ daemons.<name> }} refer to the daemons of the same instance first, and fall back to regular daemons. as aliases that point at template daemons are redirected to the same instance in the same way.
    • The new template variables {{ instance }} and {{ instance_index }} hold the instance name and its position from 0. Outside a template, both are null.
    • Every copy starts with the same port config. Give listening daemons a bump range so each copy can claim the next free port. Proxy hostnames are built from the copy's full name, for example workers-1-api.<project>.
    • Copies are created after all config files are merged, so pitchfork.local.toml can override instances. A copy or group whose name is already taken is a config error. A template can have at most 1000 instances.
    • The web UI stack page lists the generated groups. Commands that write config files, such as pitchfork daemons add, keep [daemon_templates] as written.

    See the daemon templates guide for details.

  • Port bump step for daemons limited to evenly spaced ports (#1154). This helps when only certain ports are allowed, for example when an OAuth provider accepts a fixed set of redirect URLs:

    [daemons.api]
    run = "node server.js"
    port = { expect = [4200], bump = 9, step = 10 }  # tries 4200, 4210, ... 4290

    step defaults to 1, so existing configs behave as before, and step = 0 is rejected. When a daemon expects several ports, all of them move by the same step. If the next candidate would be above port 65535, startup fails with the usual "no available port" error instead of wrapping around. step can only be set in the config, not on the CLI. It is kept across pitchfork restart.

  • Per-daemon proxy_auto_start (#1163), requested by @stephane-klein in #1161. This setting overrides settings.proxy.auto_start for one daemon, in either direction:

    [settings.proxy]
    auto_start = false
    
    [daemons.docs]
    run = "npm run docs"
    port = 4000
    proxy_auto_start = true   # starts when its URL is opened

    Daemons without the field follow the global setting. When a daemon is auto-started, its dependencies start with it regardless of their own proxy_auto_start.

Fixed

  • Each git worktree gets its own namespace when pitchfork.toml is in a subdirectory (#1168). Before this fix, app/pitchfork.toml got the namespace app in every worktree. As a result, pitchfork start api in one worktree reported that the daemon from another worktree was already running, and pitchfork stop api stopped the wrong daemon.

    • In a linked worktree (including worktrees of bare repositories), a namespace derived from a subdirectory now starts with the worktree's directory name. For example, ~/feature-a/app/pitchfork.toml gets the namespace feature-a-app.
    • The main checkout and worktree roots keep their current names.
    • An explicit namespace and namespaces registered with pitchfork config add still take precedence.
    • Derived directory names that are not valid namespaces are now cleaned up instead of failing to load. For example, review--1234 becomes review-1234. Names with non-ASCII characters still need an explicit namespace.
    • After upgrading: daemons that are already running from a subdirectory of a worktree stay registered under their old ID, such as app/api. Stop them by that qualified ID.
  • Less inotify queue pressure on Linux for file watching (#1174). The watch file watcher now filters out access events such as IN_OPEN in the kernel, so large recursive watches are less likely to fill the inotify queue. Restart behavior is unchanged.

Full Changelog: v2.36.0...v2.37.0

💚 Sponsor pitchfork

pitchfork is built and maintained by @jdx, an open source developer at entire.io, the title sponsor of his open source work.

If pitchfork has a place in your development workflow, please consider becoming an individual or company sponsor. Your support funds ongoing development and helps keep pitchfork fast, free, and independent.