Skip to content

Instantly share code, notes, and snippets.

@therobot
Created January 7, 2011 18:31
Show Gist options
  • Save therobot/769879 to your computer and use it in GitHub Desktop.
Save therobot/769879 to your computer and use it in GitHub Desktop.
set[:swap][:location]="/swapfile"
set[:swap][:blocksize]="1024k"
set[:swap][:count]="1024"
# -*- coding: utf-8 -*-
#
# Cookbook Name:: swap
# Recipe:: default
#
# Copyright 2010, Jacobo García López de Araujo
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
script "create swap" do
interpreter "bash"
user "root"
cwd "/"
code <<-EOF
dd if=/dev/zero of=#{node[:swap][:location]} bs=#{node[:swap][:blocksize]} count=#{node[:swap][:count]}
mkswap #{node[:swap][:location]}
swapon #{node[:swap][:location]}
EOF
not_if do File.exists?(node[:swap][:location]) end
end
mount "none" do
device node[:swap][:location]
fstype "swap"
options %w(sw)
dump 0
pass 0
action [:enable, :mount]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment