Skip to content

Instantly share code, notes, and snippets.

View Geesu's full-sized avatar

Josh Becker Geesu

View GitHub Profile
@Geesu
Geesu / gist:8476386
Created January 17, 2014 16:27
Example of a archive_command bash script to replication to 2 different servers. Like the local_backup_script.sh referenced here: http://www.postgresql.org/docs/current/static/continuous-archiving.html#BACKUP-SCRIPTS
#!/bin/bash
FAIL=0
job_1 = `rsync -aq $1 postgres@server1:/var/lib/postgresql/9.2/archive/$2`
job_2 = `rsync -aq $1 postgres@server2:/var/lib/postgresql/9.2/archive/$2`
$job_1 & pid_1=$! ; $job_2 & pid_2=$!
echo "Spawned replication processes $pid_1 AND $pid_2"
@Geesu
Geesu / local_backup_script.sh
Created January 26, 2014 23:00
Postgresql replication archive_command
#!/bin/bash
echoerr() { echo "$@" 1>&2; }
FAIL=0
`rsync -aq $1 postgres@b:/var/lib/postgresql/9.2/archive/$2` & pid_1=$! ; `rsync -aq $1 postgres@c:/var/lib/postgresql/9.2/archive/$2` & pid_2=$! ; `rsync -aq $1 postgres@d:/var/lib/postgresql/9.2/archive/$2` & pid_3=$!
echoerr "Spawned replication processes $pid_1 AND $pid_2 AND $pid_3"
standby_mode = 'on' # enables stand-by (readonly) mode
# Connect to the master postgres server using the replicator user we created.
primary_conninfo = 'host=a port=5432 user=replicator password=password'
# Specifies a trigger file whose presence should cause streaming replication to
# end (i.e., failover).
trigger_file = '/tmp/pg_failover_trigger'
# Shell command to execute an archived segment of WAL file series.
@Geesu
Geesu / gist:1a696262e46ba9f0a24c
Created May 7, 2014 01:48
Postgresql replication

Configuration

Slave

  • Install WAL-E (Note: You will have to run sudo python setup.py install MULTIPLE times, probably like 10):
sudo apt-get install daemontools pv lzop
git clone https://github.com/wal-e/wal-e.git && cd wal-e && sudo python setup.py install
  • Configure the environment for WAL-E (as root):
umask u=rwx,g=rx,o=
mkdir -p /etc/wal-e.d/env
echo "THEACCESSKEY" > /etc/wal-e.d/env/AWS_SECRET_ACCESS_KEY
echo "THEKEYID" > /etc/wal-e.d/env/AWS_ACCESS_KEY_ID

#!/bin/bash
echoerr() { echo "$@" 1>&2; }
FAIL=0
echoerr "Called"
`envdir /etc/wal-e.d/env /usr/local/bin/wal-e wal-push $1` & pid_1=$!
Verifying that +geesu is my Bitcoin username. You can send me #bitcoin here: https://onename.io/geesu
class Semaphore
def self.get(name, options = {})
# Create a new Redis connection specifically for the semaphore.
# Treat a semaphore as stale if it's too old. We have to assume that processing was interrupted, so that we can try the same files again.
Redis::Semaphore.new(name.to_sym,
:redis => Aperture.redis,
stale_client_timeout: options[:stale_client_timeout].try(:to_i) || 1.hour,
)
end
end
module Aperture
module Redis
class Pool < ::ConnectionPool
attr_accessor :namespace
def initialize(options = {})
super(options.delete :pool) { ::Redis.new options }
end
def with_namespace(ns)
@Geesu
Geesu / assets.rake
Created December 8, 2014 16:55
Disable asset precompilation on heroku
Rake::Task["assets:precompile"].clear
namespace :assets do
task 'precompile' do
puts "Not pre-compiling assets..."
end
end
➜ mono git:(master) ✗ PATH=$PREFIX/bin:$PATH
➜ mono git:(master) ✗ CC='cc -m32' ./autogen.sh --prefix=$PREFIX --disable-nls --build=i386-apple-darwin11.2.0
Running libtoolize...
glibtoolize: putting auxiliary files in `.'.
glibtoolize: copying file `./ltmain.sh'
glibtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'.
glibtoolize: copying file `m4/libtool.m4'
glibtoolize: copying file `m4/ltoptions.m4'
glibtoolize: copying file `m4/ltsugar.m4'
glibtoolize: copying file `m4/ltversion.m4'