dev: Tweaks to cluster dev scripts

Consolidate all nomad data dir in a single root
`/tmp/nomad-dev-cluster`.  Eases clean up.

Allow running script from any path - don't require devs to cd into
`dev/cluster` directory first.

Also, block while nomad processes are running and prapogate
SIGTERM/SIGINT to nomad processes to shutdown.
This commit is contained in:
Mahmood Ali 2020-02-03 11:50:43 -05:00
parent ea18569f2c
commit 65fb8ba637
8 changed files with 24 additions and 13 deletions

View File

@ -2,7 +2,7 @@
log_level = "DEBUG" log_level = "DEBUG"
# Setup data dir # Setup data dir
data_dir = "/tmp/client1" data_dir = "/tmp/nomad-dev-cluster/client1"
# Give the agent a unique name. Defaults to hostname # Give the agent a unique name. Defaults to hostname
name = "client1" name = "client1"

View File

@ -2,7 +2,7 @@
log_level = "DEBUG" log_level = "DEBUG"
# Setup data dir # Setup data dir
data_dir = "/tmp/client2" data_dir = "/tmp/nomad-dev-cluster/client2"
# Give the agent a unique name. Defaults to hostname # Give the agent a unique name. Defaults to hostname
name = "client2" name = "client2"

View File

@ -2,7 +2,7 @@
log_level = "DEBUG" log_level = "DEBUG"
# Setup data dir # Setup data dir
data_dir = "/tmp/client3" data_dir = "/tmp/nomad-dev-cluster/client3"
# Give the agent a unique name. Defaults to hostname # Give the agent a unique name. Defaults to hostname
name = "client3" name = "client3"

View File

@ -1,17 +1,28 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e
mkdir -p /tmp/server{1,2,3} /tmp/client{1,2} mkdir -p /tmp/nomad-dev-cluster/server{1,2,3} /tmp/nomad-dev-cluster/client{1,2}
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
# launch server # launch server
( nomad agent -config=server1.hcl 2>&1 | tee "/tmp/server1/log" ; echo "Exit code: $?" >> "/tmp/server1/log" ) & ( nomad agent -config=${DIR}/server1.hcl 2>&1 | tee "/tmp/nomad-dev-cluster/server1/log" ; echo "Exit code: $?" >> "/tmp/nomad-dev-cluster/server1/log" ) &
( nomad agent -config=server2.hcl 2>&1 | tee "/tmp/server2/log" ; echo "Exit code: $?" >> "/tmp/server2/log" ) & ( nomad agent -config=${DIR}/server2.hcl 2>&1 | tee "/tmp/nomad-dev-cluster/server2/log" ; echo "Exit code: $?" >> "/tmp/nomad-dev-cluster/server2/log" ) &
( nomad agent -config=server3.hcl 2>&1 | tee "/tmp/server3/log" ; echo "Exit code: $?" >> "/tmp/server3/log" ) & ( nomad agent -config=${DIR}/server3.hcl 2>&1 | tee "/tmp/nomad-dev-cluster/server3/log" ; echo "Exit code: $?" >> "/tmp/nomad-dev-cluster/server3/log" ) &
# launch client 1 # launch client 1
( nomad agent -config=client1.hcl 2>&1 | tee "/tmp/client1/log" ; echo "Exit code: $?" >> "/tmp/client1/log" ) & ( nomad agent -config=${DIR}/client1.hcl 2>&1 | tee "/tmp/nomad-dev-cluster/client1/log" ; echo "Exit code: $?" >> "/tmp/nomad-dev-cluster/client1/log" ) &
# launch client 2 # launch client 2
( nomad agent -config=client2.hcl 2>&1 | tee "/tmp/client2/log" ; echo "Exit code: $?" >> "/tmp/client2/log" ) & ( nomad agent -config=${DIR}/client2.hcl 2>&1 | tee "/tmp/nomad-dev-cluster/client2/log" ; echo "Exit code: $?" >> "/tmp/nomad-dev-cluster/client2/log" ) &
trap 'kill -SIGTERM $(jobs -pr)' SIGINT SIGTERM
wait
# wait again to ensure process die
wait

View File

@ -2,7 +2,7 @@
log_level = "DEBUG" log_level = "DEBUG"
# Setup data dir # Setup data dir
data_dir = "/tmp/serverstandalone" data_dir = "/tmp/nomad-dev-cluster/serverstandalone"
# Give the agent a unique name. Defaults to hostname # Give the agent a unique name. Defaults to hostname
name = "serverstandalone" name = "serverstandalone"

View File

@ -2,7 +2,7 @@
log_level = "DEBUG" log_level = "DEBUG"
# Setup data dir # Setup data dir
data_dir = "/tmp/server1" data_dir = "/tmp/nomad-dev-cluster/server1"
# Give the agent a unique name. Defaults to hostname # Give the agent a unique name. Defaults to hostname
name = "server1" name = "server1"

View File

@ -2,7 +2,7 @@
log_level = "DEBUG" log_level = "DEBUG"
# Setup data dir # Setup data dir
data_dir = "/tmp/server2" data_dir = "/tmp/nomad-dev-cluster/server2"
# Give the agent a unique name. Defaults to hostname # Give the agent a unique name. Defaults to hostname
name = "server2" name = "server2"

View File

@ -2,7 +2,7 @@
log_level = "DEBUG" log_level = "DEBUG"
# Setup data dir # Setup data dir
data_dir = "/tmp/server3" data_dir = "/tmp/nomad-dev-cluster/server3"
# Give the agent a unique name. Defaults to hostname # Give the agent a unique name. Defaults to hostname
name = "server3" name = "server3"