Skip to content

Instantly share code, notes, and snippets.

View ctgswallow's full-sized avatar

Greg Swallow ctgswallow

  • ExactTarget
  • Indianapolis
View GitHub Profile
@ctgswallow
ctgswallow / es_backup.sh
Last active November 14, 2022 05:33
Elasticsearch backup script
#!/bin/bash
################################################################
##### script to backup lucene index from elastic search ####
################################################################
# Shamelessly copied from https://gist.github.com/nherment/1939828
NOW=`date +%Y%m%d%H%M%S`
@ctgswallow
ctgswallow / gist:3409231
Created August 20, 2012 23:27
Create a template within a ruby block
ruby_block "create ssh key" do
block do
k = SSHKey.generate(:type => 'RSA', :bits => 1024, :comment => "Postgres Master")
node.set[:postgresql][:pubkey] = k.ssh_public_key
node.save
# Much of the DSL disappears in ruby blocks. Here's how to create a template.
rc = Chef::RunContext.new(node, node.cookbook_collection)
t = Chef::Resource::Template.new "/var/lib/postgresql/.ssh/id_rsa"
t.source("id_rsa.erb")
@ctgswallow
ctgswallow / gist:5095878
Last active December 14, 2015 13:48
Varnish config from template
namespace :varnish do
desc "Configure varnish"
task :configure, :roles => :varnish do
ws = find_servers :roles => :web
set :ws, ws
backends_vcl = from_template("backends.vcl.erb")
put backends_vcl, "/tmp/backends.vcl"
run "sed -i -e 's/SUFFIX/'`hostname -s`'/' /tmp/backends.vcl"
run "#{sudo} cp /tmp/backends.vcl /etc/varnish"
run "#{sudo} varnishadm vcl.load #{date} /etc/varnish/default.vcl && " +
#
# Cookbook Name:: varnish
# Recipe:: graphite-vmods
#
# Copyright 2013, ExactTarget
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
@ctgswallow
ctgswallow / gist:5061366
Created March 1, 2013 00:16
Capistrano task to create a read-only user for Drupal DB Slaves
desc "create read-only user and set access to #{db_name} database"
task :create_ro_user, :roles => :dbmaster do
# General select-only access to all tables in #{db_name}
stmt = <<-SQL
GRANT SELECT ON #{db_name}.* TO #{rouser}@'%' IDENTIFIED BY '#{ropw}';
SQL
run "mysql -u#{dbmasterroot} -p#{dbmasterrootpw} -e \"#{stmt}\""
# Look up tables to which rw grants apply
desc "Configure Varnish cache module"
task :varnish, :roles => :publish do
run "cd #{latest_release}/docroot/sites/exacttarget ; drush dl -y varnish"
run "cd #{latest_release}/docroot/sites/exacttarget ; drush en -y varnish"
vcache = (find_servers :roles => :varnish).collect { |s| "#{s}:6080" }.join " "
vsettings = { "varnish_cache_clear" => "1",
"varnish_control_key" => :varnish_key.to_s,
"varnish_control_terminal" => "#{vcache}",
"varnish_flush_cron" => "0",
"varnish_socket_timeout" => "3600",
@ctgswallow
ctgswallow / gist:4948302
Created February 13, 2013 21:10
confusing redis stuff
# Retrieve all nodes' local hostnames and set the master_ip
# based on a match to *this* node's local hostname.
#
# I don't know why this is even necessary.
redis_nodes = all_provider_local_hostnames(node[:redis][:service_name])
master_ip = ""
myhostname = node[:cloud][:local_hostname] rescue node[:fqdn]
found = 0
redis_sorted_nodes = redis_nodes.sort
namespace :varnish do
desc "Configure varnish"
task :configure, :roles => :varnish do
upload("config/deploy/#{stage}/backends.vcl", "/tmp", :via => :scp)
run "#{sudo} cp /tmp/backends.vcl /etc/varnish"
run "#{sudo} varnishadm vcl.load #{date} /etc/varnish/default.vcl && " +
"#{sudo} varnishadm vcl.use #{date} /etc/varnish/default.vcl"
end
end
#!/bin/bash
while true ; do
for i in {1..4} ; do
now=$(date '+%s' | perl -pe 's/\012//')
c=$(echo stats | nc xtincache0$i.xt.local 11211 | grep curr_conn | cut -d ' ' -f 3 | perl -pe 's/\015//' )
echo "greg.cache.xtincache0${i}.curr_connections ${c} $now" | nc graphite-s1.xt.local 2013
done
sleep 5
done
actions :create
attribute :user, :kind_of => String, :name_attribute => true, :required => true
attribute :type, :kind_of => String, :default => "rsa", :equal_to => ["rsa", "dsa"]
attribute :length, :kind_of => String, :default => "2048", :equal_to => [ "1024", "2048", "4096" ]
action :create do
gem_package "sshkey" do
action :install