2019-03-03 08:50:49 +00:00
|
|
|
# Make swap file:
|
|
|
|
[
|
2019-11-05 15:20:26 +00:00
|
|
|
'dd if=/dev/zero of=/swap.img bs=1M count=2048 && chmod 600 /swap.img && mkswap /swap.img'
|
2019-03-03 08:50:49 +00:00
|
|
|
].each do |cmd|
|
|
|
|
execute cmd do
|
|
|
|
user 'root'
|
|
|
|
|
2019-11-05 15:20:26 +00:00
|
|
|
only_if 'test ! -f /swap.img'
|
2019-03-03 08:50:49 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Add the fstab entry:
|
|
|
|
file '/etc/fstab' do
|
|
|
|
action :edit
|
|
|
|
|
|
|
|
block do |content|
|
|
|
|
content << "/swap.img /dev/null swap defaults 0 2\n"
|
|
|
|
end
|
|
|
|
|
|
|
|
not_if 'grep swap.img /etc/fstab'
|
|
|
|
end
|
|
|
|
|
|
|
|
# Mount the swap file:
|
|
|
|
execute 'swapon -ae' do
|
|
|
|
only_if 'test `cat /proc/swaps | wc -l` -eq 1'
|
|
|
|
end
|