Skip to content

Instantly share code, notes, and snippets.

@robdimarco
Created August 6, 2010 01:36
Show Gist options
  • Save robdimarco/510683 to your computer and use it in GitHub Desktop.
Save robdimarco/510683 to your computer and use it in GitHub Desktop.
Scripts to set up an EngineYard AppCloud that will use Amazon S3 as its assets host. These scripts will sync your public directory (including any cache files such as cached javascript) up to a bucket on S3 which can then be used as an asset host.
#!/usr/bin/env ruby
# Script resides at
# $RAILS_ROOT/script/generate_asset_cache_files.rb
#
# Big assist on this to Kyle Burton
#
require 'net/http'
require 'uri'
env = ENV['RAILS_ENV'] || "development" # Environment to run
# List of all URLs needed to generate all cached content that should be synced out to the asset host
urls = ["/"]
port = 3009
#
# We need the retries as the Webrick server may not be ready right away
#
max_retries = 20
cmd = "#{File.join(File.dirname(__FILE__))}/server -e #{env} -p #{port} -d"
puts "Starting Webrick with #{cmd}"
unless system(cmd)
raise "Problem booting webrick!"
end
try_count = 0
urls.each do |url|
make_request = true
while make_request and try_count < max_retries do
begin
full_url = "http://localhost:#{port}#{url}"
puts "Getting url #{full_url}"
Net::HTTP.get_print URI.parse(full_url)
puts "Got url #{full_url}"
make_request=false
rescue Exception => e
puts "Errored...#{e.inspect}"
try_count += 1
sleep 2
end
end
end
res = `ps aux | grep [r]uby | grep [s]cript/server`
pid = res.split[1]
puts "Killing Webrick"
Process.kill "KILL", pid.to_i
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment