Created
January 2, 2020 07:10
-
-
Save shantanugadgil/0af69d4df486ca2da3aed9b04a84106a to your computer and use it in GitHub Desktop.
generator to create the zookeeper job file
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ cat generate_job_file.bash | |
#!/bin/bash | |
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 | |
set -u | |
job_file="zookeeper.nomad" | |
cat > ${job_file} <<EOF | |
job "zookeeper_test" { | |
datacenters = ["dc1"] | |
type = "service" | |
constraint { | |
attribute = "\${attr.kernel.name}" | |
value = "linux" | |
} | |
EOF | |
for zkid in {1..3}; do | |
cat >> $job_file <<EOF | |
############################################################ | |
# zookeeper [$zkid] | |
group "zookeeper_${zkid}" { | |
constraint { | |
attribute = "\${meta.zookeeperid}" | |
value = "$zkid" | |
} | |
count = 1 | |
task "zk" { | |
driver = "raw_exec" | |
artifact { | |
source = "http://192.168.0.100/my_zk_data/bin/apache-zookeeper-3.5.6-bin.tar.gz" | |
destination = "local/" | |
} | |
artifact { | |
source = "http://192.168.0.100/my_zk_data/scripts/zk_starter.bash" | |
destination = "local/zk_starter.bash" | |
mode = "file" | |
} | |
artifact { | |
source = "http://192.168.0.100/my_zk_data/config/configuration.xsl" | |
destination = "local/zkconfig/configuration.xsl" | |
mode = "file" | |
} | |
artifact { | |
source = "http://192.168.0.100/my_zk_data/config/log4j.properties" | |
destination = "local/zkconfig/log4j.properties" | |
mode = "file" | |
} | |
template { | |
data = <<EOH | |
tickTime=2000 | |
dataDir=/var/lib/zookeeper | |
clientPort=2181 | |
maxClientCnxns=120 | |
initLimit=50 | |
syncLimit=10 | |
4lw.commands.whitelist=* | |
{{range \$i, \$node := nodes}}{{if index .Meta "zookeeperid" | regexMatch "^\\\\d+$"}}server.{{index .Meta "zookeeperid"}}={{.Address}}:2888:3888 | |
{{end}}{{end}} | |
EOH | |
destination = "local/zkconfig/zoo.cfg" | |
} | |
env { | |
"ZOOKEEPER_ID" = "\${meta.zookeeperid}" | |
} | |
config { | |
command = "/bin/bash" | |
args = ["local/zk_starter.bash", "local/apache-zookeeper-3.5.6-bin", "local/zkconfig"] | |
} | |
resources { | |
cpu = 2000 | |
memory = 2000 | |
network { | |
port "zookeeper" { | |
static = 2181 | |
} | |
} | |
} # resources | |
service { | |
name = "zookeeper" | |
port = "zookeeper" | |
check { | |
name = "zookeeper" | |
type = "tcp" | |
interval = "60s" | |
timeout = "10s" | |
port = "zookeeper" | |
} | |
} # service | |
} # task | |
} # group | |
EOF | |
done | |
cat >> $job_file <<EOF | |
} # job | |
EOF | |
set -x | |
hclfmt -w $job_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment