Skip to content

Instantly share code, notes, and snippets.

@krames
Forked from smashwilson/swap-setup.rb
Last active January 4, 2016 09:08
Show Gist options
  • Save krames/8599608 to your computer and use it in GitHub Desktop.
Save krames/8599608 to your computer and use it in GitHub Desktop.
require 'fog'
service = Fog::Compute.new(
provider: 'rackspace',
rackspace_username: ENV['RAX_USERNAME'],
rackspace_api_key: ENV['RAX_API_KEY'],
rackspace_region: :ord
)
# Adjust these settings based on your needs.
@swapsize = "1048576"
@swappiness = "10"
puts "creating server."
server = service.servers.bootstrap :name => 'bootstrap-server',
:flavor_id => service.flavors.first.id,
:image_id => service.images.find {|img| img.name =~ /Ubuntu/}.id,
:public_key_path => '~/.ssh/id_rsa.pub',
:private_key_path => '~/.ssh/id_rsa'
puts "server created."
# See:
# http://www.rackspace.com/knowledge_center/article/create-a-linux-swap-file
server.ssh [
"set -e",
"dd if=/dev/zero of=/mnt/swapfile bs=1024 count=#{@swapsize}",
"mkswap /mnt/swapfile",
"swapon /mnt/swapfile",
%Q[echo "/mnt/swapfile none swap sw 0 0" >> /etc/fstab],
%Q[echo "vm.swappiness=#{@swappiness}" >> /etc/sysctl.conf],
"sysctl vm.swappiness=#{@swappiness}"
]
puts "log in with: ssh root@#{server.ipv4_address}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment