-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstart.bash
105 lines (96 loc) · 3.81 KB
/
start.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/bin/bash
# Takes redis server location, and asks user to confirm starting the server
function start_local_redis {
if [ -f $1 ];
then
read -r -p "Start redis-server found at $1 [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
$1 --daemonize yes
echo "Redis Server Started"
else
exit 1
fi
fi
}
# Checks if redis-server is already downloaded locally
if [ -f "./redis_dir/redis-stable/src/redis-server" ]
then
echo "redis-server locally available"
start_local_redis "./redis_dir/redis-stable/src/redis-server"
# Alternatively, is redis-server available in the path, if not, download and build the server/cli
elif ! redis_loc="$(type -p "redis-server")" || [[ -z /usr/local/bin/.redis-server ]];
then
echo "Redis is not installed"
echo "Redis uses the license at https://redis.io/topics/license"
echo "The license may also be found at ./redis-dir/Redis-License,"
echo "although the linked license is the current, authoritative version"
echo "By installing, you agree to the terms of this license"
read -r -p "Install Redis? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
[[ -d ./redis_dir/redis_dir ]] && rm -r ./redis_dir/redis-stable || echo "redis-stable directory handling"
curl -so - http://download.redis.io/redis-stable.tar.gz | tar -C ./redis_dir -xvzf -
make -C ./redis_dir/redis-stable
start_local_redis "./redis_dir/redis-stable/src/redis-server"
else
exit 1
fi
# Starts redis server in path
else
redis_path = $(type -p redis-server | cut -d" " -f3)
echo "Redis Installation Found at: $redis_path"
type -p "redis-server"
echo "Starting redis:"
redis-server --daemonize yes
fi
# Function used with trap to shutdown redis server cleanly as part of exiting program
function shutdown_with_redis {
./redis_dir/redis-stable/src/redis-cli SHUTDOWN
echo "Redis Server shutdown"
echo "Thanks for using tesla-ver!"
exit 0
}
trap "shutdown_with_redis" SIGINT
# Sources conda behavior scripts, and then generates/checks for existing tesla-ver environment,
# and then activates the tesla-ver environment
function start_conda_session {
CONDA_PREFIX=$(find $HOME -maxdepth 1 -type d | grep -E "\w{3,4}conda")
source $CONDA_PREFIX/etc/profile.d/conda.sh
ENVS=$(conda env list | awk '{print $1}' )
# if [[ $ENVS = *"tesla-ver"* ]]; then
# echo "Activating tesla-ver environment"
# conda activate tesla-ver
# else
# echo "Creating and activating tesla-ver environment"
# conda env create --file environment_run.yaml && conda activate tesla-ver
# fi
echo "Activating tesla-ver environment"
conda env create --file environment_run.yaml
conda activate tesla-ver
}
# Checks if conda installation is found -- if not, it offers to install it via batch silent install
if [[ ! conda_loc="$(type -p "conda")" ]] || [[ ! -f $(find $HOME -maxdepth 1 -type d | grep -E "\w{3,4}conda")/etc/profile.d/conda.sh ]];
then
echo "Conda installation not found"
echo "By installing, you agree to the conda license at https://docs.conda.io/en/latest/license.html"
read -r -p "Install Conda? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]
then
read -p "Mac or Linux (M/L)? " choice
case "$choice" in
m|M|mac|macOSX|Mac|MacOSX ) os_name="MacOSX";;
l|L|linux|Linux ) os_name="Linux";;
* ) echo "invalid selection" && exit 1;;
esac
curl -o miniconda.sh https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh && bash miniconda.sh -b -p $HOME/miniconda && rm miniconda.sh
start_conda_session
else
exit 1
fi
# If conda installation is found, start conda session
else
start_conda_session
fi
# Runs tesla-ver with gunicorn and 2 workers.
gunicorn --workers=1 --bind=localhost:5000 --chdir ./src/ --log-level=debug wsgi:server