Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#!/bin/bash
export DEBIAN_FRONTEND=noninteractive
sed -i 's/#PasswordAuthentication yes/PasswordAuthentication no/g' /etc/ssh/sshd_config
service ssh restart
apt-get -y update
apt-get -y install fail2ban
apt-get -y install apt-transport-https ca-certificates
apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
echo "deb https://apt.dockerproject.org/repo ubuntu-xenial experimental" > /etc/apt/sources.list.d/docker.list
apt-get -y update
apt-get -y install linux-image-extra-$(uname -r)
apt-get -y install docker-engine=1.12.0~rc4-0~xenial
service docker start
#!/bin/bash
set -euo pipefail
# Usage:
# dockerswarm100.sh create
# dockerswarm100.sh version
# dockerswarm100.sh join {swarm-secret} {swarm-manager-ip}
# dockerswarm100.sh info
# dockerswarm100.sh delete
# Requirements:
# Environment Variables:
# export RS_USERNAME={my-rackspace-username}
# export RS_API_KEY={my-rackspace-api-key}
# rack: The Rackspace command line interface for managing Rackspace services
# https://developer.rackspace.com/docs/rack-cli/configuration/#installation-and-configuration
# Keypair named swarm
# ssh-keygen -q -b 4096 -t rsa -N "" -f ~/.ssh/id_rsa.swarm
# for region in ORD IAD; do
# export RS_REGION_NAME=${region}
# rack servers keypair upload --name swarm --file ~/.ssh/id_rsa.swarm.pub
# done
main() {
echo "$@"
loop $@
}
loop() {
for region in ORD IAD; do
export RS_REGION_NAME=${region}
echo -e "Region\t\t${RS_REGION_NAME}"
for i in $(seq -f "%02g" 1 1); do
SERVER_NAME=swarm-${i}
echo -e "Name\t\t${SERVER_NAME}"
"$@"
done
done
}
create() {
rack servers instance create \
--name ${SERVER_NAME} \
--image-name "Ubuntu 16.04 LTS (Xenial Xerus) (PVHVM)" \
--flavor-name "512MB Standard Instance" \
--keypair swarm \
--user-data dockerize.sh
}
delete() {
rack servers instance delete --name ${SERVER_NAME}
}
version() {
SERVER_IP=$(get_server_ip)
DOCKER_VERSION=$(ssh -i ~/.ssh/id_rsa.swarm root@${SERVER_IP} docker version | grep Version | tail -n 1 | awk '{print $2}')
echo -e "Version\t\t${DOCKER_VERSION}"
}
hello() {
SERVER_IP=$(get_server_ip)
ssh -i ~/.ssh/id_rsa.swarm root@${SERVER_IP} docker run alpine echo "Hello World"
}
join() {
SWARM_SECRET=$1
SWARM_MANAGER_IP=$2
SERVER_IP=$(get_server_ip)
ssh -i ~/.ssh/id_rsa.swarm root@${SERVER_IP} docker swarm join --secret ${SWARM_SECRET} ${SWARM_MANAGER_IP}:2377
}
leave() {
SERVER_IP=$(get_server_ip)
ssh -i ~/.ssh/id_rsa.swarm root@${SERVER_IP} docker swarm leave
}
info() {
SERVER_IP=$(get_server_ip)
ssh -i ~/.ssh/id_rsa.swarm root@${SERVER_IP} docker info | awk '/Swarm/,/Runtimes/' | sed '$ d'
}
get_server_ip() {
echo $(rack servers instance get --name ${SERVER_NAME} --fields publicipv4 | awk '{print $2}')
}
main $@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment