init.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. upgrade(){
  14. git pull
  15. count=`sandbox/bin/pip freeze|sort |diff requirements.txt -|grep \<|grep -E " .+$" -o|wc -l`
  16. if [ ! "$count" = "0" ]; then
  17. `sandbox/bin/pip freeze|sort |diff requirements.txt -|grep \<|grep -E " .+$" -o|sandbox/bin/pip install --upgrade`
  18. else
  19. echo "No Upgrade required for sandbox"
  20. fi
  21. }
  22. start(){
  23. if [ "$1" = "collector" ]; then
  24. sandbox/bin/python src/utils/agents/data-collector.py --path $PWD/config.json
  25. else
  26. sandbox/bin/python src/api/index.py --path $PWD/config.json &
  27. fi
  28. }
  29. stop(){
  30. ps -eo pid,command|grep python|grep -E "$PWD"|grep index.py|grep -E "^ {0,}[0-9]+" -o |xargs kill -9
  31. ps -eo pid,command|grep python|grep -E "$PWD"|grep data-collector|grep -E "^ {0,}[0-9]+" -o |xargs kill -9
  32. }
  33. status(){
  34. pid=`ps -eo pid,command|grep python|grep -E "$PWD"|grep index.py|grep -E "^ {0,}[0-9]+" -m 1 -o`
  35. if [ "$pid" = "" ]; then
  36. echo "API IS OFFLINE"
  37. else
  38. echo "API IS ONLINE $pid"
  39. fi
  40. pid=`ps -eo pid,command|grep python|grep -E "$PWD"|grep data-collector|grep -E "^ {0,}[0-9]+" -m 1 -o`
  41. if [ "$pid" = "" ]; then
  42. echo "DATA-COLLECTOR IS OFFLINE"
  43. else
  44. echo "DATA-COLLECTOR IS ONLINE $pid"
  45. fi
  46. }
  47. if [ "$1" = "start" ]; then
  48. if [ "$2" = "collector" ]; then
  49. start "collector"
  50. else
  51. start
  52. fi
  53. else
  54. $1
  55. fi