NAME

Developer::Dashboard::Guide::Runtime - runtime lifecycle and state updates

DESCRIPTION

The runtime lifecycle: how the dashboard services run day to day, and how runtime state is updated.

This guide is part of the Developer::Dashboard manual. The main page is the front door for the whole set.

A diagram of the runtime lifecycle: four boxes in a row, Stopped, Starting, Running and Stopping, with d2 serve moving from Stopped to Starting, ready moving to Running, and d2 stop moving to Stopping, and a note that the supervisor restarts a worker that dies while Running.

The four states of the web runtime, and the commands that move it between them.

Runtime Lifecycle

The runtime manager follows the older local-service pattern:

  • d2 serve starts the web service in the background by default

  • On POSIX, background web startup launches the private web-foreground helper through GoRoutine's shell-free process API. The runtime records the listener only after the configured port accepts connections; if readiness times out, it terminates and reaps the child and reports its exit status and log paths.

  • d2 serve starts the configured collector loops alongside the web service, so a plain serve keeps collectors and the web runtime under the same lifecycle action

  • d2 serve --foreground keeps the web service attached to the terminal

  • d2 serve --ssl enables HTTPS in Starman with the generated local certificate and key, keeps that certificate on a browser-correct SAN profile covering localhost, loopback IPs, the concrete non-wildcard bind host, and any configured web.ssl_subject_alt_names, regenerates older dashboard certs when they are stale, redirects non-HTTPS requests to the matching https://... URL, and reuses the saved SSL setting on later d2 restart runs unless you override it

  • In SSL mode, the public frontend starts web-ssl-backend-foreground with GoRoutine's shell-free OS-process API. Accepted client sockets are handled by GoRoutine routines using the 0.12 shared filehandle support; shutdown stops and waits for the backend process and drains client routine errors explicitly. If a client or listener socket close fails, the frontend retains the first close error, joins its workers, stops the managed backend, and then reports the saved error so cleanup is not abandoned at the first failed close.

  • On Windows, saved-Ajax stdout and stderr pipes are drained by one Perl reader thread per pipe because IO::Select cannot reliably report anonymous pipe readiness there. Chunks and read errors pass through a bounded event queue; interrupted reads are retried, and a disconnected writer or fatal stream error terminates the child and joins both readers before returning.

  • d2 serve --no-editor and d2 serve --no-endit keep the browser in read-only mode by hiding Share, Play, and View Source chrome, denying /app/<id>/edit, /app/<id>/source, and bookmark-save POST routes with 403, and persisting that read-only flag for later d2 restart runs until d2 serve --editor turns it back off

  • d2 serve --no-indicators and d2 serve --no-indicator keep normal page rendering and left-side page chrome intact while clearing the whole top-right browser-only chrome area, including the status strip, username, host or IP link, and live date-time line, and persisting that flag for later d2 restart runs until d2 serve --indicators turns it back off

  • d2 serve logs prints the web-service runtime log captured in the d2 log file. -t prefixes lines with UTC timestamps, --tail N, --tail=N, and -n N limit the initial output, and -f follows appended lines. For example, d2 serve logs -t --tail 100 -f starts with the final 100 lines and then follows new output.

  • d2 serve workers N saves the default Starman worker count and starts the web service immediately when it is currently stopped; --host HOST and --port PORT can steer that auto-start path, and both d2 serve --workers N and d2 restart --workers N can still override the worker count for one run

  • d2 stop stops both the web service and managed collector loops and, prints the final lifecycle summary as a terminal table by default or JSON with -o json; on an interactive terminal it also prints the full stop task board on stderr before work starts so each shutdown step becomes visible instead of silent waiting.

    The shutdown path now also follows the saved managed listener port back to the real listener pid when the live web process has renamed itself into a starman master shape, so minimal Docker runs still stop the actual serving process instead of leaving the listener behind.

    Managed collector stop and restart flows also wait for the previous loop to really die before accepting a replacement, so a slow shutdown does not leave a stale collector process rewriting loop state while the next restart is proving the new pid.

  • d2 stop web only stops the managed web service

  • d2 collector stop only stops managed collector loops

  • d2 collector stop <name> only stops the requested managed collector loop, and collector-name shell completion suggests registered collector names

  • d2 restart stops both, starts configured collector loops again, then starts the web service, prints the final lifecycle summary as a terminal table by default or JSON with -o json, and only reports success after the replacement collector loops and web runtime become visible and survive a short post-ready confirmation window, with the web side still holding a live managed pid and an accepting listener on the requested port.

    Restart now also reuses the saved listener port to recover the real serving pid when the web process has renamed itself into the underlying starman master form, so container restarts still own and replace the active listener instead of losing control after startup. On Linux hosts that are also running Developer Dashboard inside Docker containers, managed stop and restart paths now reject sibling runtime pids that live in a different Linux pid namespace, so a host-side restart does not accidentally kill or adopt a container-owned web listener or collector loop

  • d2 restart web only restarts the managed web service

  • d2 collector restart only restarts managed collector loops

  • d2 collector restart <name> only restarts the requested collector loop, including an on-demand manual collector by converting it into a managed interval loop, and collector-name shell completion suggests registered collector names

  • managed collector loops also run under a watchdog supervisor; if a loop dies unexpectedly after startup, the watchdog restarts it automatically, records the restart attempt in collector status/logs, and after too many crashes inside the watchdog window marks the collector attention_required so the operator sees an explicit problem instead of infinite silent restart churn

  • d2 log and d2 logs print the combined dashboard web log plus collector logs

  • d2 logs --tail 100 or d2 logs --tail=100 prints only the last 100 lines of the combined output. The same --tail option accepts both spellings for d2 log web, d2 collector log, and a named collector log. -n N remains a compatible short form. --tail=0 prints no lines; negative or non-integer counts are rejected with usage information.

    -t prefixes each displayed line with a UTC timestamp. Collector output uses the recorded run timestamp; raw web output, which has no stored per-line event time, uses the time it is read. -f follows new lines from web logs, one collector, all collectors, or the combined view. Flags may be combined, so d2 logs -f -t --tail 50 starts with the last 50 combined lines and continues following both sources.

  • d2 log web prints only the dashboard web log and supports -t, --tail N, --tail=N, -n N, and -f

  • d2 collector log prints only collector logs and accepts -t, -f, and the same trailing-line limit

  • d2 collector log <name> prints only the requested collector log, accepts -t, -f, --tail N, and --tail=N, and collector-name shell completion suggests registered collector names

  • interactive restart and stop task boards mark the active step with a blue -, stream active detail lines in blue, mark completed steps with a green [OK], mark failed steps with a red [X] plus red failure detail lines, keep the final table or JSON summary on stdout, and use numeric POSIX shutdown signals so minimal Alpine/iSH Perl builds that reject TERM by name still terminate managed web and collector processes correctly

  • web shutdown and duplicate detection do not trust pid files alone; they validate managed processes by environment marker or process title and use a pkill-style scan fallback when needed

  • When a collector pid file is missing, duplicate detection checks both the process table and the parent-written loop state. That state closes the short startup interval before a newly forked supervisor adopts its process title, so a concurrent start does not fork a second loop.

