|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +source $SRCDIR/utils.sh |
| 4 | + |
| 5 | +job_name=mosquitto |
| 6 | +filename="/mosquitto/config/mosquitto.conf" |
| 7 | + |
| 8 | +# test template stanza |
| 9 | +test_template_stanza_nomad_job() { |
| 10 | + pushd ~/go/src/github.com/Roblox/nomad-driver-containerd/example |
| 11 | + |
| 12 | + echo "INFO: Starting nomad $job_name job using nomad-driver-containerd." |
| 13 | + nomad job run -detach $job_name.nomad |
| 14 | + |
| 15 | + # Even though $(nomad job status) reports job status as "running" |
| 16 | + # The actual container process might not be running yet. |
| 17 | + # We need to wait for actual container to start running before trying exec. |
| 18 | + echo "INFO: Wait for ${job_name} container to get into RUNNING state, before trying exec." |
| 19 | + is_container_active ${job_name} true |
| 20 | + |
| 21 | + echo "INFO: Checking status of $job_name job." |
| 22 | + job_status=$(nomad job status -short $job_name|grep Status|awk '{split($0,a,"="); print a[2]}'|tr -d ' ') |
| 23 | + if [ "$job_status" != "running" ];then |
| 24 | + echo "ERROR: Error in getting ${job_name} job status." |
| 25 | + exit 1 |
| 26 | + fi |
| 27 | + |
| 28 | + # Check if bind mount exists. |
| 29 | + echo "INFO: Checking if bind mount was successful and $filename exists." |
| 30 | + nomad alloc exec -job $job_name cat $filename >/dev/null 2>&1 |
| 31 | + rc=$? |
| 32 | + if [ $rc -ne 0 ]; then |
| 33 | + echo "ERROR: bind mount was unsuccessful. $filename does not exist." |
| 34 | + exit 1 |
| 35 | + fi |
| 36 | + |
| 37 | + echo "INFO: Stopping nomad ${job_name} job." |
| 38 | + nomad job stop -detach ${job_name} |
| 39 | + job_status=$(nomad job status -short ${job_name}|grep Status|awk '{split($0,a,"="); print a[2]}'|tr -d ' ') |
| 40 | + if [ $job_status != "dead(stopped)" ];then |
| 41 | + echo "ERROR: Error in stopping ${job_name} job." |
| 42 | + exit 1 |
| 43 | + fi |
| 44 | + |
| 45 | + echo "INFO: purge nomad ${job_name} job." |
| 46 | + nomad job stop -detach -purge ${job_name} |
| 47 | + popd |
| 48 | +} |
| 49 | + |
| 50 | +test_template_stanza_nomad_job |
0 commit comments