init.sh 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. sandbox/bin/python src/data-collector.py --path $PWD/config.json
  24. }
  25. stop(){
  26. ps -eo pid,command|grep python|grep -E "$PWD"|grep data-collector|grep -E "^ {0,}[0-9]+" -o |xargs kill -9
  27. }
  28. status(){
  29. pid=`ps -eo pid,command|grep python|grep -E "$PWD"|grep data-collector|grep -E "^ {0,}[0-9]+" -m 1 -o`
  30. if [ "$pid" = "" ]; then
  31. echo "Data Collector is Offline"
  32. else
  33. echo "Data Collector is Online $pid"
  34. fi
  35. }
  36. $1