Skip to content

Commit

Permalink
Merge pull request #11 from rightscale-cookbooks/white_14_01_acu14664…
Browse files Browse the repository at this point in the history
…0_swap_input_fix

Added swap size input
  • Loading branch information
douglaswth committed Jan 7, 2014
2 parents 64d76e8 + 4273227 commit a90f53f
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ Place the `rs-base::default` recipe in the runlist.

# Attributes

* `node['rs-base']['swap']['size']` - The swap file size in MB. This attribute must be a numeric value.
Default is `1024`.
* `node['rs-base']['swap']['size']` - The swap file size in GB. This attribute must be an integer.
Default is `1`.
* `node['rs-base']['swap']['file']` - The location of the swap file. This attribute must be a valid filename.
Default is `'/mnt/ephemeral/swapfile'`.
* `node['rs-base']['ntp']['servers']` - List of fully qualified domain names for the array of servers that are used for
Expand All @@ -36,7 +36,7 @@ All-in-one recipe to run all recipes in rs-base cookbook.

## rs-base::swap

Creates a swapfile of the specified size `node['rs-base']['swap']['size']` in the
Creates a swapfile of the specified size (in GB) `node['rs-base']['swap']['size']` in the
specified location `node['rs-base']['swap']['file']` and enables it's usage.
The swap file is added to `/etc/fstab` and will persist across reboots. If the size or the
file location is invalid this recipe will fail with an error message indicating what the
Expand All @@ -53,8 +53,8 @@ used as the remote syslog server. Otherwise local machine is used.

## rs-base::collectd

Installs the collectd client with some of the basic plugins, syslog, interface, df, disk, memory, load,
processes, users, and network.
Installs the collectd client with some of the basic plugins, syslog, interface, df, disk, memory, load,
processes, users, and network.

# Author

Expand Down
4 changes: 2 additions & 2 deletions attributes/swap.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#
# Cookbook Name:: rs-base
# Attributes:: swap
# Attributes:: swap
#
# Copyright (C) 2013 RightScale, Inc.
#
Expand All @@ -17,5 +17,5 @@
# limitations under the License.
#

default['rs-base']['swap']['size'] = 1024 # MB
default['rs-base']['swap']['size'] = 1 # GB
default['rs-base']['swap']['file'] = "/mnt/ephemeral/swapfile"
9 changes: 9 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@
"ec2-us-west.time.rightscale.com"
]

attribute "rs-base/swap/size",
:display_name => "Swap Size",
:description =>
"The size of the swap file (in Gigabytes). This value should be an integer." +
" Example: 1",
:recipes => ["rs-base::default", "rs-base::swap"],
:required => "optional",
:default => "1"

attribute "rs-base/rsyslog_server",
:display_name => "Remote rsyslog Server",
:description =>
Expand Down
11 changes: 6 additions & 5 deletions recipes/swap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
# Recipe:: swap
#
# Copyright (C) 2013 RightScale, Inc.
#
#
# 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.
Expand All @@ -32,9 +32,10 @@
end

swap_file node['rs-base']['swap']['file'] do
size node['rs-base']['swap']['size'].to_i
# The swap cookbook expects the size to be in MB. So convert the size in GB to MB.
size node['rs-base']['swap']['size'].to_i * 1024
persist true
action :create
end

#TODO deal with collectd
#TODO deal with collectd
2 changes: 1 addition & 1 deletion test/integration/swap/bats/swap.bats
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ SWAPFILE="/mnt/ephemeral/swapfile"
}

@test "Has the correct swapfile size." {
ls -l --human-readable --block-size=M $SWAPFILE | grep "1024M"
ls -l --human-readable --block-size=G $SWAPFILE | grep "1G"
}

@test "Swapfile is enabled." {
Expand Down

0 comments on commit a90f53f

Please sign in to comment.