Skip to content

Instantly share code, notes, and snippets.

View thpham's full-sized avatar

Thomas Kim Pham thpham

View GitHub Profile
@thpham
thpham / rp.conf
Created March 3, 2014 14:58
Nginx configuration
server {
listen 80;
root /var/www/;
index index.php index.html index.htm;
server_name example.com;
location / {
try_files $uri $uri/ /index.php;
RPM and FPM
Install rpm-build via yum (from CentOS Updates and Base)
Install fpm via rubygems (requires json gem)
Creating an RPM from the apache-tomcat-7.0.25 directory and installing to /opt/tomcat/${Packagestuff}
fpm -s dir -t rpm -n tomcat -v 7.0.25 --prefix /opt/tomcat -C apache-tomcat-7.0.25
Creating a Puppet Module
fpm -s dir -t puppet -n tomcat -v 7.0.25 -C apache-tomcat-7.0.25
#!/bin/bash
source /etc/environment
hostname=$(cat /etc/machine-id)
machines=$(etcdctl ls /consul.io/bootstrap/machines)
#If there are 'machines' then the cluster has been initialised.
if [ -z "$machines" ]
then
flags="${flags} -bootstrap"
@thpham
thpham / iptableflip.sh
Created October 7, 2015 14:24 — forked from lewisd32/iptableflip.sh
Snippet of Unbounce script for restarting HAProxy with zero downtime
echo "Flipping tables! (╯°□°)╯︵ ┻━┻"
num_rules=3
real=3 # exposed to the ELB as port 443
test=4 # used to install test certs for domain verification
health=5 # used by the ELB healthcheck
blue_prefix=855
green_prefix=866
#!/usr/bin/env python
#
# Converts any integer into a base [BASE] number. I have chosen 62
# as it is meant to represent the integers using all the alphanumeric
# characters, [no special characters] = {0..9}, {A..Z}, {a..z}
#
# I plan on using this to shorten the representation of possibly long ids,
# a la url shortenters
#
@thpham
thpham / migration.sh
Created March 27, 2015 12:05
Consul.io Leader discovery and election to invoque migration...
# check if leader exist (means associated session with the )
hasSession=$(curl -s http://localhost:8500/v1/kv/service/migration/leader | jq -r .[] | jq 'has("Session")')
if [ -z "$hasSession" ] || [ "$hasSession" = false ]; then
# create session
session=$(curl -s -X PUT -d '{"Name": "migration"}' http://localhost:8500/v1/session/create | jq -r .ID)
echo "session=$session"
leaderValue=$(curl -s http://localhost:8500/v1/kv/service/migration/leader | jq -r .[].Value | base64 --decode)
echo "leaderValue=$leaderValue"
if [ -z "$leaderValue" ] || [ "$leaderValue" != "JOB_DONE" ]; then
# try to put a lock
@thpham
thpham / .credentials
Created February 23, 2016 09:27 — forked from vrischmann/.credentials
Running SBT with a Nexus proxy with authentication
realm=Nexus Repository Manager
host=nexus.company.com
user=admin
password=admin123
#!/usr/bin/env python
from xivo_auth_client import Client as Auth
from xivo_confd_client import Client as Confd
auth = Auth('127.0.0.1', username='sylvain', password='sylvain', verify_certificate=False)
token_data = auth.token.new('xivo_user', expiration=10)
token = token_data['token']
uuid = token_data['xivo_user_uuid']
@thpham
thpham / zookeeper-kafka
Created June 28, 2016 12:14 — forked from mesonoxian/zookeeper-kafka
Simple Zookeeper and Kafka init.d Startup Script
#! /bin/bash
### BEGIN INIT INFO
# Provides: kafka
# Required-Start:
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: kafka service
### END INIT INFO
@thpham
thpham / gist:ae62739c226ead06e320ad318f629565
Created April 25, 2017 12:21 — forked from ruckus/gist:2293434
Basic setup of WAL-E for continuous archiving and recovery

WAL-E needs to be installed on all machines, masters and slaves.

How to install WAL-E

Only one machine, the master, writes WAL segments via continuous archiving. The configuration for the master postgresql.conf is:

archive_mode = on
archive_command = 'envdir /etc/wal-e.d/env wal-e wal-push %p'
archive_timeout = 60