github.com/rohankumardubey/nomad@v0.11.8/scripts/example_weave.bash (about) 1 #!/bin/bash 2 if [[ "$USER" != "vagrant" ]]; then 3 echo "WARNING: This script is intended to be run from Nomad's Vagrant" 4 read -rsp $'Press any key to continue anyway...\n' -n1 5 fi 6 7 set -e 8 9 if [[ ! -a /usr/local/bin/weave ]]; then 10 echo "Installing weave..." 11 sudo curl -L git.io/weave -o /usr/local/bin/weave 12 sudo chmod a+x /usr/local/bin/weave 13 fi 14 weave launch || echo "weave running" 15 eval "$(weave env)" 16 17 if curl -s localhost:8500 > /dev/null; then 18 echo "Consul running" 19 else 20 echo "Running Consul dev agent..." 21 consul agent -dev > consul.out & 22 fi 23 24 if curl -s localhost:4646 > /dev/null; then 25 echo "Nomad running" 26 else 27 echo "Running Nomad dev agent..." 28 nomad agent -dev > nomad.out & 29 fi 30 31 sleep 5 32 33 echo "Running Redis with Weave in Nomad..." 34 cat > redis-weave.nomad <<EOF 35 job "weave-example" { 36 datacenters = ["dc1"] 37 type = "service" 38 39 group "cache" { 40 count = 1 41 42 task "redis" { 43 driver = "docker" 44 config { 45 image = "redis:3.2" 46 port_map { 47 db = 6379 48 } 49 50 # Use Weave overlay network 51 network_mode = "weave" 52 } 53 54 resources { 55 cpu = 500 # 500 MHz 56 memory = 256 # 256MB 57 network { 58 mbits = 10 59 port "db" {} 60 } 61 } 62 63 # By default services will advertise the weave address 64 service { 65 name = "redis" 66 tags = ["redis", "weave-addr"] 67 port = "db" 68 69 # Since checks are done by Consul on the host system, they default to 70 # the host IP:Port. 71 check { 72 name = "host-alive" 73 type = "tcp" 74 interval = "10s" 75 timeout = "2s" 76 } 77 78 # Script checks are run from inside the container, so you can use 79 # environment vars to get the container ip:port. 80 check { 81 name = "container-script" 82 type = "script" 83 command = "/usr/local/bin/redis-cli" 84 args = ["-p", "\${NOMAD_PORT_db}", "QUIT"] 85 interval = "10s" 86 timeout = "2s" 87 } 88 } 89 90 # Setting address_mode = "host" will create a service entry with the 91 # host's address. 92 service { 93 name = "host-redis" 94 tags = ["redis", "host-addr"] 95 port = "db" 96 address_mode = "host" 97 } 98 } 99 } 100 } 101 EOF 102 103 nomad run redis-weave.nomad