DSH Self-Restart Plugin: turn “privileged kill process tree → port release confirmation → service startup → liveness detection” into a reusable capability, and enable automatic frontend recovery.
Introduction¶
DSH’s host runs inside the process, and plugin or configuration updates usually require a process restart. Because the DSH process often runs in a privileged context, a regular-privilege Stop-Process cannot terminate it and fails silently. This plugin registers an elevated scheduled task to force-kill the process tree, then restarts the service and performs liveness detection, working with the frontend mechanism to achieve seamless automatic recovery for users.
Core Capabilities¶
- Privileged Restart: registers a one-time scheduled task via
schtasks /rl HIGHEST, then executestaskkill /F /Tin a privileged context to kill the process tree listening on the port. - Frontend Automatic Recovery: automatically refreshes the page after the service recovers, with minimal user impact.
- Auto-Discovery Resume: scans in-memory agents, session log mtimes, and background jobs before restart; automatically resumes with staggered timing after restart.
- Business Gate · Anti-Self-Trigger Loop: compares wake time with business input time to prevent self-inspection loops from triggering themselves.
- Task Ledger: supports manually adding, completing, and listing tasks, and records sessionId.
- Dry-Run Scan: provides a
scanmethod that only discovers without registering, used for verification.
API and Usage¶
The plugin provides an HTTP interface for external calls. The main methods are as follows:
ping: liveness check, returns{ok, t, pending}.status: views the current pending restart and configuration.schedule: schedules a restart (loopback access only).scan: dry-run auto-discovery (view only, no registration).task.add/task.done/task.list: manual task ledger operations.
Trigger Restart¶
Trigger a restart with a POST request:
POST http://127.0.0.1:3080/__dsh-restart/api
Content-Type: application/json
{
"method": "schedule",
"args": {
"delayMs": 15000,
"reason": "host 插件更新"
}
}
PowerShell example:
Invoke-RestMethod http://127.0.0.1:3080/__dsh-restart/api -Method Post -ContentType 'application/json' -Body '{"method":"schedule","args":{"delayMs":15000,"reason":"host 插件更新"}}'
Configuration¶
The configuration file is located at ~/.dsh/self-restart/config.json:
{
"port": 3080,
"startTask": "dsh-web-service",
"delaySec": 12,
"autoResume": true,
"activeWindowMs": 900000,
"maxAutoRegister": 12,
"maxAutoResume": 5,
"staggerMs": 8000,
"excludeSessions": []
}
port: DSH listening port (used to locate the process to kill).startTask: Windows scheduled task name used to start DSH.delaySec: default delay in seconds.autoResume: whether to enable auto-discovery resume.activeWindowMs: session log activity window time (default 15 minutes).maxAutoResume: upper limit for auto-resume tasks (default 5).staggerMs: staggered resume interval (default 8 seconds).
Installation and Enablement¶
Install:
npm i dsh-self-restart
Enable:
Copy the package directory into the profile’s node_modules\dsh-self-restart\, add "dsh-self-restart" to dsh.profile.bundles in the profile’s package.json, and restart DSH.
Notes¶
- Environment Dependency: Windows only.
- Permission Requirement: the
scheduleendpoint is restricted to loopback access (127.0.0.1/::1) to prevent accidental remote invocation. - Service Dependency: requires a preconfigured start task (default
dsh-web-service). - License: MIT