monitor_entrypoint.sh 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. echo '*** Waiting for initial identity generation...'
  22. while [ ! -s /var/lib/zerotier-one/identity.secret ]; do
  23. sleep 0.2
  24. done
  25. echo '*** Waiting for network config...'
  26. virtip4=""
  27. while [ ! -s /var/lib/zerotier-one/networks.d/"$nwconf" ]; do
  28. sleep 0.2
  29. done
  30. while [ -z "$virtip4" ]; do
  31. sleep 0.2
  32. virtip4=`/zerotier-cli listnetworks | grep -F $nwid | cut -d ' ' -f 9 | sed 's/,/\n/g' | grep -F '.' | cut -d / -f 1`
  33. done
  34. echo '*** Starting Test...'
  35. echo '*** Up and running at' $virtip4 ' on network: ' $nwid
  36. echo '*** Sleeping for (' "$netcon_wait_time" 's ) while we wait for the Network Container to come online...'
  37. sleep "$netcon_wait_time"s
  38. ncvirtip=$(<$address_file)
  39. # --- Test section ---
  40. echo '*** Curling from intercepted server at' $ncvirtip
  41. response_string=$(curl --connect-timeout "$app_timeout_time" -v http://"$ncvirtip":8080/)
  42. if [[ $response_string == *"welcome to the machine!"* ]]
  43. then
  44. echo 'NODEJS RESPONSE OK'
  45. touch "$file_path$ok$test_name.txt"
  46. printf 'Test: nodejs-server responded!\n' >> "$file_path$ok$test_name.txt"
  47. else
  48. echo 'NODEJS RESPONSE FAIL'
  49. touch "$file_path$fail$test_name.txt"
  50. printf 'Test: nodejs server did NOT respond!\n' >> "$file_path$fail$test_name.txt"
  51. fi