Updating Runtime State

Run your user-provided update command:

d2 update

If ./.developer-dashboard/cli/update or ./.developer-dashboard/cli/update/run exists in the current project it is used first; otherwise the home runtime fallback is used. d2 update runs that command after any sorted hook files from update/ or update.d.

Re-running d2 init keeps an existing ~/.developer-dashboard/config/config.json intact. If the file is missing, init creates it as {}. The command refreshes dashboard-managed helpers in ~/.developer-dashboard/cli/dd/ and preserves user-owned saved pages.

When d2 init refreshes a dashboard-managed helper or shipped starter file, it compares the existing content against the shipped content by MD5 inside Perl first. If the content already matches, init skips the copy instead of rewriting the file unnecessarily.

When bookmark HTML: or shared nav/*.tt fragments hit a Template Toolkit syntax error, render mode now shows a visible runtime-error block instead of leaking the raw [% ... %] source into the browser or d2 page render output.

Home helper staging is non-destructive too. d2 init may add or update dashboard-managed built-in helpers only under ~/.developer-dashboard/cli/dd/. User commands and hook directories stay in ~/.developer-dashboard/cli/ and in child-layer ./.developer-dashboard/cli/ roots, and init must not overwrite or delete those user-space files while refreshing the home-only dd namespace.

The public d2 entrypoint also stays thin for all built-in commands. It only stages and execs helper assets from share/private-cli/: dedicated helper bodies for d2 jq, d2 yq, d2 of, d2 open-file, d2 workspace, d2 path, d2 paths, d2 file, d2 files, and d2 ps1, plus thin wrappers for the remaining built-ins that hand off to the shared private _dashboard-core runtime.

The shipped starter bookmark source lives under share/seeded-pages/, and the shipped helper scripts live under share/private-cli/, so neither bookmark bodies nor helper script bodies are embedded directly in the command script. Installed copies resolve the same seeded pages and helper assets from the distribution share directory, so d2 init works after a cpanm install and not just from a source checkout.

Those helper-backed built-ins also rewrite their live process title to developer-dashboard ..., so process listings stay aligned with the public command names instead of exposing the staged helper path.

When d2 re-execs a Perl-backed helper or hook, it also forces the same active dashboard lib/ root into that child Perl process. That keeps thin switchboard handoff on the current checkout code instead of drifting onto an older installed Developer::Dashboard copy that may also be visible in PERL5LIB.

d2 cpan <Module...> installs optional Perl modules into the active runtime-local ./.developer-dashboard/local tree and appends matching requires 'Module'; lines to ./.developer-dashboard/cpanfile.

The command stays implemented in the d2 entrypoint rather than introducing a separate CPAN manager product module, and saved Ajax workers infer the same runtime-local local/lib/perl5 path directly from the active runtime root. When the requested modules include DBD::*, the command also installs and records DBI automatically so generic database driver requests work with a single command.

A terminal session: d2 serve with the editor integrations off reports the running app as a status document listing the housekeeper, demo.clock and demo.disk collectors with their process ids, host 0.0.0.0, port 7890 and one worker.

d2 serve reports the running app: its process, its port, and the collectors it supervises.

A terminal session: d2 doctor prints its audit as a document with ok true, an issue count of zero, and one entry per runtime root it checked.

d2 doctor audits the runtime and reports every root it checked; this run is clean.

SEE ALSO

Developer::Dashboard