Skip to content

Instantly share code, notes, and snippets.

@erochest
Created September 22, 2011 15:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save erochest/1235066 to your computer and use it in GitHub Desktop.
Save erochest/1235066 to your computer and use it in GitHub Desktop.
Vagrant/Rake config files for setting up a GeoServer instance.
require 'etc'
require 'fileutils'
require 'vagrant'
task :default => :usage
task :usage do
puts "You forgot to tell the computer what to do; try one of these commands:"
system("rake -T")
end
# Execute a command in the primary VM and write its output to the screen.
def vm_ssh(env, cmd)
puts ">>> '#{cmd}'"
env.primary_vm.ssh.execute do |ssh|
ssh.exec!(cmd) do |channel, stream, data|
print data
$stdout.flush
end
end
end
desc 'Initializes the environment.'
task :init => [:clobber,
:cookbooks,
:up]
desc 'Cleans everything out of the environment.'
task :clobber do
FileUtils.rmtree %w{cookbooks}, :verbose => true
env = Vagrant::Environment.new
if env.primary_vm.created?
puts 'vagrant destroy'
env.cli('destroy')
end
end
desc 'Downloads the cookbooks.'
task :cookbooks do
Dir.mkdir("cookbooks") unless File.directory?("cookbooks")
system('git clone --branch=slab https://github.com/erochest/opscode-cookbooks.git cookbooks/opscode')
system('git clone https://github.com/scholarslab/cookbooks.git cookbooks/slab')
end
desc 'This calls Vagrant up.'
task :up do
env = Vagrant::Environment.new
puts 'vagrant up'
env.cli('up')
end
desc 'Do a safe halt on the VM.'
task :halt do
vm_ssh(Vagrant::Environment.new, 'sudo halt')
end
desc "cat /tmp/vagrant-chef-1/chef-stacktrace.out."
task :chefst do
env = Vagrant::Environment.new
raise "Must run `vagrant up`" if !env.primary_vm.created?
raise "Must be running!" if !env.primary_vm.vm.running?
puts "Getting chef stacktrace."
vm_ssh(env, "cat /tmp/vagrant-chef-1/chef-stacktrace.out")
end
namespace :tomcat do
desc 'This restarts Tomcat 6.'
task :restart do
puts 'Restarting Tomcat 6.'
env = Vagrant::Environment.new
vm_ssh(env, 'sudo /etc/init.d/tomcat6 restart')
end
end
Vagrant::Config.run do |config|
config.vm.box = "geoserver2"
config.vm.box_url = "http://files.vagrantup.com/lucid32.box"
config.vm.network "33.33.33.10"
config.vm.provision :chef_solo do |chef|
chef.cookbooks_path = [
'cookbooks/opscode',
'cookbooks/slab',
]
chef.add_recipe 'apt'
chef.add_recipe 'geoserver'
chef.add_recipe 'postgis'
chef.add_recipe 'geonetwork'
chef.add_recipe 'tmux'
chef.add_recipe 'vim'
chef.json.merge!({
:id => 'geoserver',
:postgis => {
:download_url => 'http://postgis.refractions.net/download/postgis-1.3.6.tar.gz',
},
:vim => {
:extra_packages => %w{vim-scripts exuberant-ctags ack-grep htop}
},
:domain => [],
:openldap => {}
})
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment