movierec-run-server.sh 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #!/bin/bash
  2. #
  3. # Script to run movierec. Run server with trained model and enable command-line client.
  4. # - To run on a provisioned DAIR Ubuntu 18.04 Base Cloud Image instance (see movierec-provision.sh).
  5. # - Download model and client code.
  6. # - Run inferece server and create container for testing command line client.
  7. #
  8. set -e
  9. export DEBIAN_FRONTEND=noninteractive
  10. echo "movierec-run-server: Get code and models"
  11. cd /home/ubuntu/
  12. wget --no-check-certificate https://code.cloud.canarie.ca:3000/carlamb/MovieRecommender/archive/master.zip
  13. unzip master.zip
  14. cd movierecommender/modelstrt
  15. unzip movierec.zip
  16. rm movierec.zip
  17. # stop if already running
  18. docker ps -q --filter "name=trtserver" | grep -q . && docker stop trtserver
  19. # run inference server with heath check that verifies api status
  20. # and wait until server is healthy to exit the command
  21. echo "movierec-run-server: Run inference server"
  22. nvidia-docker run -d --rm --name trtserver \
  23. --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 \
  24. -p8000:8000 -p8001:8001 -p8002:8002 \
  25. -v/home/ubuntu/movierecommender/modelstrt:/models \
  26. --health-cmd='curl localhost:8000/api/status | grep "ready_state: SERVER_READY" || exit 1' \
  27. --health-timeout=10s \
  28. --health-interval=1s \
  29. nvcr.io/nvidia/tensorrtserver:19.02-py3 \
  30. trtserver --model-store=/models && \
  31. c=0 && sleep 2 && \
  32. until docker inspect --format "{{json .State.Health.Status }}" trtserver | \
  33. grep -m 1 '"healthy"'; do
  34. ((c++)) && ((c>50)) && break
  35. sleep 2
  36. done
  37. # stop if already running
  38. docker ps -q --filter "name=trtclient" | grep -q . && docker stop trtclient
  39. # run docker for client
  40. echo "movierec-run-server: Run docker for client command line"
  41. nvidia-docker run --rm -d -it --net=host --name trtclient \
  42. --shm-size=1g --ulimit memlock=-1 --ulimit stack=67108864 \
  43. -v /home/ubuntu/movierecommender/movierec:/workspace/movierec \
  44. nvcr.io/nvidia/tensorflow:19.02-py3 \
  45. /bin/bash -c "cd /workspace/ && mkdir clients && cd clients && \
  46. wget https://github.com/NVIDIA/tensorrt-inference-server/releases/download/v0.11.0/v0.11.0.clients.tar.gz && \
  47. tar xzf v0.11.0.clients.tar.gz && apt-get update && apt-get -y install python3-pip libcurl3 && \
  48. pip3 install --user --upgrade python/tensorrtserver-*.whl pillow && cd .. && bash"
  49. # for return status
  50. docker inspect --format "{{json .State.Health.Status }}" trtserver | \
  51. grep -m 1 '"healthy"'