This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "json" | |
require "rexml/document" | |
require "time" | |
require "unpack_strategy" | |
require "lazy_object" | |
require "cgi" | |
class AbstractDownloadStrategy | |
extend Forwardable | |
include FileUtils |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
aws ec2 describe-spot-instance-requests \ | |
--filters Name=instance-id,Values="$(wget -q -O - http://169.254.169.254/latest/meta-data/instance-id)" \ | |
--region us-east-1 | \ | |
jq -r '.SpotInstanceRequests | if length > 0 then "spot" else "normal" end' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# exit when any command fails | |
set -e | |
current_command=$BASH_COMMAND | |
last_command="" | |
# keep track of the last executed command | |
trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
HTTP_STATUS_CODE=421 | |
CF_DISTRIBUTION_NAME=foobar | |
s3cmd "s3://${S3_BUCKET}/${LOGS_PREFIX}" | |
## OR s3cmd "s3://${S3_BUCKET}/${LOGS_PREFIX}/${CF_DISTRIBUTION_NAME}" to download only specific distributions | |
zcat *.gz | awk 'match($9, /421/) && match($7, /foobar/) { print $7" "$9" "$16" "$10 }' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
set -e | |
export CONSUL_HTTP_ADDR="https://my-consul-address" | |
VALUE=$(consul kv get <key>) | |
if [ "$VALUE" != "locked" ]; then | |
# Unlocked, check the timeout | |
TIMEOUT=$(echo $VALUE | jq 'reduce .[] as $num (0; .+$num)') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
###################################################################### | |
# Waits for Mongodb, Redis and Mysql to be ready | |
# usage examples: | |
# wait-for-dependencies.sh echo "READY TO GO" | |
# wait-for-dependencies.sh make build | |
# Exit Codes: 0 for success, 2 if wait command timed out | |
###################################################################### |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://help.datadoghq.com/hc/en-us/articles/206441345-Send-metrics-and-events-using-dogstatsd-and-the-shell | |
# Send an event to DD based on success or failure | |
echo "_e{${#title},${#text}}:$title|$text|t:${alert_type}" | nc -u -w1 "${HOST_IP}" 8125 | |
if [ "$CMD_EXIT_CODE" -eq 0 ]; | |
echo "foo.bar.success:1|g" | nc -u -w1 "${HOST_IP}" 8125 | |
then | |
echo "foo.bar.failure:1|g" | nc -u -w1 "${HOST_IP}" 8125 | |
fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This script will send a signal to a container | |
# Sleep for a random time b/w 1 to 3 seconds to avoid restarting at the exact same time | |
# This bc format of finding random doesn't print scientific notation which sometimes sleep doesn't like a lot | |
/bin/sleep "$(echo "scale=3; 0.5 + 2.5 * $RANDOM / 32767" | bc)s" | |
## Running in silent curl mode (-s and > /dev/null) - remember while debugging | |
if curl --silent --show-error --output /dev/null --unix-socket /var/run/docker.sock -X POST "http/containers/${CONTAINER_ID}/kill?signal=SIGUSR2" ; then | |
echo "Successfully sent signal to $CONTAINER_ID" | |
else | |
echo "Failed to send signal to $CONTAINER_ID. Triggering alarms." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
###### ERROR TRAP - DONT WRITE OTHER COMMANDS BEFORE THIS ############ | |
set -eEx | |
function HANDLE_ERROR() { | |
echo "SCRIPT FAILED" | |
echo "FAILED AT: $(caller)" | |
# Do any other commands here | |
exit 1 | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### example for setting up a make workflow that can tag images based on the git tag | |
### the trailing ; are important: runs the commands in the same "shell" and the $$tag variable flows through | |
docker-build: | |
@echo "Latest 3 tags: "; \ | |
git ls-remote --sort='v:refname' --tags ./. | tail -n 3; \ | |
read -p "Enter New Tag:" tag; \ | |
echo "Releasing new tag: $$tag"; \ | |
git tag $$tag; \ | |
git push origin $$tag -f; \ |