dsh-ris-ide 1.8.6 → 1.8.7

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.
@@ -64,16 +64,6 @@ printf -- '--- %s started %s ---\n' "$log_name" "$(date -Is 2>/dev/null || date)
64
64
  printf 'LOG_FILE=%s\n' "$log_file"
65
65
  printf -- '--- command: %s ---\n' "$*" >>"$log_file"
66
66
 
67
- # Start the service in the background so we know ITS pid, and mirror its output
68
- # through tee. The pidfile next to the log is what the plugin's stop button
69
- # reads — one line: "<servicePid> <wrapperPid> <epochMs>".
70
- "$@" > >(tee -a "$log_file") 2>&1 &
71
- child=$!
72
- pid_file="$log_file.pid"
73
- # 4th field (optional): the stop grace the host should honor, so a per-program
74
- # `stopGraceMs` from the generated config survives until the stop happens.
75
- printf '%s %s %s %s\n' "$child" "$$" "$(date +%s%3N 2>/dev/null || echo 0)" "${DSH_STOP_GRACE_MS:-}" >"$pid_file"
76
-
77
67
  # The plugin signals THIS wrapper (never the service directly). A plain
78
68
  # `kill $child` is not enough for dev servers: the child is usually a runner
79
69
  # (`bash -lc ... && exec pnpm run dev`) and pnpm does NOT forward SIGTERM, so the
@@ -116,9 +106,37 @@ on_signal() {
116
106
  }
117
107
  trap on_signal TERM INT
118
108
 
109
+ # Start the service in the background so we know ITS pid, and mirror its output
110
+ # through tee. The pidfile next to the log is what the plugin's stop button
111
+ # reads — one line: "<servicePid> <wrapperPid> <epochMs>".
112
+ #
113
+ # The trap is installed BEFORE the pidfile is published: the stop route reads the
114
+ # pidfile and signals immediately, and a TERM that arrives before `trap` kills
115
+ # bash outright — the child is orphaned, the banner never lands, and the host
116
+ # waits out its whole grace watching a pidfile nobody will ever remove.
117
+ "$@" > >(tee -a "$log_file") 2>&1 &
118
+ child=$!
119
+ pid_file="$log_file.pid"
120
+ # 4th field (optional): the stop grace the host should honor, so a per-program
121
+ # `stopGraceMs` from the generated config survives until the stop happens.
122
+ # Written to a temp name and renamed: a reader (the host's start/stop polls)
123
+ # must never see a half-written or empty pidfile the moment it appears.
124
+ pid_tmp="$pid_file.tmp.$$"
125
+ printf '%s %s %s %s\n' "$child" "$$" "$(date +%s%3N 2>/dev/null || echo 0)" "${DSH_STOP_GRACE_MS:-}" >"$pid_tmp"
126
+ mv -f "$pid_tmp" "$pid_file"
127
+
119
128
  wait "$child"
120
129
  status=$?
121
130
 
131
+ # A service that exits on its own is announced immediately: the pidfile means
132
+ # "there is a live service behind this log", and the start route polls it to tell
133
+ # "started" from "died instantly". On the stop path the pidfile stays until the
134
+ # group cleanup below is done, so a stop never looks finished while descendants
135
+ # (dev servers, grandchildren) are still being killed.
136
+ if [[ "$stopping" != "1" ]]; then
137
+ rm -f "$pid_file"
138
+ fi
139
+
122
140
  if [[ "$stopping" == "1" ]]; then
123
141
  for _ in $(seq 1 50); do
124
142
  kill -0 "$child" 2>/dev/null || break