Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions image/setup_wizard/lib/discourse_setup/system_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ def check_disk_and_memory
check_disk
end

def swap_needed?
available_memory_gb <= SWAP_THRESHOLD_GB && calculate_swap_gb < MIN_SWAP_GB
end

def prompt_swap_creation
return unless swap_needed?

@ui.warning(<<~MSG)
Discourse requires at least #{MIN_SWAP_GB}GB of swap when running with #{SWAP_THRESHOLD_GB}GB of RAM or less.
This system has #{calculate_swap_gb}GB of swap.

Without sufficient swap, your site may not work properly.
MSG

if @ui.confirm("Create a 2GB swapfile?", default: true)
signal_swap_creation
else
@ui.warning("Proceeding without swap. This may cause issues.")
end
end

def check_ports(skip: false)
return if skip

Expand Down Expand Up @@ -73,27 +94,6 @@ def check_memory
Your site may not work properly, or future upgrades may not complete successfully.
MSG
end

check_swap if mem_gb <= SWAP_THRESHOLD_GB
end

def check_swap
total_swap_gb = calculate_swap_gb

return if total_swap_gb >= MIN_SWAP_GB

@ui.warning(<<~MSG)
Discourse requires at least #{MIN_SWAP_GB}GB of swap when running with #{SWAP_THRESHOLD_GB}GB of RAM or less.
This system has #{total_swap_gb}GB of swap.

Without sufficient swap, your site may not work properly.
MSG

if @ui.confirm("Create a 2GB swapfile?", default: true)
signal_swap_creation
else
@ui.warning("Proceeding without swap. This may cause issues.")
end
end

def signal_swap_creation
Expand Down
3 changes: 3 additions & 0 deletions image/setup_wizard/wizard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ def run_system_checks

@ui.spin("Checking memory and disk...") { @system_checks.check_disk_and_memory }
@ui.success("Memory: #{@system_checks.available_memory_gb}GB, CPU: #{@system_checks.available_cpu_cores} cores")

# Prompt for swap creation outside spinner (interactive)
@system_checks.prompt_swap_creation
end

def setup_config
Expand Down
Loading