Skip to content

Commit 167c0d0

Browse files
authored
FIX: Move swap prompt outside spinner (#1021)
1 parent a0a5b53 commit 167c0d0

File tree

2 files changed

+24
-21
lines changed

2 files changed

+24
-21
lines changed

image/setup_wizard/lib/discourse_setup/system_checks.rb

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,27 @@ def check_disk_and_memory
4545
check_disk
4646
end
4747

48+
def swap_needed?
49+
available_memory_gb <= SWAP_THRESHOLD_GB && calculate_swap_gb < MIN_SWAP_GB
50+
end
51+
52+
def prompt_swap_creation
53+
return unless swap_needed?
54+
55+
@ui.warning(<<~MSG)
56+
Discourse requires at least #{MIN_SWAP_GB}GB of swap when running with #{SWAP_THRESHOLD_GB}GB of RAM or less.
57+
This system has #{calculate_swap_gb}GB of swap.
58+
59+
Without sufficient swap, your site may not work properly.
60+
MSG
61+
62+
if @ui.confirm("Create a 2GB swapfile?", default: true)
63+
signal_swap_creation
64+
else
65+
@ui.warning("Proceeding without swap. This may cause issues.")
66+
end
67+
end
68+
4869
def check_ports(skip: false)
4970
return if skip
5071

@@ -73,27 +94,6 @@ def check_memory
7394
Your site may not work properly, or future upgrades may not complete successfully.
7495
MSG
7596
end
76-
77-
check_swap if mem_gb <= SWAP_THRESHOLD_GB
78-
end
79-
80-
def check_swap
81-
total_swap_gb = calculate_swap_gb
82-
83-
return if total_swap_gb >= MIN_SWAP_GB
84-
85-
@ui.warning(<<~MSG)
86-
Discourse requires at least #{MIN_SWAP_GB}GB of swap when running with #{SWAP_THRESHOLD_GB}GB of RAM or less.
87-
This system has #{total_swap_gb}GB of swap.
88-
89-
Without sufficient swap, your site may not work properly.
90-
MSG
91-
92-
if @ui.confirm("Create a 2GB swapfile?", default: true)
93-
signal_swap_creation
94-
else
95-
@ui.warning("Proceeding without swap. This may cause issues.")
96-
end
9797
end
9898

9999
def signal_swap_creation

image/setup_wizard/wizard.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ def run_system_checks
7575

7676
@ui.spin("Checking memory and disk...") { @system_checks.check_disk_and_memory }
7777
@ui.success("Memory: #{@system_checks.available_memory_gb}GB, CPU: #{@system_checks.available_cpu_cores} cores")
78+
79+
# Prompt for swap creation outside spinner (interactive)
80+
@system_checks.prompt_swap_creation
7881
end
7982

8083
def setup_config

0 commit comments

Comments
 (0)