Skip to content

Instantly share code, notes, and snippets.

Avatar

Jesse Cotton JCotton1123

View GitHub Profile
@JCotton1123
JCotton1123 / gist:5ee42a34d19cc7c50bb23eef5a06142c
Created Mar 4, 2017
Audit Chef client versions via knife
View gist:5ee42a34d19cc7c50bb23eef5a06142c
knife search node '*' -a chef_packages.chef.version | grep "chef_packages.chef.version" | cut -d" " -f4 | sort | uniq
@JCotton1123
JCotton1123 / setup.sh
Created Feb 20, 2017
Setup Londiste2 on Ubuntu as of Feb 2017
View setup.sh
add-apt-repository "deb https://apt.postgresql.org/pub/repos/apt/ trusty-pgdg main"
wget --quiet -O - https://postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
apt-get update
apt-get install postgresql-server-dev-9.4
apt-get install python-pip python-dev
pip install --upgrade pip
pip install psycopg2
apt-get install build-essential autoconf
View gist:f0fe955bcb242cf74e198bb0c4541555
# Database size
SELECT table_schema "Data Base Name",
sum( data_length + index_length ) / 1024 / 1024 "Data Base Size in MB",
sum( data_free )/ 1024 / 1024 "Free Space in MB"
FROM information_schema.TABLES
GROUP BY table_schema ;
# Size of each non-primary index
SELECT database_name, table_name, index_name,
round(stat_value*@@innodb_page_size/1024/1024, 2) size_in_mb
@JCotton1123
JCotton1123 / fetchenv.sh
Created Jun 9, 2016
Export env variables for each AWS CloudFormation stack output
View fetchenv.sh
#!/bin/bash
# This script will find all AWS CloudFormation stacks matching the supplied filter
# and export the outputs into environment variables.
#
# This script is assumed to be run on a host with an IAM profile matching the following:
#
# {
# "Version": "2012-10-17",
# "Statement": [
View jenkins-bulk-delete-nodes.sh
#!/bin/bash
cookies="JSESSIONID.8d49441c=1xzuqo2mhtku1pq2q7kvffeud; JSESSIONID.b502a53a=19uzmrp8ggsplp44mageiqqq7; JSESSIONID.6accbce3=zkbcn2gy1qye1h89aan7o6zog; JSESSIONID.b1204f00=11rs98x2idnf01woxy79tmx7ev; hudson_auto_refresh=false; screenResolution=1440x900"
base_url="https://jenkins.example.com"
while read -r slave_name; do
curl -v --cookie "$cookies" "$base_url/computer/$slave_name/doDelete"
[ $? ] || exit 1
done < $1
@JCotton1123
JCotton1123 / mysql-query-time-test.sh
Last active Feb 11, 2016
Simple script to measure the time it takes to execute a series of MySQL queries
View mysql-query-time-test.sh
#!/bin/bash
user='root'
password=''
function usage() {
echo "usage: $0 <query-file> <default-database>"
exit 1
}
@JCotton1123
JCotton1123 / generate-ssl-cert.sh
Created Feb 3, 2016
Generate an SSL certificate and key with multiple subject alternative names
View generate-ssl-cert.sh
#!/bin/sh
subject='/C=US/ST=California/L=San Francisco/O=Organization/OU=Operations/CN=*.orgdev.net/emailAddress=operations@org.co'
subject="${subject}/subjectAltName=DNS.1=orgdev.net,DNS.2=*.orgdev.net,DNS.3=dev.orgdev.net,DNS.4=*.dev.orgdev.net"
openssl genrsa -out server.key 2048
openssl req -new -key server.key -sha256 -nodes -subj "$subject" > server.csr
openssl x509 -req -days 3650 -in server.csr -signkey server.key -out server.crt
View setup-s3s3mirror.sh
# Ideally, run this from a EC2 instance within the same
# region as your source and destination buckets
apt-get update -y
apt-get install -y git openjdk-7-jdk
git clone https://github.com/cobbzilla/s3s3mirror.git
cd s3s3mirror
export AWS_ACCESS_KEY_ID=
@JCotton1123
JCotton1123 / setup-chef.md
Last active May 19, 2017
Setup Chef Server
View setup-chef.md

Setup Chef server

  • Make sure the server is configured with an appropriate hostname that resolves to itself (add hosts entry if needed)
  • Download and install Chef server package from: http://downloads.chef.io/chef-server/
  • chef-server-ctl reconfigure
  • chef-server-ctl user-create admin Chef Administrator jcotton@bitlancer.com <password> --filename /tmp/admin.pem
  • chef-server-ctl org-create <org-short-name> "<org-full-name>" --association_user admin --filename /tmp/validator.pem
  • Use OpenSSL to generate a new cert and key and update: /var/opt/opscode/nginx/ca/<fqdn>.key, /var/opt/opscode/nginx/ca/<fqdn>.crt. Restart services (nginx) with: chef-server-ctl restart

Cleanup and re-initiate a bad install

@JCotton1123
JCotton1123 / export-mailgun-bounces.php
Created Oct 22, 2015
Export bounces from Mailgun
View export-mailgun-bounces.php
#!/usr/bin/php
<?php
## Constants
define('MAILGUN_API_ENDPOINT','https://api.mailgun.net/v3');
define('API_CREDENTIALS_STRING','api:key-');
define('DEFAULT_DOMAIN','');
## Main
if($argc != 2){