In the DSH Web development workflow, stopping or restarting the server usually requires terminal operations, which can interrupt the current browser session or lose port context. The dsh-web-lifecycle plugin solves this problem by providing direct interactive buttons at the bottom of the sidebar.

Plugin Overview

This is a DSH Web plugin maintained by DDA-DIGITAL. It adds “Restart” and “Shutdown” buttons to the bottom of the sidebar. The plugin does not depend on any runtime libraries and uses only built-in Node.js modules. If the current environment does not support it (for example, if webServer or appExit is missing), the plugin remains silent and does not affect the host.

Core Features

  1. Restart: Keeps the same port and session (cookie permissions unchanged), and supports running standalone or through the dshweb wrapper. Restarting interrupts all current active tasks.
  2. Shutdown: Stops the server and closes the tab. If browser restrictions (such as a regular tab) prevent automatic closing, a full-screen notification card is displayed.

Installation and Enablement

Install the plugin with the following command:

dsh plugin --profile web add github:DDA-DIGITAL/dsh-web-lifecycle

After installation, restart dsh web to load the host-side components and refresh the page to load the client-side components.

Typical Usage

Restart

Restart has two operating modes, depending on whether the dshweb wrapper is used:

  • dshweb wrapper: The plugin exits with code 75. After detecting this code, the wrapper restarts the server and reloads the page in about 1 second.
  • Standalone mode: The plugin spawns a coordinator process that watches for the port to become free and waits for the new server’s health check. Logs are written to $DSH_HOME/plugins-data/dsh-web-lifecycle/restart.log.

Shutdown

The plugin exits with code 0, ensuring that the wrapper stops its restart loop. The page attempts to call window.close() to close the tab. Due to browser security restrictions, window.close() only works for windows opened by scripts. In a normal browser tab, this method fails and the page displays a full-screen notification card.

Configuration

Default configuration is located in the plugin’s cordis.patch.yml entry and can be overridden by $DSH_HOME/profiles/web/cordis.patch.yml. Key configuration options include:

  • confirm: Whether to show a confirmation dialog before performing an operation (default: true).
  • allowShutdown: Whether to show the Shutdown button (default: true).
  • healthTimeoutMs: Timeout for waiting for the new server’s health check in standalone mode (default: 30000 milliseconds).
  • logToConsole: Whether to output the plugin’s decision logs to the dsh web logs (default: true).

Notes

  • Browser restrictions: window.close() does not work in a normal browser tab; you must close it manually using a keyboard shortcut.
  • Daemons: Shutdown only stops the process. System-level daemons (such as launchd/systemd/pm2) might restart it. The plugin itself does not handle this scenario.
  • Session interruption: Both restarting and shutting down interrupt all currently active tasks, subagents, and background jobs.
  • Activation verification: If the buttons are not displayed, run dsh --profile web --dump-config to confirm that web-lifecycle is listed, and ensure that dsh web has been restarted.

The plugin interacts with the DSH environment using an Exit Code protocol (75 = restart, 0 = shutdown), simplifying server management from the Web side. For more details, visit GitHub.