Skip to content

Instantly share code, notes, and snippets.

@charlesmarshall
charlesmarshall / coreos-cloud-init-host-access-only
Created June 8, 2014 11:50
CoreOS Cloud-Init with host access and etcd tokens only
#cloud-config
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB ...snip... QAyapHGwoBvkq7nNp
coreos:
etcd:
# via https://discovery.etcd.io/new
discovery: https://discovery.etcd.io/7028e012ca66ef0121b64c19c40a425a
addr: $private_ipv4:4001
peer-addr: $private_ipv4:7001
write_files:
@charlesmarshall
charlesmarshall / coreos-cloud-init-fleet-etcd-start
Created June 8, 2014 12:09
CoreOS Cloud-Init with fleet and etcd start up
#cloud-config
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB ...snip... QAyapHGwoBvkq7nNp
coreos:
etcd:
# via https://discovery.etcd.io/new
discovery: https://discovery.etcd.io/7028e012ca66ef0121b64c19c40a425a
addr: $private_ipv4:4001
peer-addr: $private_ipv4:7001
units:
@charlesmarshall
charlesmarshall / coreos-cloud-init-host-announce
Created June 9, 2014 08:43
CoreOS Cloud-Init with host announcement service
#cloud-config
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB ...snip... QAyapHGwoBvkq7nNp
coreos:
etcd:
# via https://discovery.etcd.io/new
discovery: https://discovery.etcd.io/7028e012ca66ef0121b64c19c40a425a
addr: $private_ipv4:4001
peer-addr: $private_ipv4:7001
units:
@charlesmarshall
charlesmarshall / coreos-cloud-init-env
Created June 9, 2014 09:15
CoreOS Cloud-Init with amends to environment file
#cloud-config
ssh_authorized_keys:
- ssh-rsa AAAAB3NzaC1yc2EAAAADAQAB ...snip... QAyapHGwoBvkq7nNp
coreos:
etcd:
# via https://discovery.etcd.io/new
discovery: https://discovery.etcd.io/7028e012ca66ef0121b64c19c40a425a
addr: $private_ipv4:4001
peer-addr: $private_ipv4:7001
units:
@charlesmarshall
charlesmarshall / coreos-etcd-sync-check
Created June 9, 2014 09:49
CoreOS etcd sync check
etcd_sync_check(){
count=0;
while ( true ); do
check=$(etcdctl ls / | grep 'Cannot sync' | wc -l) ;
if [ $check -eq 0 ]; then
break ;
else
warning "Cannot connect to etcd"
if [ $count -gt 50 ]; then
fatal "Failed to connect to etcd"
@charlesmarshall
charlesmarshall / coreos-simple-service-registry
Last active August 29, 2015 14:04
CoreOS setting up Docker registry
docker pull registry:latest && docker run --rm --name registry -p 5000:5000 registry
@charlesmarshall
charlesmarshall / coreos-simple-service-docker-service
Created July 22, 2014 12:24
CoreOS Docker registry as a service
[Unit]
Description=Docker registry
After=etcd.service
After=docker.service
[Service]
ExecStop=/usr/bin/bash -l -c "docker stop registry ;"
ExecStart=/usr/bin/bash -l -c "docker pull registry:latest ; docker run --rm --name registry -p 5000:5000 registry ;"
@charlesmarshall
charlesmarshall / website-service-file.service
Last active August 29, 2015 14:04
basic website service file
[Unit]
Description=Example website
After=etcd.service
After=docker.service
[Service]
ExecStop=/usr/bin/bash -l -c "docker stop $image_name ;"
ExecStart=/usr/bin/bash -l -c "docker pull $registry_ip:5000/$image_name ; docker run --rm --name $container_name -p 80:80 -i $image_name /bin/bash -l -c "service nginx start";"
@charlesmarshall
charlesmarshall / website-service-dynamic-port.service
Created July 25, 2014 14:10
basic website without hard coded port mapping
[Unit]
Description=Example website
After=etcd.service
After=docker.service
[Service]
ExecStop=/usr/bin/bash -l -c "docker stop $image_name ;"
ExecStart=/usr/bin/bash -l -c "docker pull $registry_ip:5000/$image_name ; docker run --rm --name $container_name -p 80 -i $image_name /bin/bash -l -c "service nginx start";"
@charlesmarshall
charlesmarshall / get-service-ip-and-port.sh
Last active August 29, 2015 14:04
Use a service name to find the ip & port that its running on
# $1 = service name
# $2 = service internal port
getServiceIPAndPort(){
local id=$(docker ps -a | grep "\( ${1}\)" | awk '{ print $1 }')
local port=$(docker port $id $2 | sed -r 's#0.0.0.0:##gi')
if [[ -z $port ]]; then
sleep 5
getServiceIPAndPort "${1}" "${2}"
fi
echo "${COREOS_PRIVATE_IPV4}:${port}"