Auto-configure swap
Create a swapfile and configure it to be used for swap, immediately and on boot; defaults to half the size of RAM. See attribute for overriding configs to tune size or swappiness.
This commit is contained in:
@@ -8,3 +8,20 @@ package %w(qemu-guest-agent)
|
||||
service "qemu-guest-agent" do
|
||||
action [:enable, :start]
|
||||
end
|
||||
|
||||
swap_cfg = node["kosmos_kvm"]["guest"]["swap"]
|
||||
|
||||
if swap_cfg["enabled"] && swap_cfg["size_mb"] != 0
|
||||
size = swap_cfg["size_mb"] ||
|
||||
(node["memory"]["total"].to_i / 2 / 1024) # kB -> MB, half RAM
|
||||
|
||||
# The resource only creates/activates the swapfile if it is not already
|
||||
# active; an existing active swapfile is left untouched (size is NOT
|
||||
# reconciled to current RAM).
|
||||
swap_file swap_cfg["path"] do
|
||||
size size
|
||||
persist true
|
||||
swappiness swap_cfg["swappiness"] if swap_cfg["swappiness"]
|
||||
action :create
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user