-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.sh
executable file
·81 lines (62 loc) · 1.82 KB
/
setup.sh
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
#!/bin/bash
PROJECT_DIR=~/SuMeMainTest
VIRTUALENV_NAME=SuMeMainEnv
echo "Install basic initial packages required............."
sudo apt-get update
sudo apt-get install vim python3 python3-dev nginx postgresql postgresql-contrib libpq-dev
echo "Setup Flask in a virtual env....................."
mkdir $PROJECT_DIR
cd $PROJECT_DIR
mkdir app
virtualenv $VIRTUALENV_NAME
source $VIRTUALENV_NAME/bin/activate
pip install uwsgi flask psycopg2
deactivate
echo "Configure uwsgi...................."
cat << 'EOF' > $PROJECT_DIR/app/uwsgi.ini
[uwsgi]
module = wsgi
master = true
processes = 5
socket = /tmp/sume_internal.sock
chmod-socket = 660
uid = www-data
gid = www-data
vacuum = true
die-on-term = true
EOF
echo "Setup nginx to proxy requests........."
sudo touch /etc/nginx/sites-available/SuMeNginx.conf
sudo tee /etc/nginx/sites-available/SuMeNginx.conf << 'EOF'
server {
listen 80 default_server;
listen [::]:80 default_server;
location / {
include uwsgi_params;
uwsgi_pass unix:/tmp/sume_internal.sock;
}
}
EOF
sudo rm /etc/nginx/sites-enabled/default
sudo ln -s /etc/nginx/sites-available/SuMeNginx.conf /etc/nginx/sites-enabled
sudo service nginx restart
cd $PROJECT_DIR/app
cat << 'EOF' > wsgi.py
from sume_main import application
if __name__ == "__main__":
application.run(host='0.0.0.0')
EOF
cat << 'EOF' > sume_main.py
from flask import Flask
application = Flask(__name__)
@application.route('/')
def hello():
return "Hello, World!"
if __name__ == "__main__":
application.run(host='0.0.0.0')
EOF
touch __init__.py
echo "Bring up the SuMe application......"
sudo ../$VIRTUALENV_NAME/bin/uwsgi -i uwsgi.ini &
echo "===================================================="
echo "If by chance everything went fine, you will see Hello world message when you connect to current IP via a decent browser."