Skip to content

Instantly share code, notes, and snippets.

Avatar

Greg Swallow ctgswallow

  • ExactTarget
  • Indianapolis
View GitHub Profile
@ctgswallow
ctgswallow / es_backup.sh
Last active Oct 8, 2021
Elasticsearch backup script
View es_backup.sh
#!/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:5095878
Last active Dec 14, 2015
Varnish config from template
View gist:5095878
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 && " +
View gist:5092172
#
# 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 Mar 1, 2013
Capistrano task to create a read-only user for Drupal DB Slaves
View gist:5061366
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
View gist:4991025
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 Feb 13, 2013
confusing redis stuff
View gist:4948302
# 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
View gist:4780222
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
View gist:4683837
#!/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
View gist:4629288
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
View gist:4004072
namespace :pre_deploy do
task "default" do
create_zipfile
end
desc "Create package zip file"
task "create_zipfile" do
run_locally "mkdir -p #{build_dir}"
run_locally "git archive --format=zip --prefix=#{app_name}/ -6 --output=#{build_dir}/#{app_name}-`git rev-parse --short=8 HEAD`.zip HEAD"