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