stop-dgx-services.sh 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #!/usr/bin/env bash
  2. # stop-dgx-services.sh — Stop non-essential services on a DGX node.
  3. # Frees unified memory for inference. Machine-specific (DGX), not model-
  4. # specific — safe to run before any large-model serve.
  5. #
  6. # Baked into the sm121 binary at compile time (see src/builtin_scripts.rs);
  7. # recipes reference it by alias `stop_dgx_services` in a `before_serve` /
  8. # `after_stop` list. The launcher uploads and runs it via SSH on each node.
  9. #
  10. # To restore services afterwards, use `restore_dgx_services` (or reboot).
  11. set -euo pipefail
  12. SERVICES_STOP=(
  13. snapd.service
  14. fwupd.service
  15. udisks2.service
  16. upower.service
  17. ModemManager.service
  18. bluetooth.service
  19. avahi-daemon.service
  20. cups.service
  21. cups-browsed.service
  22. colord.service
  23. smartmontools.service
  24. rsyslog.service
  25. rtkit-daemon.service
  26. dgx-dashboard-admin.service
  27. dgx-dashboard.service
  28. )
  29. USER_KILL=(
  30. "pipewire"
  31. "pipewire-pulse"
  32. "wireplumber"
  33. "snapd-desktop-integration"
  34. )
  35. echo "=== [$HOSTNAME] Stopping non-essential services ==="
  36. for svc in "${SERVICES_STOP[@]}"; do
  37. if systemctl is-active --quiet "$svc" 2>/dev/null; then
  38. echo " Stopping $svc ..."
  39. systemctl stop "$svc" 2>/dev/null || true
  40. systemctl disable "$svc" 2>/dev/null || true
  41. fi
  42. done
  43. for proc in "${USER_KILL[@]}"; do
  44. pids=$(pgrep -x "$proc" 2>/dev/null || true)
  45. if [ -n "$pids" ]; then
  46. echo " Killing $proc (PIDs: $pids) ..."
  47. kill -TERM $pids 2>/dev/null || true
  48. fi
  49. done
  50. systemctl stop snapd.service snapd.socket 2>/dev/null || true
  51. echo " Dropping page cache + dentries ..."
  52. sync
  53. echo 3 > /proc/sys/vm/drop_caches 2>/dev/null || true
  54. echo "=== [$HOSTNAME] Done ==="