nterminal 1.2.22 → 1.2.23

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.
@@ -480,6 +480,30 @@ wait_for_health() {
480
480
  return 1
481
481
  }
482
482
 
483
+ restart_supervised_child() {
484
+ local monitor_pid="$1"
485
+ local old_pid="${2:-}"
486
+
487
+ if [[ -n "$old_pid" ]]; then
488
+ stop_supervised_child "$old_pid"
489
+ fi
490
+
491
+ local pid=""
492
+ local deadline=$((SECONDS + HEALTH_TIMEOUT_SECONDS))
493
+ while (( SECONDS <= deadline )); do
494
+ if ! is_running "$monitor_pid"; then
495
+ return 1
496
+ fi
497
+ pid="$(current_pid || true)"
498
+ if [[ -n "$pid" && "$pid" != "$old_pid" ]] && wait_for_health "$pid"; then
499
+ info "NTerminal restarted pid=$pid supervisor=$monitor_pid url=$(public_url) log=$LOG_PATH"
500
+ return 0
501
+ fi
502
+ sleep 0.25
503
+ done
504
+ return 1
505
+ }
506
+
483
507
  port_owner_pid() {
484
508
  if command -v lsof >/dev/null 2>&1; then
485
509
  lsof -nP -iTCP:"$PORT" -sTCP:LISTEN -t 2>/dev/null | head -n 1
@@ -645,6 +669,20 @@ cmd_restart() {
645
669
  start_launchd
646
670
  else
647
671
  prepare_start
672
+ remove_stale_pid
673
+ remove_stale_monitor_pid
674
+ local monitor_pid
675
+ monitor_pid="$(current_monitor_pid || true)"
676
+ if [[ -n "$monitor_pid" ]]; then
677
+ local pid
678
+ pid="$(current_pid || true)"
679
+ if restart_supervised_child "$monitor_pid" "$pid"; then
680
+ return 0
681
+ fi
682
+ echo "NTerminal failed to restart under supervisor. Last log lines:" >&2
683
+ tail -n 40 "$LOG_PATH" >&2 || true
684
+ return 1
685
+ fi
648
686
  cmd_stop >/dev/null
649
687
  cmd_start
650
688
  fi