@keepur/hive 0.5.1 → 0.5.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/service/deploy.sh +45 -12
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keepur/hive",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "hiveApi": "1.0.0",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/service/deploy.sh CHANGED
@@ -336,18 +336,28 @@ if $ROLLBACK; then
336
336
  # per service/install.sh). See KPR-63.
337
337
  label="com.hive.${id}.agent"
338
338
  instance_root=$(_instance_root "$id")
339
+ plist_path="$instance_root/service/$label.plist"
339
340
  echo "--- Rolling back $id (root: $instance_root) ---"
340
- # Stop LaunchAgent BEFORE rotating .hive/. Without -kp, launchd auto-respawns
341
- # mid-rollback and the restart picks up a partial state. Mirrors the deploy
342
- # loop's stop sequence at the main branch.
341
+ # Stop LaunchAgent BEFORE rotating .hive/. KPR-182: use bootout (true unload)
342
+ # rather than kickstart -kp kickstart is fundamentally a *start* operation,
343
+ # and KeepAlive auto-respawns the service mid-rollback otherwise.
343
344
  echo " Stopping $label..."
344
- run_cmd launchctl kickstart -kp "gui/$(id -u)/$label" 2>/dev/null || true
345
- kill_ports "$ports"
345
+ run_cmd launchctl bootout "gui/$(id -u)/$label" 2>/dev/null || true
346
+ # Wait for ports to release (KeepAlive can't fire — service is unloaded).
347
+ if ! $DRY_RUN; then
348
+ for port in $ports; do
349
+ for _ in $(seq 1 10); do
350
+ if ! lsof -i :"$port" -t >/dev/null 2>&1; then break; fi
351
+ sleep 0.5
352
+ done
353
+ done
354
+ fi
355
+ kill_ports "$ports" # defensive — catches anything bound elsewhere
346
356
  if ! rollback_engine "$instance_root"; then
347
357
  notify "Rollback FAILED for \`$id\`: no previous engine (.hive.prev missing)."
348
358
  exit 1
349
359
  fi
350
- run_cmd launchctl kickstart -k "gui/$(id -u)/$label"
360
+ run_cmd launchctl bootstrap "gui/$(id -u)" "$plist_path"
351
361
  if health_check "$instance_root/$logs_dir/hive.log"; then
352
362
  rollback_version=$(jq -r .version < "$instance_root/.hive/package.json" 2>/dev/null || echo "unknown")
353
363
  notify "Rollback succeeded for \`$id\` → \`$rollback_version\`."
@@ -460,6 +470,7 @@ for inst in "${INSTANCES[@]}"; do
460
470
  # --tag override > per-instance engine_tag > "latest"
461
471
  tag="${OVERRIDE_TAG:-${engine_tag:-latest}}"
462
472
  instance_root=$(_instance_root "$id")
473
+ plist_path="$instance_root/service/$label.plist"
463
474
 
464
475
  echo ""
465
476
  echo "--- Phase 2: Deploy instance '$id' @ $tag (root: $instance_root) ---"
@@ -467,15 +478,26 @@ for inst in "${INSTANCES[@]}"; do
467
478
 
468
479
  mkdir -p "$instance_root/$logs_dir"
469
480
 
481
+ # KPR-182: bootout (true unload) so KeepAlive can't auto-respawn the old
482
+ # engine during fetch/install/swap. kickstart is a *start* operation — the
483
+ # `-k` flag merely kills-then-restarts, leaving the plist loaded.
470
484
  echo " Stopping $label..."
471
- run_cmd launchctl kickstart -kp "gui/$(id -u)/$label" 2>/dev/null || true
472
- kill_ports "$ports"
485
+ run_cmd launchctl bootout "gui/$(id -u)/$label" 2>/dev/null || true
486
+ if ! $DRY_RUN; then
487
+ for port in $ports; do
488
+ for _ in $(seq 1 10); do
489
+ if ! lsof -i :"$port" -t >/dev/null 2>&1; then break; fi
490
+ sleep 0.5
491
+ done
492
+ done
493
+ fi
494
+ kill_ports "$ports" # defensive — catches anything bound elsewhere
473
495
 
474
496
  echo " Fetching engine..."
475
497
  if ! fetch_engine "$instance_root" "$tag"; then
476
498
  notify "Deploy FAILED for \`$id\`: fetch_engine errored at tag \`$tag\`."
477
499
  FAILED_INSTANCES+=("$id")
478
- run_cmd launchctl kickstart -k "gui/$(id -u)/$label" || true # bring old engine back up
500
+ run_cmd launchctl bootstrap "gui/$(id -u)" "$plist_path" || true # bring old engine back up
479
501
  continue
480
502
  fi
481
503
 
@@ -484,7 +506,7 @@ for inst in "${INSTANCES[@]}"; do
484
506
  notify "Deploy FAILED for \`$id\`: install_engine_deps errored at tag \`$tag\`."
485
507
  FAILED_INSTANCES+=("$id")
486
508
  rm -rf "$instance_root/.hive.next"
487
- run_cmd launchctl kickstart -k "gui/$(id -u)/$label" || true # bring old engine back up
509
+ run_cmd launchctl bootstrap "gui/$(id -u)" "$plist_path" || true # bring old engine back up
488
510
  continue
489
511
  fi
490
512
 
@@ -492,13 +514,24 @@ for inst in "${INSTANCES[@]}"; do
492
514
  swap_engine "$instance_root"
493
515
 
494
516
  echo " Restarting $label..."
495
- run_cmd launchctl kickstart -k "gui/$(id -u)/$label"
517
+ run_cmd launchctl bootstrap "gui/$(id -u)" "$plist_path"
496
518
 
497
519
  echo " Checking health..."
498
520
  if ! health_check "$instance_root/$logs_dir/hive.log"; then
499
521
  echo " Health check FAILED for $id — rolling back"
522
+ # New engine bound the port and failed health check — bootout it before swap.
523
+ run_cmd launchctl bootout "gui/$(id -u)/$label" 2>/dev/null || true
524
+ if ! $DRY_RUN; then
525
+ for port in $ports; do
526
+ for _ in $(seq 1 10); do
527
+ if ! lsof -i :"$port" -t >/dev/null 2>&1; then break; fi
528
+ sleep 0.5
529
+ done
530
+ done
531
+ fi
532
+ kill_ports "$ports"
500
533
  if rollback_engine "$instance_root"; then
501
- run_cmd launchctl kickstart -k "gui/$(id -u)/$label"
534
+ run_cmd launchctl bootstrap "gui/$(id -u)" "$plist_path"
502
535
  notify "Deploy rolled back for \`$id\`: \`$tag\` failed health check, restored previous version."
503
536
  else
504
537
  notify "Deploy FAILED for \`$id\` and auto-rollback unavailable (.hive.prev missing). Manual intervention required."