Skip to content

Instantly share code, notes, and snippets.

View andrewgross's full-sized avatar

Andrew Gross andrewgross

View GitHub Profile
# ssh-known-hosts completion
#
_ssh_known_hosts()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [ -n "$(echo ${cur} | grep '@')" ] ; then
@andrewgross
andrewgross / aws-raid-setup.sh
Created January 12, 2012 17:58
AWS RAID Setup
yum update
yum install mdadm
yum install xfsprogs
Attach your drives, ephemeral or EBS (/dev/sdf* here)
mdadm --create /dev/md0 --verbose --metadata=1.1 --level=0 --chunk=256 --raid-devices=8 /dev/sdf1 /dev/sdf2 /dev/sdf3 /dev/sdf4 /dev/sdf5 /dev/sdf6 /dev/sdf7 /dev/sdf8
@andrewgross
andrewgross / gist:1717859
Created February 1, 2012 16:26
Chef Template Issue
# Template Block
template "~/.ssh/config" do
source "config.erb"
owner "ubuntu"
group "ubuntu"
end
[Wed, 01 Feb 2012 16:24:10 +0000] FATAL: Errno::ENOENT: template[~/.ssh/config] (my_cookbook::my_recipe line 85) had an error: Errno::ENOENT: No such file or directory - /tmp/chef-rendered-template20120201-10135-m1gp7t-0 or ~/.ssh/config
remote_file "my package" do
path tmp_dpkg_location
source "http://www.remotesite.com/packages/initial/#{node.appfirst_account_id}/package-#{arch}.#{extention}"
ignore_failure true
end
dpkg_package "my package" do
source "#{tmp_dpkg_location}"
only_if "ls #{tmp_dpkg_location} > /dev/null"
action :install
if [ ! -f /usr/local/bin/chef-client ]; then
apt-get update
apt-get install -y ruby1.9.1 ruby1.9.1-dev build-essential wget
fi
gem install ohai --no-rdoc --no-ri --verbose
gem install right_aws --no-ri --no-rdoc --verbose
gem install chef --no-rdoc --no-ri --verbose
mkdir -p /etc/chef
service "apache2" do
name "apache2"
supports :restart => true, :reload => true
action :enable
# Hack to make sure we wait a little bit before restarting
only_if "sleep 1"
end
@andrewgross
andrewgross / gist:2629495
Created May 7, 2012 18:30
Redis Cookbook
# Set up our disk
include_recipe "data_volume::default"
data_volume "/var/lib/redis" do
action :create
size 16
provider "data_volume"
not_if "grep '/var/lib/redis' /etc/fstab > /dev/null"
end
@andrewgross
andrewgross / gist:2646785
Created May 9, 2012 17:07
No Host Key Verify Monkey Patch
class Chef::Knife::Ec2ServerCreate < Chef::Knife
alias :original_run :run
def run
@initial_sleep_delay = 30
original_run
end
option :attrs,
:long => "--attrs ATTRS",
@andrewgross
andrewgross / upload_memcache_stats.py
Created August 1, 2012 16:02
Python Script to Upload Memcache Metrics to CloudWatch
import sys, time, subprocess, socket, telnetlib
from datetime import datetime
from collections import defaultdict
from boto.ec2.cloudwatch import CloudWatchConnection
MAPPINGS = {
# Memcached name: (AWS Name, AWS Metric Type, Calculation Method)
'uptime': ('Uptime', 'Count', 'gauge'),
@andrewgross
andrewgross / pre-commit.sh
Created August 20, 2012 22:36
Bash Pre Commit Hook
#!/bin/bash
# A pre-commit hook that will stash any changes so that we are running our tests
# against what we are committing, not what was on in memory.
# Because I was having trouble getting trap to play nicely with any signal except
# EXIT we just carry around our status and exit with it at the end
status=0