From e4a80bf9ff3c2b5095789374e7d659e019a78497 Mon Sep 17 00:00:00 2001 From: steve Date: Wed, 3 May 2017 15:13:38 -0500 Subject: [PATCH] service script to manage components (simple interface) --- init.sh | 67 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 init.sh diff --git a/init.sh b/init.sh new file mode 100644 index 0000000..4c1df69 --- /dev/null +++ b/init.sh @@ -0,0 +1,67 @@ +#!/bin/bash +# +# This script is designed to handle various operations related to setting up, starting, stopping the python application +# It will assume the requirements file is at the root (not with the source code) +# + +export PYTHONPATH=$PWD/src +pip_upgrade='sandbox/bin/pip freeze|sort |diff requirements.txt -|grep \<|grep -E " .+$" -o' +install(){ + + virtualenv sandbox + sandbox/bin/pip install -r requirements.txt + `sandbox/bin/pip freeze|sort |diff requirements.txt -|grep \<|grep -E " .+$" -o|sandbox/bin/pip install --upgrade` + + +} +upgrade(){ + git pull + count=`sandbox/bin/pip freeze|sort |diff requirements.txt -|grep \<|grep -E " .+$" -o|wc -l` + if [ ! "$count" = "0" ]; then + `sandbox/bin/pip freeze|sort |diff requirements.txt -|grep \<|grep -E " .+$" -o|sandbox/bin/pip install --upgrade` + else + echo "No Upgrade required for sandbox" + fi + +} +start(){ + + if [ "$1" = "collector" ]; then + sandbox/bin/python src/utils/agents/data-collector.py --path $PWD/config.json + else + + sandbox/bin/python src/api/index.py --path $PWD/config.json & + fi + +} +stop(){ + ps -eo pid,command|grep python|grep -E "$PWD"|grep index.py|grep -E "^ {0,}[0-9]+" -o |xargs kill -9 + ps -eo pid,command|grep python|grep -E "$PWD"|grep data-collector|grep -E "^ {0,}[0-9]+" -o |xargs kill -9 +} + +status(){ + pid=`ps -eo pid,command|grep python|grep -E "$PWD"|grep index.py|grep -E "^ {0,}[0-9]+" -m 1 -o` + if [ "$pid" = "" ]; then + echo "API IS OFFLINE" + else + echo "API IS ONLINE $pid" + fi + pid=`ps -eo pid,command|grep python|grep -E "$PWD"|grep data-collector|grep -E "^ {0,}[0-9]+" -m 1 -o` + if [ "$pid" = "" ]; then + echo "DATA-COLLECTOR IS OFFLINE" + else + echo "DATA-COLLECTOR IS ONLINE $pid" + fi + +} + +if [ "$1" = "start" ]; then + if [ "$2" = "collector" ]; then + start "collector" + else + start + fi +else + $1 + +fi