2018-04-02 06:10:21 +02:00
#!/usr/bin/env bash
2017-08-24 16:02:28 +02:00
2018-07-13 15:37:10 +02:00
#set -x
2017-08-24 16:02:28 +02:00
GREEN = "\\033[1;32m"
DEFAULT = "\\033[0;39m"
RED = "\\033[1;31m"
2019-08-30 11:39:14 +02:00
function wait_until_redis_is_ready {
redis_not_ready = true
while $redis_not_ready ; do
if checking_redis; then
redis_not_ready = false;
else
sleep 1
fi
done
echo -e $GREEN "* Redis 6250 is running" $DEFAULT
}
function checking_redis {
flag_redis = 0
bash -c 'redis-cli -p 6250 PING | grep "PONG" &> /dev/null'
if [ ! $? = = 0 ] ; then
echo -e $RED "Redis 6250 not ready" $DEFAULT
flag_redis = 1
fi
sleep 0.1
return $flag_redis ;
}
2018-04-01 18:59:08 +02:00
# Getting CWD where bash script resides
DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
2018-04-02 07:13:46 +02:00
DASH_HOME = " ${ DIR } "
2018-04-01 18:59:08 +02:00
2018-04-02 06:32:32 +02:00
cd ${ DASH_HOME }
2018-04-01 18:59:08 +02:00
if [ -e " ${ DIR } /DASHENV/bin/python " ] ; then
echo "dashboard virtualenv seems to exist, good"
2018-04-02 07:13:46 +02:00
ENV_PY = " ${ DIR } /DASHENV/bin/python "
2018-04-01 18:59:08 +02:00
else
echo "Please make sure you have a dashboard environment, au revoir"
exit 1
fi
2017-08-24 16:02:28 +02:00
2019-05-08 13:03:27 +02:00
if [ [ -f "/etc/redhat-release" ] ] ; then
echo "You are running a RedHat flavour. Detecting scl potential..."
2019-05-08 13:11:31 +02:00
if [ [ -f "/usr/bin/scl" ] ] ; then
2019-05-08 13:03:27 +02:00
echo "scl detected, checking for redis-server"
SCL_REDIS = $( scl -l| grep rh-redis)
if [ [ ! -z $SCL_REDIS ] ] ; then
echo " We detected: ${ SCL_REDIS } acting accordingly "
REDIS_RUN = " /usr/bin/scl enable ${ SCL_REDIS } "
fi
else
echo "redis-server seems not to be install in scl, perhaps system-wide, testing."
[ ! -f "`which redis-server`" ] && echo "'redis-server' is not installed/not on PATH. Please fix and run again." && exit 1
fi
else
[ ! -f "`which redis-server`" ] && echo "'redis-server' is not installed/not on PATH. Please fix and run again." && exit 1
fi
2018-01-06 12:07:14 +01:00
2018-04-02 06:32:32 +02:00
netstat -an | grep LISTEN | grep 6250 | grep -v tcp6 ; check_redis_port = $?
2018-04-06 07:27:38 +02:00
netstat -an | grep LISTEN | grep 8001 | grep -v tcp6 ; check_dashboard_port = $?
2018-03-31 12:58:38 +02:00
2018-01-06 20:51:23 +01:00
# Configure accordingly, remember: 0.0.0.0 exposes to every active IP interface, play safe and bind it to something you trust and know
export FLASK_APP = server.py
export FLASK_DEBUG = 0
export FLASK_PORT = 8001
export FLASK_HOST = 127.0.0.1
2018-01-06 12:07:14 +01:00
2018-04-02 07:42:06 +02:00
conf_dir = "config/"
2018-01-06 12:07:14 +01:00
2017-08-24 16:02:28 +02:00
sleep 0.1
2018-04-02 06:32:32 +02:00
if [ " ${ check_redis_port } " = = "1" ] ; then
2019-05-08 13:07:47 +02:00
echo -e $GREEN "\t* Launching Redis servers" $DEFAULT
2019-05-09 01:08:54 +02:00
if [ [ ! -z $REDIS_RUN ] ] ; then
2019-05-08 13:07:47 +02:00
$REDIS_RUN " redis-server ${ conf_dir } 6250.conf " &
else
redis-server ${ conf_dir } 6250.conf &
fi
2018-03-31 12:58:38 +02:00
else
echo -e $RED "\t* NOT starting Redis server, made a very unrealiable check on port 6250, and something seems to be there… please double check if this is good!" $DEFAULT
fi
2017-08-24 16:02:28 +02:00
2018-04-06 07:27:38 +02:00
sleep 0.1
2019-08-30 11:39:14 +02:00
wait_until_redis_is_ready;
2018-04-06 07:27:38 +02:00
if [ " ${ check_dashboard_port } " = = "1" ] ; then
echo -e $GREEN "\t* Launching flask server" $DEFAULT
${ ENV_PY } ./server.py &
else
echo -e $RED "\t* NOT starting flask server, made a very unrealiable check on port 8001, and something seems to be there… please double check if this is good!" $DEFAULT
fi
2019-06-21 12:35:53 +02:00
sleep 0.1
2019-07-02 11:57:46 +02:00
sudo -u zmqs /bin/bash ${ DIR } /start_zmq.sh &