Skip to content

Instantly share code, notes, and snippets.

@j3tm0t0
j3tm0t0 / healthcheck
Created February 13, 2014 17:31
healthcheck by ping
#!/bin/sh
count=3
timeout=2
success=0
for ip in `echo $PATH_INFO | perl -pe 's#[^\d\./]##g;s#/#\ #g'`
do
ping $ip -c $count -W $timeout > /dev/null && success=1
done
@j3tm0t0
j3tm0t0 / init.sh
Last active August 29, 2015 13:56
init script for NAT instance
#!/bin/sh -x
# function to get meta-data info
function m ()
{
curl --retry 3 --retry-delay 0 --silent --fail http://169.254.169.254/latest/meta-data/$1
}
# get REGION and setenv
export AWS_DEFAULT_REGION=`m placement/availability-zone | sed 's/.$//'`
#!/bin/sh
# This script will monitor another NAT instance and take over its routes
# if communication with the other instance fails
# NAT instance variables
# Other instance's IP to ping and route to grab if other node goes down
NAT_ID=
NAT_RT_ID=
# My route to grab when I come back up
@j3tm0t0
j3tm0t0 / init_with_eip.sh
Created February 14, 2014 18:38
same as https://gist.github.com/j3tm0t0/8980236 but with EIP for each AZ
#!/bin/sh -x
# function to get meta-data info
function m ()
{
curl --retry 3 --retry-delay 0 --silent --fail http://169.254.169.254/latest/meta-data/$1
}
# EIP for each AZ
declare -A EIP
EIP['ap-northeast-1a']='eipalloc-5887903a'
@j3tm0t0
j3tm0t0 / coffee2cfn.md
Last active August 29, 2015 13:58
CoffeeScript to generate CFN template

CoffeeScript to generate CFN template

preparation

  • install coffee script
    npm install coffee-script
  • install AWS CLI (optional)
    pip install awscli

sample

bucket.coffee

@j3tm0t0
j3tm0t0 / VyOS_AMIi_changelog.md
Last active August 29, 2015 13:58
Unofficial VyOS AMI changelog

Unofficial VyOS AMI changelog

1.0.2 rev2

  • auto load config via user-data with following format

config format

system {
  time-zone Asia/Tokyo
}
@j3tm0t0
j3tm0t0 / log.txt
Created April 11, 2014 08:58
mkdir on S3
~$ aws s3 ls s3://bucket-123/
PRE folder/
~$ aws s3api list-objects --bucket bucket-123
{
"CommonPrefixes": [],
"Contents": [
{
"LastModified": "2014-04-11T08:53:58.000Z",
"ETag": "\"d41d8cd98f00b204e9800998ecf8427e\"",
$ cat bucket.coffee
Resources =
# You can use comment!
Bucket:
Type:"AWS::S3::Bucket"
Properties:
BucketName: "my-special-bucket"
Template =
AWSTemplateFormatVersion : "2010-09-09"
@j3tm0t0
j3tm0t0 / csfn
Last active August 29, 2015 14:03
CoffeeScript + CloudFormation = CoffeeScriptFormation -> csfn
#!/bin/sh
type coffee &> /dev/null || (echo ERROR: CoffeeScript is not installed. > /dev/stderr ; exit -1 )
if [ "$1" = "" ]
then
echo "usage: `basename $0` hoge.coffee [ puge.coffee ... ] > hogepuge.template"
echo ' or aws cloudformation create-stack --stack-name STACKNAME --template-body "$(csfn hoge.coffee)"'
exit 0
fi
// ==UserScript==
// @name AWS MC FreeBSD icon
// @namespace j3tm0t0.gmail.com
// @version 0.1
// @match https://console.aws.amazon.com/ec2/v2/home?*
// ==/UserScript==
var icon = 'data:image/x-icon;base64,'+
'AAABAAIAEBAAAAEAIABoBAAAJgAAACAgAAABACAAqBAAAI4EAAAoAAAAEAAAACAAAAABACAAAAAA'+
'AEAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAADwMCACMDAQAk'+