Skip to content

Instantly share code, notes, and snippets.

View skwp's full-sized avatar

Yan Pritzker skwp

View GitHub Profile
#!/usr/bin/env bash
#Find the ip addresses of running instances
# set -f disables file globbing so wthat we can invoke ./list-nodes test1 '*'
# otherwise the star is expanded and messes with the command
set -f
network_name=$1
role=$2
provider "aws" {
region = "us-east-1"
shared_credentials_file = "~/.aws/credentials"
profile = "${var.aws_profile}"
}
terraform {
backend "s3" {
bucket = "your.bucket.com"
key = "path/to"
# Turn on mining if needed
if [[ "$TAG_mining" == "true" ]]; then
log "Enabling mining on this node..."
if [[ "$TAG_mining_type" == "cpuminer" ]]; then
bitcoinExec getnewaddress
docker run -d --name miner wernight/cpuminer-multi:alpine cpuminer -a sha256d -o http://$DOCKER_HOST_ADDRESS:9332 -O $TAG_rpcuser:$TAG_rpcpassword --coinbase-addr=$bitcoinExecResult --no-longpoll --no-stratum --no-extranonce --no-getwork
else
mining_rpc_call="setgenerate true $TAG_mining_cores"
mining_command="docker exec bitcoin /usr/local/bin/bitcoin-cli -rpcuser=$TAG_rpcuser -rpcpassword=$TAG_rpcpassword $mining_rpc_call"
BITCOIN_ECR_IMAGE=$AWS_ACCOUNT.dkr.ecr.$ECR_REGION.amazonaws.com/bitcoin-unlimited:$TAG_bitcoin_ecr_tag
# Log in to ECR so we can pull the docker image
$(/usr/local/bin/aws ecr get-login --region $ECR_REGION --no-include-email)
docker pull $BITCOIN_ECR_IMAGE
docker run -d --name bitcoin \
-p ${BITCOIN_RPC_PORT}-${BITCOIN_PORT}:${BITCOIN_RPC_PORT}-${BITCOIN_PORT} \
--restart unless-stopped \
-v /var/bitcoin:/var/bitcoin \
if [[ -z "$TAG_restore_backup" ]]; then
log "Tag restore_backup not set. Not restoring from backup, this is a clean node."
else
log "Restoring backup from $TAG_restore_backup"
/usr/local/bin/aws s3 cp $TAG_restore_backup /tmp
cd /
tar zxvf /tmp/bitcoin.tgz
fi
@skwp
skwp / read-tags.sh
Created October 2, 2018 16:12
AWS instance reads its own tags
# Magic AWS ip that gives you metadata about the instance
METADATA="http://169.254.169.254/latest"
# Read the AWS tag for the netmagic value that will control which
# Test network this instance will join
INSTANCE_ID="$(curl -s $METADATA/meta-data/instance-id)"
REGION="$(curl -s $METADATA/dynamic/instance-identity/document | grep region | awk -F\" '{print $4}')"
AWS_ACCOUNT="$(curl -s $METADATA/dynamic/instance-identity/document | grep accountId | awk -F\" '{print $4}')"
ECR_REGION=us-east-1
MY_IP=$(curl -s $METADATA/meta-data/public-ipv4)
resource "aws_instance" "client" {
tags {
Name = "client"
bitcoind_flags = "${var.bitcoind_flags}"
dns_name = "client${count.index}.${var.network_name}.${var.domain}"
domain = "${var.domain}"
mining = "false"
network_name = "${var.network_name}"
node_name = "client${count.index}"
node_number = "${count.index}"

Keybase proof

I hereby claim:

  • I am skwp on github.
  • I am skwp (https://keybase.io/skwp) on keybase.
  • I have a public key ASCybUSSHmHZMwJIM9bYNqfIaC1jxHOi4F_gORXRJ7Tnago

To claim this, I am signing this object:

@skwp
skwp / fastly_fluentd.conf
Created March 22, 2017 17:53
Fastly syslog listener for fluentd
<source>
@type tcp
tag fastly
format /token="secret_goes_here" service="(?<data_fastly_service>.+)" remote_address="(?<data_remote_address>.+)" timestamp="\[(?<time>.+)\]" request="(?<data_request>.+)" status="(?<data_status>.+)" size="(?<data_size>.+)"/
time_format %d/%b/%Y:%H:%M:%S %z
port 5140
bind 0.0.0.0
</source>
{
"Count": 1,
"Items": [
{
"my_key": {
"S": "my_val"
},
"updated_at": {
"S": "2016-10-15T01:44:17Z"
},