init.sh 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/bin/bash
  2. #
  3. # This script is designed to handle various operations related to setting up, starting, stopping the python application
  4. # It will assume the requirements file is at the root (not with the source code)
  5. #
  6. export PYTHONPATH=$PWD/src
  7. pip_upgrade='sandbox/bin/pip freeze|sort |diff requirements.txt -|grep \<|grep -E " .+$" -o'
  8. install(){
  9. virtualenv sandbox
  10. sandbox/bin/pip install -r requirements.txt
  11. `sandbox/bin/pip freeze|sort |diff requirements.txt -|grep \<|grep -E " .+$" -o|sandbox/bin/pip install --upgrade`
  12. }
  13. register(){
  14. #
  15. # $1 uid customer's identifier (email)
  16. # $2 pid customer's plan identifier
  17. #
  18. curl -X POST https://the-phi.com/store/init/monitor-logs -H "uid:$1" -H"pid: $2"
  19. }
  20. upgrade(){
  21. git pull
  22. count=`sandbox/bin/pip freeze|sort |diff requirements.txt -|grep \<|grep -E " .+$" -o|wc -l`
  23. if [ ! "$count" = "0" ]; then
  24. `sandbox/bin/pip freeze|sort |diff requirements.txt -|grep \<|grep -E " .+$" -o|sandbox/bin/pip install --upgrade`
  25. else
  26. echo "No Upgrade required for sandbox"
  27. fi
  28. }
  29. start(){
  30. sandbox/bin/python src/data-collector.py --path $PWD/config.json
  31. }
  32. stop(){
  33. ps -eo pid,command|grep python|grep -E "$PWD"|grep data-collector|grep -E "^ {0,}[0-9]+" -o |xargs kill -9
  34. }
  35. status(){
  36. pid=`ps -eo pid,command|grep python|grep -E "$PWD"|grep data-collector|grep -E "^ {0,}[0-9]+" -m 1 -o`
  37. if [ "$pid" = "" ]; then
  38. echo "DATA-COLLECTOR IS OFFLINE"
  39. else
  40. echo "DATA-COLLECTOR IS ONLINE $pid"
  41. fi
  42. }
  43. $1