stop.sh 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #!/bin/bash
  2. CURRDIR=$(realpath $(dirname $0))
  3. if [ -f "$CURRDIR/config.sh" ]; then
  4. source "$CURRDIR/config.sh"
  5. else
  6. echo '== config.sh not found, exiting...'; exit 23
  7. fi
  8. echo '== Stopping running containers...'
  9. stop_fails=0
  10. while read container; do
  11. sudo docker stop "$container"
  12. sudo docker rm "$container"
  13. if [ "$?" = "0" ]; then
  14. echo "== Stopped container: $container"
  15. sed -i "/^${container}$/d" "${CURRDIR}/run/running_containers"
  16. else
  17. echo "== Could not stop container: $container"
  18. stop_fails=$((stop_fails+1))
  19. fi
  20. done < "${CURRDIR}/run/running_containers"
  21. # All containers removed, so remove the running_containers file
  22. if [ "$stop_fails" -eq 0 ]; then
  23. rm "${CURRDIR}/run/running_containers"
  24. fi
  25. echo '== Stopping automatic tunneling url...'
  26. if [ -f "${CURRDIR}/run/tunneling_pid" ]; then
  27. kill -9 `cat "${CURRDIR}/run/tunneling_pid"` && rm "${CURRDIR}/run/tunneling_pid" && rm "${CURRDIR}/run/tunneling_url"
  28. else
  29. echo 'No record for local tunneling service found. Skipping...'
  30. fi
  31. echo '== Finished.'