Skip to content

Instantly share code, notes, and snippets.

View tjl2's full-sized avatar

Tim Littlemore tjl2

  • DICE
  • Cheshire, UK
  • 14:23 (UTC +01:00)
View GitHub Profile
@tjl2
tjl2 / after_symlink.rb
Created August 19, 2011 08:02
Engine Yard after_symlink deploy hook
@tjl2
tjl2 / default.rb
Created September 21, 2011 15:41
Changing localtime
# Note that this is for the GB timezone. Look in
# /usr/share/zoneinfo for your relevant file.
service "vixie-cron"
service "sysklogd"
service "nginx"
link "/etc/localtime" do
to "/usr/share/zoneinfo/GB"
notifies :restart, resources(:service => ["vixie-cron", "sysklogd", "nginx"]), :delayed
not_if "readlink /etc/localtime | grep -q 'GB$'"
@tjl2
tjl2 / default.rb
Created October 8, 2011 14:47
Replacing the passenger_monitor cron task
cron "passenger_monitor_#{app_name}" do
action :delete
end
cron "passenger_monitor_#{app_name}" do
minute '*'
hour '*'
day '*'
month '*'
weekday '*'
@tjl2
tjl2 / gist:1322487
Created October 28, 2011 15:05
What's in node?
# Run these commands first:
# sudo ohai > ~/ohai.json && sudo cp /etc/chef/dna.json ~/dna.json && sudo chown deploy:deploy ~/dna.json
# Then start an irb session in ~
require 'json'
ohai = JSON.parse(File.read('ohai.json'))
dna = JSON.parse(File.read('dna.json'))
# Examples...
# Find the instance type:
@tjl2
tjl2 / gist:1330498
Created November 1, 2011 13:29
Changing the count and memory limit of Passenger processes on Engine Yard Cloud

This was going to go into a blog post, but was removed after discussion around it being a Bad Thing for customers to do.

Changing the count and memory limit of Passenger processes

To stop applications that are prone to bloating quickly exhausting all the memory on an application instance, we have a script called passenger_monitor that checks for runaway Passenger processes every minute via a cron job. By default, this script is going to look for Passenger workers that are using over 215MB of memory and kill them. Passenger will restart them when needed. We tune the number of workers that run by default on your application instances, based on the memory specifications so that the memory is sensibly utilized. However, if your application legitimately requires more memory than this (i.e. it isn’t bloating) then it may be advantageous for you to reduce the worker count, and allow the lower number of workers to use more memory.

Doing this involves two areas of customization; modifying the Nginx configuratio

@tjl2
tjl2 / gist:1330621
Created November 1, 2011 14:27
Rake command wrapper
#!/bin/bash
#
# This script starts and stops a command in a way that monit can
# monitor it. See https://gist.github.com/1330635 for an example
# monit config.
#
# Change these 2 variables appropriately:
COMMAND_NAME="GIVE_THIS_AN_IDENTIFIABLE_NAME" # Alpha-numeric characters and underscores only
COMMAND="PUT_YOUR_RAKE_COMMAND_HERE"
# This monit config can be used in conjunction with
# https://gist.github.com/1330621 and assumes you have
# saved that file as /usr/local/bin/wrapper.
# Fill in APP_NAME, COMMAND_NAME and APP_NAME_COMMAND_NAME
# as appropriate
check process COMMAND_NAME
with pidfile /path/to/pidfile.pid
start program = "/usr/local/bin/wrapper APP_NAME start"
as uid deploy and gid deploy
stop program = "/usr/local/bin/wrapper APP_NAME stop"
@tjl2
tjl2 / default.rb
Created November 4, 2011 13:44
Find util instance host names
node[:applications].each do |app, data|
template "/data/#{app}/shared/config/resque.yml" do
owner node[:owner_name]
group node[:owner_name]
mode 0644
source "resque.yml.erb"
variables({
:host => node[:utility_instances].each {|util| util[:hostname] if util[:name] == 'resque'}[0][:hostname]
})
end
@tjl2
tjl2 / default.rb
Created November 7, 2011 11:27
Using notifies with templates
service "mysql" do
supports :restart => true
action :enable
end
if ['solo', 'db_master', 'db_slave'].include? node[:instance_role]
template "/etc/mysql.d/custom.cnf" do
owner 'root'
group 'root'
source 'custom.cnf.erb'
@tjl2
tjl2 / error.log
Created November 15, 2011 13:22
Examining request objects
ActionView::Template::Error (can't dump anonymous class Class):
1: <h3>Rack request env</h3>
2: <h3>Rails request object</h3>
3: <pre><%= h(@request_obj.to_yaml).gsub(" ", "&nbsp;").html_safe %></pre>
app/views/headers/index.html.erb:3:in `_app_views_headers_index_html_erb___1006215901_77896010__270781548'