Skip to content

Instantly share code, notes, and snippets.

View progrium's full-sized avatar

Jeff Lindsay progrium

View GitHub Profile
@progrium
progrium / consulkv
Created June 4, 2014 22:21
Consul KV client, depends on jq
#!/bin/bash
CONSUL="localhost:8500"
main() {
case "$1" in
info)
curl -s "$CONSUL/v1/kv/$2" | jq -r .[]
;;
get)
{
"ssl_certificate": {"$file": "/nginx/files/foobar"},
"user": ["nobody", "nogroup"],
"events": {
"worker_connections": 1024,
"accept_mutex": "on"
},
"http": {
"gzip_disable": "\"MSIE [1-6]\\.\"",
"upstream": {
#!/bin/bash
foo() {
echo "foo: exported from file1"
}
locals() {
bar() {
echo "bar: local to file1"
}
-----> Python app detected
-----> Preparing Python runtime (python-2.7.7)
Traceback (most recent call last):
File "/tmp/buildpacks/heroku-buildpack-python/vendor/bpwatch/bpwatch", line 13, in <module>
import bp_cli
File "/tmp/buildpacks/heroku-buildpack-python/vendor/bpwatch/bpwatch.zip/bp_cli.py", line 26, in <module>
File "/tmp/buildpacks/heroku-buildpack-python/vendor/bpwatch/bpwatch.zip/logplex/__init__.py", line 1, in <module>
File "/tmp/buildpacks/heroku-buildpack-python/vendor/bpwatch/bpwatch.zip/logplex/core.py", line 8, in <module>
File "/tmp/buildpacks/heroku-buildpack-python/vendor/bpwatch/bpwatch.zip/logplex/packages/requests/__init__.py", line 58, in <module>
File "/tmp/buildpacks/heroku-buildpack-python/vendor/bpwatch/bpwatch.zip/logplex/packages/requests/utils.py", line 12, in <module>
destructuring_assignment_for_named_local_args() {
declare numbers letters words
read numbers letters words <<<"$@"
echo "$numbers"
echo "$letters"
echo "$words"
}
destructuring_assignment_for_named_local_args 123 abc "Hello world"
FROM ubuntu:trusty
MAINTAINER Jeff Lindsay <progrium@gmail.com>
RUN apt-get -y install unzip
ADD https://dl.bintray.com/mitchellh/consul/0.2.0_linux_amd64.zip /tmp/consul.zip
RUN cd /usr/local/sbin && unzip /tmp/consul.zip && chmod +x /usr/local/sbin/consul
EXPOSE 8300 8301 8302
ENTRYPOINT ["/usr/local/sbin/consul", "agent", "-server", "-data-dir=/tmp/consul"]
@progrium
progrium / gist:8641641
Created January 27, 2014 01:04
version of skybash-runner that would encrypt variables. ended up not using that because it will be protected to begin with, but wanted to keep the code around since it took a while to figure out
package main
import (
"bufio"
"crypto/sha1"
"crypto/tls"
"encoding/base64"
"encoding/hex"
"io"
"io/ioutil"

Discoverd Leader Election API

Notes:

  • cannot be used for multiple leaders/quorum
  • races between leader updates in servers/clients should be handled by message queuing and/or retry

Server Patterns

Many uncoordinated active servers (no leaders)

// many servers, one master, many clients
// server
set, err := discoverd.Register("db", 9099)
<-set.BecomeLeader()
// client
set, err := discoverd.ServiceSet("db")
leader := <-set.NewLeader()
@progrium
progrium / sshmany
Last active April 20, 2016 12:37
bash script for executing a command via ssh in parallel on multiple servers with colored output
#!/bin/bash
#
# Usage:
# $ echo "host1 host2 host3" | ./sshmany uname -a
# $ cat myservers | ./sshmany echo Hello world
#
cmd="$@"
servers="$(cat)"
i=37
for server in $servers; do