monitor_entrypoint.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. export PATH=/bin:/usr/bin:/usr/local/bin:/sbin:/usr/sbin:/
  3. # --- Test Parameters ---
  4. test_namefile=$(ls *.name)
  5. test_name="${test_namefile%.*}" # test network id
  6. nwconf=$(ls *.conf) # blank test network config file
  7. nwid="${nwconf%.*}" # test network id
  8. netcon_wait_time=25 # wait for test container to come online
  9. app_timeout_time=15 # app-specific timeout
  10. file_path=/opt/results/ # test result output file path (fs shared between host and containers)
  11. file_base="$test_name".txt # test result output file
  12. fail=FAIL. # appended to result file in event of failure
  13. ok=OK. # appended to result file in event of success
  14. tmp_ext=.tmp # temporary filetype used for sharing test data between containers
  15. address_file="$file_path$test_name"_addr"$tmp_ext" # file shared between host and containers for sharing address (optional)
  16. # --- Network Config ---
  17. echo '*** ZeroTier Network Containers Test Monitor'
  18. chown -R daemon /var/lib/zerotier-one
  19. chgrp -R daemon /var/lib/zerotier-one
  20. su daemon -s /bin/bash -c '/zerotier-one -d -U -p9993 >>/tmp/zerotier-one.out 2>&1'
  21. virtip4=""
  22. while [ -z "$virtip4" ]; do
  23. sleep 0.2
  24. virtip4=`/zerotier-cli listnetworks | grep -F $nwid | cut -d ' ' -f 9 | sed 's/,/\n/g' | grep -F '.' | cut -d / -f 1`
  25. done
  26. echo '*** Starting Test...'
  27. echo '*** Up and running at' $virtip4 ' on network: ' $nwid
  28. echo '*** Sleeping for (' "$netcon_wait_time" 's ) while we wait for the Network Container to come online...'
  29. sleep "$netcon_wait_time"s
  30. ncvirtip=$(<$address_file)
  31. # --- Test section ---
  32. echo '*** Running lua script against redis host at' $ncvirtip
  33. redis-cli -h $ncvirtip EVAL "$(cat hello.lua)" 0 > redis_response.txt
  34. response_string=$(<redis_response.txt)
  35. if [[ $response_string == *"welcome to the machine!"* ]]
  36. then
  37. echo 'REDIS RESPONSE OK'
  38. touch "$file_path$ok$test_name.txt"
  39. printf 'Test: redis-server responded!\n' >> "$file_path$ok$test_name.txt"
  40. else
  41. echo 'REDIS RESPONSE FAIL'
  42. touch "$file_path$fail$test_name.txt"
  43. printf 'Test: redis server did NOT respond!\n' >> "$file_path$fail$test_name.txt"
  44. fi