forked from pjvandehaar/pathweb
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-server.sh
More file actions
executable file
·85 lines (75 loc) · 3.07 KB
/
setup-server.sh
File metadata and controls
executable file
·85 lines (75 loc) · 3.07 KB
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
#!/bin/bash
# This script attempts to do all the work to host the site. It expects to be on Ubuntu 18.04+ but likely also works on 16.04.
set -euo pipefail # exit if an error occurs rather than ignoring it
# Move to the directory containing this script (to allow relative paths)
_readlinkf() { perl -MCwd -le 'print Cwd::abs_path shift' "$1"; } # cross-platform version of `readlink -f`
cd "$(dirname "$(_readlinkf "${BASH_SOURCE[0]}")")" # `cd` to the directory holding this script (which is the root of this git repo)
# Check that needed data is present. If a missing file can be generated from other files, do that.
if ! [ -e pathweb/pheno_pathway_assoc.db ]; then
if [ -e input_data/pathways ]; then
python3 pathweb/make_sqlite3_db.py
else
echo "either populate input_data/pathways/ and run ./make_sqlite_db.py or copy pheno_pathway_assoc.db here"
exit 1
fi
fi
if ! [ -e pathweb/gene.db ]; then
if [ -e input_data/genes ]; then
python3 pathweb/make_gene_sqlite3_db.py
else
echo "either populate input_data/genes/ and run ./make_gene_sqlite_db.py or copy gene.db here"
exit 1
fi
fi
if ! [ -e pathweb/static/phenotypes.json ] || ! [ -e pathweb/static/pathways.json ]; then
python3 pathweb/make_tables.py
fi
# Install dependencies
if ! [ -e venv ]; then
sudo apt update && sudo apt install python3-pip python3-venv nginx
python3 -m venv venv
./venv/bin/pip3 install -r requirements.txt
fi
# Make a Systemd Unit file that runs gunicorn to host the site (available only locally on this machine)
if ! [ -e /etc/systemd/system/gunicorn-pathweb.service ]; then
sudo tee /etc/systemd/system/gunicorn-pathweb.service >/dev/null <<END
# Sample commands to use:
# sudo systemctl daemon-reload # makes systemd notice changes to this file
# sudo systemctl enable gunicorn-pathweb.service # run once (re-running is fine) so that systemd knows to run this when the system starts
# sudo systemctl start gunicorn-pathweb.service
# sudo systemctl restart gunicorn-pathweb.service
# sudo systemctl status -n30 gunicorn-pathweb.service
[Unit]
Description=Gunicorn instance to serve pathweb
After=network.target
[Service]
User=nobody
Group=nogroup
WorkingDirectory=$PWD/pathweb/
ExecStart=$PWD/venv/bin/gunicorn -k gevent -w4 --bind localhost:8899 serve:app
[Install]
WantedBy=multi-user.target
END
sudo systemctl daemon-reload
sudo systemctl enable gunicorn-pathweb
sudo systemctl start gunicorn-pathweb
fi
# Make nginx reverse-proxy the local-only gunicorn port to an externally-accessible subdomain
if ! [ -e /etc/nginx/sites-enabled/pathweb ]; then
sudo tee /etc/nginx/sites-available/pathweb >/dev/null <<END
server {
listen 80;
server_name ukb-pathway.leelabsg.org;
location / {
include proxy_params;
proxy_pass http://localhost:8899;
}
}
END
sudo ln -s /etc/nginx/sites-available/pathweb /etc/nginx/sites-enabled/
sudo nginx -t # check that the file is good
sudo systemctl restart nginx
fi
# Restart gunicorn to apply any changes
sudo systemctl restart gunicorn-pathweb
echo SUCCESS