mirror of
https://github.com/jpetazzo/container.training.git
synced 2026-03-06 11:20:48 +00:00
43 lines
1.7 KiB
Plaintext
Executable File
43 lines
1.7 KiB
Plaintext
Executable File
pssh -I tee /tmp/postprep.py <<EOF
|
|
#!/usr/bin/env python
|
|
import os
|
|
import sys
|
|
import urllib
|
|
|
|
clustersize = 5
|
|
|
|
myaddr = urllib.urlopen("http://myip.enix.org/REMOTE_ADDR").read()
|
|
|
|
addresses = list(l.strip() for l in sys.stdin)
|
|
|
|
def makenames(addrs):
|
|
return [ "node%s"%(i+1) for i in range(len(addrs)) ]
|
|
|
|
while addresses:
|
|
cluster = addresses[:clustersize]
|
|
addresses = addresses[clustersize:]
|
|
if myaddr not in cluster:
|
|
continue
|
|
names = makenames(cluster)
|
|
for ipaddr, name in zip(cluster, names):
|
|
os.system("grep ^%s /etc/hosts || echo %s %s | sudo tee -a /etc/hosts"
|
|
%(ipaddr, ipaddr, name))
|
|
if myaddr == cluster[0]:
|
|
os.system("[ -f .ssh/id_rsa ] || ssh-keygen -t rsa -f .ssh/id_rsa -P ''")
|
|
|
|
|
|
os.system("sudo apt-get -qy install python-setuptools pssh apache2-utils httping htop")
|
|
os.system("sudo easy_install pip")
|
|
os.system("sudo pip install docker-compose==1.4.2")
|
|
os.system("docker pull swarm:0.4.0")
|
|
os.system("docker tag -f swarm:0.4.0 swarm")
|
|
os.system("sudo curl -L https://github.com/docker/machine/releases/download/v0.4.1/docker-machine_linux-amd64 -o /usr/local/bin/docker-machine")
|
|
os.system("sudo chmod +x /usr/local/bin/docker-machine")
|
|
os.system("echo 1000000 | sudo tee /proc/sys/net/nf_conntrack_max")
|
|
os.system("""sudo sed -i 's,^DOCKER_OPTS=.*,DOCKER_OPTS="-H unix:///var/run/docker.sock -H tcp://0.0.0.0:55555",' /etc/default/docker""")
|
|
os.system("sudo service docker restart")
|
|
EOF
|
|
pssh -t 300 -I "python /tmp/postprep.py >>/tmp/pp.out 2>>/tmp/pp.err" < ips.txt
|
|
pssh "[ -f .ssh/id_rsa ] || scp -o StrictHostKeyChecking=no node1:.ssh/id_rsa* .ssh"
|
|
pssh "grep docker@ .ssh/authorized_keys || cat .ssh/id_rsa.pub >> .ssh/authorized_keys"
|