dsh-restart: One-Click Restart and Verifiable Evidence for the DSH Process

DSH maintains hot listening for profile configurations. Adding or removing a bundle mounts it immediately, making the tool instantly available. However, hmr defaults to listening only to configurations, not source code modules. Changes to the source code of already-mounted plugins will not take effect, requiring a restart. Restarting DSH implies disconnecting current browser connections, and if the restart fails, the service might never come back up. dsh-restart turns this into a single tool call, guaranteeing two things: a graceful exit and confirmation before exiting that “someone will bring it back up.”

Plugin Introduction

dsh-restart is a DSH plugin maintained by ajia1206 under the MIT license. It provides one-click restart capabilities for running DSH processes, featuring launchd supervision detection, verifiable restart logs, and a GUI control in the bottom right corner.

Core Capabilities

Graceful Exit and Supervision Detection

The plugin detects what is supervising it and determines the exit strategy accordingly:

  1. Desktop Strategy: Identified as the macOS Desktop version (has a main process and IPC connection); it performs the exit/reopen cycle via the macOS application.
  2. Launchd Strategy: If the current process is the main process of the launchctl job and KeepAlive is unconditionally enabled (conditional policies are not recognized), it directly calls ctx.appExit(0) for a graceful exit.
  3. Supervisor Strategy: If there is no confirmable KeepAlive supervision (e.g., manually started, or the parent process does not exit along with it), it spawns a detached supervisor. The supervisor writes a record before being killed and writes supervisor-ready after passing a recovery resource pre-check. The plugin must wait until both records are present before allowing itself to exit; if it waits for more than 8 seconds, it aborts.
  4. None Strategy: If there is no supervision and superviseFallback=false, the restart is rejected.

Verifiable Restart Logs

Restart logs are recorded in JSONL format at <home>/.dsh/logs/dsh-restart.log with 0600 permissions. Key record types include:
* boot: Written when the plugin is ready, containing pid/ppid/mode/port/profile.
* armed: Written when a restart is scheduled, containing armId, fireAt, and the reason.
* supervisor / supervisor-ready: Supervisor handshake status.
* exiting / supervised: Exit process and spawn results.
* cancelled / aborted: Cancelled or aborted status.

GUI Control and Authentication

The web interface features a floating “↻ Restart” button in the bottom right corner that displays the supervision mode, port, and downtime duration. It supports delay selection and reason entry. The control sits on the shell.overlay slot and is click-through.

Regarding authentication, the registered route itself does not carry authentication middleware but strictly accepts only loopback sources (127.0.0.0/8, ::1, ::ffff:127.x). Non-loopback requests are met with a 403. This is to prevent accidental harm from external requests forwarded by reverse proxies.

Installation

Please check the source code and license before installing.

dsh plugin --profile web add github:ajia1206/dsh-restart

Typical Usage

The plugin provides three command-line tools and one browser control, all sharing the same underlying implementation.

  1. dsh_restart [delaySeconds] [reason] [dryRun]
    Schedules a restart. The default delay is 10 seconds, allowing tool results to reach the browser first. dryRun only shows the plan without scheduling.
  2. dsh_restart_status
    Views the supervision mode, whether a restart is currently scheduled, and the restart history. This serves as a verification method to calculate downtime.
  3. dsh_restart_cancel
    Cancels a restart before it is triggered.
  4. Browser Floating Button (Bottom Right)
    Click the floating button to restart, requiring confirmation via a popup.

Configuration

The plugin relies on the cordis.patch.yml patch, and path configurations must use absolute paths (~ or environment variables are not expanded).

- id: dsh-restart
  name: dsh-restart
  config:
    logPath: /absolute/path/.dsh/logs/dsh-restart.log
    childLogPath: /absolute/path/.dsh/logs/dsh-restart-child.log
    defaultDelaySeconds: 10
    maxDelaySeconds: 600
    superviseFallback: true
    trustParentJob: false
    healthUrl: ''
    healthTimeoutMs: 60000
    healthIntervalMs: 500
    exitTimeoutMs: 45000
    bootHistoryLimit: 5

Notes

  • Not Published to npm: The name dsh-restart is already taken on npm. This package is installed via the tgz from GitHub Releases.
  • Absolute Paths: logPath and childLogPath must be absolute paths. Using ~ will create a directory named ~ in the current directory.
  • Authentication Note: Only loopback sources are accepted. If the host lacks a connection service, external requests (even from a local reverse proxy) will be rejected with a 403.
  • Duplicate Instances: The Supervisor cannot prove that someone else (launchd, manual operation, etc.) hasn’t already started it, so there may be instances where two run simultaneously.
  • Permissions: Restart logs are created with 0600 permissions, but the supervisor’s child process log childLogPath is created with default system permissions.

dsh-restart | Catalog Page

羽毛球分组比赛记分
小程序二维码

欢迎使用《羽毛球分组比赛记分》微信小程序

Xiaoye