Skip to content

Instantly share code, notes, and snippets.

@shantanugadgil
Created January 2, 2020 07:10
Show Gist options
  • Save shantanugadgil/0af69d4df486ca2da3aed9b04a84106a to your computer and use it in GitHub Desktop.
Save shantanugadgil/0af69d4df486ca2da3aed9b04a84106a to your computer and use it in GitHub Desktop.
generator to create the zookeeper job file
$ 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