@pkkkkh/dsh-restart 0.0.0-stage → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/timings.js ADDED
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Pure timing helpers for dsh-restart.
3
+ *
4
+ * Kept free of any @deepseek-ai imports so `node --test` can run without the
5
+ * host profile (the plugin's index.js does import the host modules).
6
+ *
7
+ * @module dsh-restart/timings
8
+ */
9
+
10
+ export const DEFAULT_KILL_SECONDS = 45;
11
+ export const DEFAULT_START_GAP_SECONDS = 11;
12
+ export const MIN_KILL_SECONDS = 20;
13
+ export const MAX_KILL_SECONDS = 600;
14
+
15
+ /**
16
+ * Clamp a requested delay and derive the start-task delay.
17
+ *
18
+ * Rules (mirrors the PowerShell side, which clamps again):
19
+ * - non-numeric / <= 0 → fall back to the default
20
+ * - clamp to [20, 600] seconds
21
+ * - start always runs `startGapSeconds` (default 11s) after kill
22
+ *
23
+ * @param {unknown} requested delay in seconds, as passed by the tool caller
24
+ * @param {{ defaultKillSeconds?: number, startGapSeconds?: number }} [options]
25
+ * @returns {{ killSeconds: number, startSeconds: number }}
26
+ */
27
+ export function resolveTimings(requested, options = {}) {
28
+ const fallback = Number.isFinite(Number(options.defaultKillSeconds))
29
+ ? Number(options.defaultKillSeconds)
30
+ : DEFAULT_KILL_SECONDS;
31
+ const gap = Number.isFinite(Number(options.startGapSeconds))
32
+ ? Math.max(1, Math.round(Number(options.startGapSeconds)))
33
+ : DEFAULT_START_GAP_SECONDS;
34
+
35
+ const raw = Number(requested);
36
+ const base = Number.isFinite(raw) && raw > 0 ? raw : fallback;
37
+ const killSeconds = Math.min(MAX_KILL_SECONDS, Math.max(MIN_KILL_SECONDS, Math.round(base)));
38
+
39
+ return { killSeconds, startSeconds: killSeconds + gap };
40
+ }
41
+
42
+ /** Human-readable one-liner, also used in the tool result. */
43
+ export function describeTimings({ killSeconds, startSeconds }) {
44
+ return `kill at +${killSeconds}s, start at +${startSeconds}s`;
45
+ }
package/package.json CHANGED
@@ -1,6 +1,45 @@
1
1
  {
2
2
  "name": "@pkkkkh/dsh-restart",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.6",
4
+ "description": "Safe self-restart for DeepSeek Harness: arms a scheduled kill + start pair through the vetted restart scripts so an IM/Web session can restart the app itself.",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/pkkkkh/dsh-plugins-public.git",
11
+ "directory": "dsh-restart"
12
+ },
13
+ "keywords": [
14
+ "deepseek-harness",
15
+ "dsh",
16
+ "plugin",
17
+ "restart",
18
+ "dsh-plugin"
19
+ ],
20
+ "engines": {
21
+ "node": "^22.19.0 || >=24.0.0",
22
+ "dsh": ">=0.2.1-rc.2 <0.3.0-0"
23
+ },
24
+ "dsh": {
25
+ "manifestVersion": 1,
26
+ "bundle": {
27
+ "patch": "./cordis.patch.yml"
28
+ }
29
+ },
30
+ "peerDependencies": {
31
+ "@deepseek-ai/cordis": "^4.0.1",
32
+ "@deepseek-ai/dsh-tools": ">=0.1.0-rc.6 <0.3.0-0",
33
+ "@deepseek-ai/schemastery": "^3.18.1"
34
+ },
35
+ "files": [
36
+ "lib",
37
+ "scripts",
38
+ "cordis.patch.yml",
39
+ "README.md",
40
+ "LICENSE"
41
+ ],
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
6
45
  }
@@ -0,0 +1,53 @@
1
+ # Inspect or cancel the scheduled tasks used by dsh-restart.
2
+ # -Action status : print "NAME=STATE" per known task, "-" when not registered
3
+ # -Action cancel : unregister every known task, print what was removed
4
+ #
5
+ # Task names cover both families:
6
+ # DSH-Restart-* : armed by restart-dsh-arm.ps1 / restart-dsh-arm2.ps1
7
+ # DSH-Maint-* : the 2026-11-10 maintenance window (one-off tasks)
8
+ #
9
+ # ASCII only: PowerShell 5.1 misreads BOM-less UTF-8, so no Chinese comments.
10
+
11
+ param(
12
+ [ValidateSet("status", "cancel")]
13
+ [string]$Action = "status"
14
+ )
15
+
16
+ $ErrorActionPreference = "Continue"
17
+ $names = @(
18
+ "DSH-Restart-Start",
19
+ "DSH-Restart-Kill",
20
+ "DSH-Restart-Watchdog",
21
+ "DSH-Maint-Start",
22
+ "DSH-Maint-Kill",
23
+ "DSH-Maint-Watchdog"
24
+ )
25
+
26
+ if ($Action -eq "status") {
27
+ foreach ($n in $names) {
28
+ $t = Get-ScheduledTask -TaskName $n -ErrorAction SilentlyContinue
29
+ if ($t) {
30
+ $info = Get-ScheduledTaskInfo -TaskName $n -ErrorAction SilentlyContinue
31
+ $next = if ($info -and $info.NextRunTime) { $info.NextRunTime.ToString("yyyy-MM-dd HH:mm:ss") } else { "-" }
32
+ Write-Output ("{0}={1};next={2}" -f $n, $t.State, $next)
33
+ } else {
34
+ Write-Output ("{0}=-" -f $n)
35
+ }
36
+ }
37
+ exit 0
38
+ }
39
+
40
+ $removed = 0
41
+ foreach ($n in $names) {
42
+ $t = Get-ScheduledTask -TaskName $n -ErrorAction SilentlyContinue
43
+ if (-not $t) { continue }
44
+ try {
45
+ Unregister-ScheduledTask -TaskName $n -Confirm:$false -ErrorAction Stop
46
+ Write-Output ("removed " + $n)
47
+ $removed += 1
48
+ } catch {
49
+ Write-Output ("failed " + $n + ": " + $_.Exception.Message)
50
+ }
51
+ }
52
+ Write-Output ("removed_total=" + $removed)
53
+ exit 0
@@ -0,0 +1,61 @@
1
+ // dsh-watchdog.cjs — DSH 常驻看门狗(由 dsh-restart 插件拉起)。
2
+ // 机制:插件每 5s 写一次心跳文件;本脚本发现心跳超过 staleMs 没更新且没有
3
+ // 「重启中」标志,就用 vetted 的 start 脚本把 DSH 拉起来(冷却期内不重复拉)。
4
+ // 设计参考 anweat/dsh-restart 的看门狗思路(MIT),实现独立。
5
+ const fs = require('node:fs');
6
+ const path = require('node:path');
7
+ const { spawn } = require('node:child_process');
8
+
9
+ // 配置路径:优先取命令行第 1 个参数(插件传进来),退回脚本同目录。
10
+ const CFG_PATH = process.argv[2] || path.join(__dirname, 'dsh-watchdog.json');
11
+ const CFG = JSON.parse(fs.readFileSync(CFG_PATH, 'utf8'));
12
+
13
+ function log(msg) {
14
+ try { fs.appendFileSync(CFG.logFile, '[' + new Date().toISOString() + '] ' + msg + '\n', 'utf8'); } catch {}
15
+ }
16
+ function mtime(file) {
17
+ try { return fs.statSync(file).mtimeMs; } catch { return 0; }
18
+ }
19
+ function rm(file) { try { fs.unlinkSync(file); } catch {} }
20
+
21
+ try { fs.writeFileSync(CFG.pidFile, String(process.pid), 'utf8'); } catch {}
22
+ log('watchdog up pid=' + process.pid + ' poll=' + CFG.pollMs + 'ms stale=' + CFG.staleMs + 'ms cooldown=' + CFG.cooldownMs + 'ms');
23
+
24
+ let lastLaunch = 0;
25
+
26
+ const timer = setInterval(function () {
27
+ if (fs.existsSync(CFG.stopFlag)) {
28
+ log('stop flag found → exiting');
29
+ rm(CFG.pidFile);
30
+ clearInterval(timer);
31
+ process.exit(0);
32
+ }
33
+ const hb = mtime(CFG.heartbeat);
34
+ const age = hb ? Date.now() - hb : Number.MAX_SAFE_INTEGER;
35
+ if (hb && age < CFG.staleMs) return;
36
+
37
+ if (fs.existsSync(CFG.restartFlag)) {
38
+ const rAge = Date.now() - mtime(CFG.restartFlag);
39
+ if (rAge < CFG.cooldownMs) return; // 正在重启,别插手
40
+ rm(CFG.restartFlag); // 过期标志,清掉
41
+ }
42
+ if (Date.now() - lastLaunch < CFG.cooldownMs) return;
43
+
44
+ lastLaunch = Date.now();
45
+ try {
46
+ fs.writeFileSync(CFG.restartFlag, JSON.stringify({ at: new Date().toISOString(), by: 'watchdog' }), 'utf8');
47
+ } catch {}
48
+ log('heartbeat stale for ' + (hb ? Math.round(age / 1000) + 's' : 'ever') + ' → relaunching via ' + CFG.startScript);
49
+ try {
50
+ const child = spawn('powershell.exe', ['-NoProfile', '-ExecutionPolicy', 'Bypass', '-File', CFG.startScript], {
51
+ detached: true,
52
+ stdio: 'ignore',
53
+ windowsHide: true,
54
+ });
55
+ child.on('error', function (e) { log('spawn error: ' + String(e)); });
56
+ child.unref();
57
+ } catch (e) {
58
+ log('spawn threw: ' + String(e));
59
+ }
60
+ }, CFG.pollMs);
61
+
@@ -0,0 +1,76 @@
1
+ # Arms the two halves of a restart with second-level precision.
2
+ # start at now +56s : start DSH if it is not running
3
+ # kill at now +45s : taskkill DSH
4
+ #
5
+ # ORDER MATTERS: the START task is registered FIRST. If the KILL registration
6
+ # then fails we roll back and leave DSH untouched -- "kill registered, start
7
+ # missing" must never happen (that is how DSH gets lost for good).
8
+ #
9
+ # schtasks can only schedule whole minutes, hence PowerShell here.
10
+ # ASCII only: PowerShell 5.1 misreads BOM-less UTF-8, so no Chinese comments.
11
+ #
12
+ # Parameters (defaults keep restart-dsh.cmd behaviour unchanged):
13
+ # -KillAfterSeconds 20..600, kill task fires this many seconds from now
14
+ # -StartAfterSeconds start task fires this many seconds from now
15
+ # The START task is always registered first; see the ordering note below.
16
+
17
+ param(
18
+ [int]$KillAfterSeconds = 45,
19
+ [int]$StartAfterSeconds = 56
20
+ )
21
+
22
+ $ErrorActionPreference = "Stop"
23
+ $log = "C:\Users\YOURNAME\.dsh\im\logs\restart-dsh.log"
24
+ $root = "C:\Users\YOURNAME\.dsh\im\scripts"
25
+
26
+ function Write-Log([string]$msg) {
27
+ # A failed log write must never stop the restart from being armed.
28
+ try {
29
+ "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss.fff')] $msg" |
30
+ Out-File -Append -FilePath $log -Encoding utf8 -ErrorAction Stop
31
+ } catch {
32
+ Write-Verbose "log write failed: $($_.Exception.Message)"
33
+ }
34
+ }
35
+
36
+ $now = Get-Date
37
+ if ($KillAfterSeconds -lt 20) { $KillAfterSeconds = 20 }
38
+ if ($KillAfterSeconds -gt 600) { $KillAfterSeconds = 600 }
39
+ if ($StartAfterSeconds -le $KillAfterSeconds) { $StartAfterSeconds = $KillAfterSeconds + 11 }
40
+ $killAt = $now.AddSeconds($KillAfterSeconds)
41
+ $startAt = $now.AddSeconds($StartAfterSeconds)
42
+
43
+ try {
44
+ $user = [Security.Principal.WindowsIdentity]::GetCurrent().Name
45
+ $principal = New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive -RunLevel Limited
46
+ $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable
47
+ $startAction = New-ScheduledTaskAction -Execute (Join-Path $root "restart-dsh-fallback.cmd")
48
+ $startTrigger = New-ScheduledTaskTrigger -Once -At $startAt
49
+ $killAction = New-ScheduledTaskAction -Execute (Join-Path $root "restart-dsh-kill.cmd")
50
+ $killTrigger = New-ScheduledTaskTrigger -Once -At $killAt
51
+ } catch {
52
+ Write-Log ("ARM-FAIL: cannot build task objects: " + $_.Exception.Message)
53
+ exit 1
54
+ }
55
+
56
+ $registered = @()
57
+ try {
58
+ Register-ScheduledTask -TaskName "DSH-Restart-Start" -Action $startAction -Trigger $startTrigger `
59
+ -Settings $settings -Principal $principal -Force | Out-Null
60
+ $registered += "DSH-Restart-Start"
61
+ Register-ScheduledTask -TaskName "DSH-Restart-Kill" -Action $killAction -Trigger $killTrigger `
62
+ -Settings $settings -Principal $principal -Force | Out-Null
63
+ $registered += "DSH-Restart-Kill"
64
+ } catch {
65
+ $message = $_.Exception.Message
66
+ foreach ($name in $registered) {
67
+ try { Unregister-ScheduledTask -TaskName $name -Confirm:$false -ErrorAction Stop | Out-Null } catch { }
68
+ }
69
+ Write-Log ("ARM-FAIL: " + $message)
70
+ Write-Log "ARM-FAIL: rolled back, DSH left untouched"
71
+ exit 1
72
+ }
73
+
74
+ Write-Log ("arming restart: kill at {0:HH:mm:ss}, start at {1:HH:mm:ss}" -f $killAt, $startAt)
75
+ Write-Log "tasks registered (start first, then kill)"
76
+ exit 0
@@ -0,0 +1,111 @@
1
+ # Extended arm script for planned MAINTENANCE restarts (2026-11-10).
2
+ #
3
+ # Why a second file instead of editing restart-dsh-arm.ps1: that one is the
4
+ # long-verified path (11-08 building, 11-09 hardening) and stays untouched.
5
+ # This file is a strict superset used only when a caller needs a custom
6
+ # "start half" or a third watchdog task.
7
+ #
8
+ # start at now +56s : custom -StartScript, or restart-dsh-fallback.cmd
9
+ # kill at now +45s : taskkill DSH (always restart-dsh-kill.cmd)
10
+ # watchdog at now +N s : optional, brings DSH up if it is STILL down
11
+ #
12
+ # ORDER: start registered FIRST, then kill, then watchdog. Any registration
13
+ # failure rolls back everything so DSH is never left killed with no start half.
14
+ #
15
+ # Huorong HIPS kills the killer right after taskkill, so the start half MUST be
16
+ # a separate task -- that is exactly why -StartScript exists (e.g. a cmd that
17
+ # runs pnpm install and then calls restart-dsh-start.ps1).
18
+ #
19
+ # Parameters:
20
+ # -KillAfterSeconds 20..600
21
+ # -StartAfterSeconds > kill, clamped to kill+11 at least
22
+ # -StartScript optional path to the start-half cmd
23
+ # -WatchAfterSeconds 0 = off, else >= start+60, max 1800
24
+ #
25
+ # ASCII only: PowerShell 5.1 misreads BOM-less UTF-8, so no Chinese comments.
26
+
27
+ param(
28
+ [int]$KillAfterSeconds = 45,
29
+ [int]$StartAfterSeconds = 56,
30
+ [string]$StartScript = "",
31
+ [int]$WatchAfterSeconds = 0
32
+ )
33
+
34
+ $ErrorActionPreference = "Stop"
35
+ $log = "C:\Users\YOURNAME\.dsh\im\logs\restart-dsh.log"
36
+ $root = "C:\Users\YOURNAME\.dsh\im\scripts"
37
+
38
+ function Write-Log([string]$msg) {
39
+ try {
40
+ "[$(Get-Date -Format 'yyyy-MM-dd HH:mm:ss.fff')] $msg" |
41
+ Out-File -Append -FilePath $log -Encoding utf8 -ErrorAction Stop
42
+ } catch {
43
+ Write-Verbose "log write failed: $($_.Exception.Message)"
44
+ }
45
+ }
46
+
47
+ $now = Get-Date
48
+ if ($KillAfterSeconds -lt 20) { $KillAfterSeconds = 20 }
49
+ if ($KillAfterSeconds -gt 600) { $KillAfterSeconds = 600 }
50
+ if ($StartAfterSeconds -le $KillAfterSeconds) { $StartAfterSeconds = $KillAfterSeconds + 11 }
51
+
52
+ $startFile = Join-Path $root "restart-dsh-fallback.cmd"
53
+ if ($StartScript -and $StartScript.Trim().Length -gt 0) { $startFile = $StartScript.Trim() }
54
+ if (-not (Test-Path -LiteralPath $startFile)) {
55
+ Write-Log ("ARM-FAIL: start script not found: " + $startFile)
56
+ exit 1
57
+ }
58
+
59
+ $useWatchdog = $WatchAfterSeconds -gt 0
60
+ if ($useWatchdog) {
61
+ if ($WatchAfterSeconds -lt ($StartAfterSeconds + 60)) { $WatchAfterSeconds = $StartAfterSeconds + 60 }
62
+ if ($WatchAfterSeconds -gt 1800) { $WatchAfterSeconds = 1800 }
63
+ }
64
+
65
+ $killAt = $now.AddSeconds($KillAfterSeconds)
66
+ $startAt = $now.AddSeconds($StartAfterSeconds)
67
+ $watchAt = $now.AddSeconds($WatchAfterSeconds)
68
+
69
+ try {
70
+ $user = [Security.Principal.WindowsIdentity]::GetCurrent().Name
71
+ $principal = New-ScheduledTaskPrincipal -UserId $user -LogonType Interactive -RunLevel Limited
72
+ $settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable
73
+ $startAction = New-ScheduledTaskAction -Execute $startFile
74
+ $startTrigger = New-ScheduledTaskTrigger -Once -At $startAt
75
+ $killAction = New-ScheduledTaskAction -Execute (Join-Path $root "restart-dsh-kill.cmd")
76
+ $killTrigger = New-ScheduledTaskTrigger -Once -At $killAt
77
+ $watchAction = New-ScheduledTaskAction -Execute (Join-Path $root "restart-dsh-watchdog.cmd")
78
+ $watchTrigger = New-ScheduledTaskTrigger -Once -At $watchAt
79
+ } catch {
80
+ Write-Log ("ARM-FAIL: cannot build task objects: " + $_.Exception.Message)
81
+ exit 1
82
+ }
83
+
84
+ $registered = @()
85
+ try {
86
+ Register-ScheduledTask -TaskName "DSH-Restart-Start" -Action $startAction -Trigger $startTrigger `
87
+ -Settings $settings -Principal $principal -Force | Out-Null
88
+ $registered += "DSH-Restart-Start"
89
+ Register-ScheduledTask -TaskName "DSH-Restart-Kill" -Action $killAction -Trigger $killTrigger `
90
+ -Settings $settings -Principal $principal -Force | Out-Null
91
+ $registered += "DSH-Restart-Kill"
92
+ if ($useWatchdog) {
93
+ Register-ScheduledTask -TaskName "DSH-Restart-Watchdog" -Action $watchAction -Trigger $watchTrigger `
94
+ -Settings $settings -Principal $principal -Force | Out-Null
95
+ $registered += "DSH-Restart-Watchdog"
96
+ }
97
+ } catch {
98
+ $message = $_.Exception.Message
99
+ foreach ($name in $registered) {
100
+ try { Unregister-ScheduledTask -TaskName $name -Confirm:$false -ErrorAction Stop | Out-Null } catch { }
101
+ }
102
+ Write-Log ("ARM-FAIL: " + $message)
103
+ Write-Log "ARM-FAIL: rolled back, DSH left untouched"
104
+ exit 1
105
+ }
106
+
107
+ Write-Log ("arming MAINT restart: kill at {0:HH:mm:ss}, start at {1:HH:mm:ss}" -f $killAt, $startAt)
108
+ if ($useWatchdog) { Write-Log ("watchdog at {0:HH:mm:ss}" -f $watchAt) }
109
+ Write-Log ("start half: " + $startFile)
110
+ Write-Log "tasks registered (start first, then kill, then watchdog)"
111
+ exit 0
@@ -0,0 +1,95 @@
1
+ # Starts DSH detached from whatever console called us, and verifies the app
2
+ # actually STAYS up: a process that appears and then crashes (the desktop
3
+ # "Web authentication failed" startup crash, seen 2026-11-09 15:48-16:14) must
4
+ # NOT be reported as "up".
5
+ #
6
+ # History:
7
+ # 1) `start "" "...DeepSeek Harness.exe"` inherited cmd's console -> the window
8
+ # stayed alive and closing it killed DSH (2026-11-08 21:59).
9
+ # 2) Win32_Process.Create (WMI) fixed the console issue, but the WMI-launched
10
+ # instance crashed at 22:13 (crash-main.log: connect UNKNOWN 127.0.0.1:64297)
11
+ # -- a WMI-created process gets a different environment block than a normal
12
+ # shell launch, which this app does not survive.
13
+ # 3) Now: launch through explorer.exe first (same as a double-click: no console,
14
+ # normal user environment). WMI stays as a last resort.
15
+ #
16
+ # Exit codes: 0 = process up and survived the confirmation window; 1 = gave up.
17
+ # ASCII only: PowerShell 5.1 misreads BOM-less UTF-8.
18
+
19
+ $ErrorActionPreference = "Continue"
20
+ $exe = "D:\DSH\DeepSeek Harness.exe"
21
+
22
+ if (-not (Test-Path -LiteralPath $exe)) {
23
+ " START: exe not found: $exe"
24
+ exit 1
25
+ }
26
+
27
+ function Count-Dsh {
28
+ @(Get-Process -Name "DeepSeek Harness" -ErrorAction SilentlyContinue).Count
29
+ }
30
+
31
+ function Wait-ForProcess([int]$seconds) {
32
+ for ($i = 0; $i -lt $seconds; $i++) {
33
+ Start-Sleep -Seconds 1
34
+ if ((Count-Dsh) -gt 0) { return $true }
35
+ }
36
+ return $false
37
+ }
38
+
39
+ # The process appearing is not enough: today's failure mode is "appears, then
40
+ # dies within seconds". Wait, then check it is still there.
41
+ function Confirm-StaysUp([int]$seconds) {
42
+ Start-Sleep -Seconds $seconds
43
+ return ((Count-Dsh) -gt 0)
44
+ }
45
+
46
+ function Launch-Explorer {
47
+ " START: launching via explorer.exe"
48
+ Start-Process -FilePath "$env:WINDIR\explorer.exe" -ArgumentList ('"' + $exe + '"')
49
+ }
50
+
51
+ function Launch-Wmi {
52
+ " START: trying WMI create"
53
+ try {
54
+ $r = Invoke-CimMethod -ClassName Win32_Process -MethodName Create -Arguments @{
55
+ CommandLine = ('"' + $exe + '"')
56
+ }
57
+ " START: WMI create rc=$($r.ReturnValue) pid=$($r.ProcessId)"
58
+ } catch {
59
+ " START: WMI create failed: $($_.Exception.Message)"
60
+ }
61
+ }
62
+
63
+ function Bring-Up([int]$waitSeconds) {
64
+ if (-not (Wait-ForProcess $waitSeconds)) {
65
+ Launch-Wmi
66
+ if (-not (Wait-ForProcess 12)) { return $false }
67
+ }
68
+ return $true
69
+ }
70
+
71
+ # Attempt 1
72
+ Launch-Explorer
73
+ if (-not (Bring-Up 15)) {
74
+ " START: gave up, DSH never came up"
75
+ exit 1
76
+ }
77
+ if (Confirm-StaysUp 20) {
78
+ " START: DSH is up and stayed up"
79
+ exit 0
80
+ }
81
+
82
+ # Attempt 2: only after a startup crash (process is already gone)
83
+ " START: DSH exited within 20s after launch, retrying once"
84
+ Launch-Explorer
85
+ if (-not (Bring-Up 15)) {
86
+ " START: gave up (retry), DSH never came up"
87
+ exit 1
88
+ }
89
+ if (Confirm-StaysUp 20) {
90
+ " START: DSH is up after retry and stayed up"
91
+ exit 0
92
+ }
93
+
94
+ " START: gave up, DSH keeps exiting at startup"
95
+ exit 1