Skip to content

Instantly share code, notes, and snippets.

View rajeshkp's full-sized avatar

Rajesh Koilpillai rajeshkp

View GitHub Profile
# config/deploy.rb
# probably a lot of ways to improve this...
set :application, 'my_app'
set :repo_url, 'git@github.com:USERNAME/my_app.git'
# should set up a deploy user
set :user, 'deploy'
set :deploy_to, '/var/www/my_app'
set :scm, :git
set :application, "appname"
set :deploy_to, "/var/www"
set :scm, :git
set :repository, "git@github.com:user/app.git"
default_run_options[:pty] = true
set :user, "www-data"
set :domain, "foo.tld"
set :normalize_asset_timestamps, false

Setting up Flume NG, listening to syslog over UDP, with an S3 Sink

My goal was to set up Flume on my web instances, and write all events into s3, so I could easily use other tools like Amazon Elastic Map Reduce, and Amazon Red Shift.

I didn't want to have to deal with log rotation myself, so I setup Flume to read from a syslog UDP source. In this case, Flume NG acts as a syslog server, so as long as Flume is running, my web application can simply write to it in syslog format on the specified port. Most languages have plugins for this.

At the time of this writing, I've been able to get Flume NG up and running on 3 ec2 instances, and all writing to the same bucket.

Install Flume NG on instances

Ruby on Rails development setup on Ubuntu 12.04

System update

# change mirror to ubuntu.osuosl.org first
sudo apt-get update

Install common libraries

sudo apt-get install build-essential libreadline-dev libssl-dev zlib1g-dev libxml2-dev libxslt-dev

@rajeshkp
rajeshkp / deploy.rb
Created September 14, 2013 06:52 — forked from mlangenberg/deploy.rb
namespace :log do
desc "Downloads application logs to ./log/deploy/<RAILS_ENV>/<TIMESTAMP>/"
task :fetch, :roles => :app do
source = "#{shared_path}/log/#{rails_env}.log*"
files_per_host = {}
run "ls #{source}" do |channel, stream, data|
files_per_host[channel[:host]] = data.split("\n")
end
destination = File.join('log', 'deploy')
redis_config = { :namespace => 'sidekiq', :url => YAML.load_file("#{Rails.root}/config/redis.yml")[Rails.env] }
Sidekiq.configure_server do |config|
config.redis = redis_config
end
Sidekiq.configure_client do |config|
config.redis = redis_config
end
# rotate log files daily, keep 32 days
daily
rotate 32
# create new (empty) log files after rotating old ones
create
compress
@rajeshkp
rajeshkp / deploy.rb
Created September 11, 2013 13:06 — forked from mlangenberg/deploy.rb
namespace :log do
desc "Downloads application logs to ./log/deploy/<RAILS_ENV>/<TIMESTAMP>/"
task :fetch, :roles => :app do
source = "#{shared_path}/log/#{rails_env}.log*"
files_per_host = {}
run "ls #{source}" do |channel, stream, data|
files_per_host[channel[:host]] = data.split("\n")
end
destination = File.join('log', 'deploy')
# stick this in your Capfile
default_environment["TERM"] = 'xterm'

Though slightly more complex, using a CDN is the most performant option for serving static assets. See the [CDN asset host](cdn-asset-host-rails31) article for more details.

Ruby on Rails applications should use Rack::Cache to efficiently serve assets on the Cedar stack. Proper Rack::Cache usage improves response time, decreases load and is important when serving static assets through your application.

This article will summarize the concepts of caching assets using Rack::Cache and walk you through the appropriate configuration of a Rails 3.1 application and the asset pipeline.

Sample code for this article's [reference application](https://github.com/heroku/rack-cache-demo) is available on