-
Notifications
You must be signed in to change notification settings - Fork 17
/
bootstrap.sh
executable file
·258 lines (211 loc) · 8.43 KB
/
bootstrap.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
#!/bin/bash
# This script is for configuring a ChemmineTools web server
# It is known to work on Debian 10.2 (Buster)
# In its current form, this script should be run as root on a fresh, minimal,
# updated install of Debian Buster. It is assumed that ChemmineTools has been
# extracted/cloned to /srv/chemminetools, and that this script is running from
# there. It has not been tested with Vagrant yet.
# Echo commands, and exit on error
set -xe
# Install GPG early
apt update
apt install -y gnupg
# Add CRAN's APT repo to sources
echo 'deb https://cloud.r-project.org/bin/linux/debian buster-cran35/' >> /etc/apt/sources.list
# Add GPG key to APT keyring
apt-key adv --keyserver keys.gnupg.net --recv-key 'E19F5F87128899B192B1A2C2AD5F960A256A04AF'
## See https://cran.r-project.org/bin/linux/debian/ for guidance when this
## inevitably becomes out-of-date.
# Install Debian packages
apt update
## If this is a development installation, these packages may be useful
#apt install -y git man rsync ssh sudo vim wget
## Direct ChemmineTools dependencies
apt install -y apache2 curl libapache2-mod-wsgi-py3 memcached openbabel \
optipng postgresql python3 python3-future python3-memcache python3-pip \
python3-psycopg2 python3-venv rabbitmq-server r-base-core
## Indirect ChemmineTools dependencies (probably to compile pip/R packages)
apt install -y libcurl4-openssl-dev libopenbabel-dev libpq-dev librsvg2-dev \
libssl-dev libxml2-dev libzmq3-dev swig
## We won't need Apache until the very end. Might as well stop it early.
systemctl stop apache2
# Setup Python venv
mkdir -p /srv/venvs
pushd /srv/venvs
python3 -m venv --system-site-packages chemminetools
source chemminetools/bin/activate
popd
## Install Python packages in venv
pip install -r django_req.txt beautifulsoup4 celery html5lib openbabel PyYAML \
requests simplejson
## Manually install gyroid_utils
curl http://cluster.hpcc.ucr.edu/~khoran/gyroid_utils.tgz | tar -xzf- --no-same-owner --no-same-permissions -C /srv/venvs/chemminetools/lib/python3.7/site-packages/
set +x
# Install R packages
for pkg in amap bitops R.oo gridExtra rzmq RPostgreSQL BiocManager shiny; do
echo "Installing R package [$pkg]. Check /tmp/$pkg.log for errors."
echo 'install.packages(c("'$pkg'"), repos="https://cloud.r-project.org")' | R --slave &> /tmp/$pkg.log
done
# Install Bioconductor packages
for pkg in ChemmineOB ChemmineR fmcsR ctc rjson R.utils eiR BatchJobs BiocParallel UniProt.ws; do
echo "Installing Bioconductor package [$pkg]. Check /tmp/$pkg.log for errors."
echo 'BiocManager::install(c("'$pkg'"))' | R --slave &> /tmp/$pkg.log
done
set -x
# Setup PostgreSQL user for ChemmineTools
runuser -u postgres -- createuser -U postgres chemminetools -w -S -R -d
runuser -u postgres -- psql -U postgres -d postgres -c "alter user chemminetools with password 'chemminetools';"
runuser -u postgres -- createdb -E utf8 -O chemminetools chemminetools -T template0 --locale=C.UTF-8
# Setup Celery
install -m 644 celery_config /etc/default/celeryd
install -m 644 celery_tmpfiles.conf /etc/tmpfiles.d/celery.conf
install -m 644 celery.service /etc/systemd/system/celery.service
# Setup RabbitMQ for remote connections
rabbitmqctl add_user remote_worker askfj4l3nbb43
rabbitmqctl set_permissions -p '/' remote_worker ".*" ".*" ".*"
# Setup Apache HTTP Server
install -m 644 apacheconfig /etc/apache2/conf-available/chemminetools.conf
a2enmod wsgi
a2enconf chemminetools
# Create working directory and set permissions
mkdir -p /srv/working
chown www-data:www-data /srv/working
ln -s /srv/working /srv/chemminetools/working
# Copy sample Django settings file and generate a secret key
# Note: you can't use sed's s/// command here because the secret key may
# contain an '&', which will freak sed out...
pushd /srv/chemminetools/chemminetools
SECRET_KEY=$(python -c 'from django.core.management.utils import get_random_secret_key; print(get_random_secret_key())')
sed -e "/^SECRET_KEY/cSECRET_KEY = '${SECRET_KEY}'" settings_sample.py > settings.py
popd
# Initialize ChemmineTools static files and DB schema
pushd /srv/chemminetools
mkdir static_production
python manage.py migrate --noinput
python manage.py collectstatic --noinput
python manage.py check_permissions
popd
# Register all applications in database
pushd /srv/chemminetools/tools/tool_scripts
for tool in *.yaml; do
python loader.py -i $tool
done
popd
# Create temp directories for Celery
systemd-tmpfiles --create
# Start remaining services
systemctl daemon-reload
systemctl enable celery
systemctl start celery
systemctl start apache2
# Present user with installation success message and further instructions.
set +x
cat << EOF
ChemmineTools installation *ALMOST* complete!
Before using ChemmineTools, you'll need to make a few more configuration
changes:
- Review /srv/chemminetools/chemminetools/settings.py to make sure the settings
are appropriate to your installation. Minimally, change the ALLOWED_HOSTS
list to include your site's domain name(s) and/or IP address. Restart Apache
after making changes (systemctl restart apache2)
- You'll need to prepare two additional databases, one with ChEMBL data, and
another with eiR index data. See the following file for more information:
/srv/chemminetools/chembl_update/README
- Create a Django superuser with:
$ source /srv/venvs/chemminetools/bin/activate
$ cd /srv/chemminetools/
$ python manage.py createsuperuser
- Consider using a firewall to limit access to your server. This will be
specific to your installation (AWS, VirtualBox, iptables, etc.) and is beyond
the scope of this script.
EOF
# Exit now if running as a Bash script
exit 0
################
# Useful notes #
################
# Activate venv before doing anything Django-related
source /srv/venvs/chemminetools/bin/activate
# Create a superuser for Django site
python manage.py createsuperuser
# Start a shell with Django environment loaded
python manage.py shell
# Adding a new app
python manage.py startapp newAppName
## Add newAppName to INSTALLED_APPS set in settings.py
## Add app to urlpatterns list in urls.py with something like:
## url(r'^newAppName/', include('newAppName.urls')),
# Create database migrations (changes to DB schema over time)
python manage.py makemigrations newAppName
# Apply database migrations
python manage.py migrate
###############################
# Older notes - for reference #
###############################
# The following steps are only necessary for creating a real production environment
# create a user for chemmine tools, and su to that user
cd ~
git clone [email protected]/girke-lab/chemminetools.git
# as root move to /srv
mv chemminetools /srv/
# to get joelib working:
# -install java jre1.7.0_17 in /opt/jre
# - install JOELib2-alpha-20070303 in /opt/JOELib2-alpha-20070303
# log into /admin and add users and static content
### OPTIONAL FOR DEV SITE: ###
# launch test page on local port
python manage.py runserver 8020
# launch celery worker on local port
python manage.py celery worker --loglevel=info
#####################
# Django Console #
#####################
# test compound upload from django console
python manage.py shell
from myCompounds import views
from compounddb import tools
sdf = open('/home/tbackman/example_db.sdf', 'r')
sdf = sdf.read()
views.addMyCompounds(sdf, 'tbackman')
# get a users compounds
from compounddb.models import Compound
base_queryset = Compound.objects
base_queryset.filter(username='tbackman')
# list all users
from django.contrib.auth.models import User
base_queryset = User.objects
base_queryset.filter()
# test compound clustering and celery
from tools.runapp import launch
from compounddb import tools
sdf = open('/home/tbackman/example_db.sdf', 'r')
sdf = sdf.read()
result = launch.delay("apcluster.R", "", sdf)
result.ready()
result.get()
result.result
result.successful()
# show results from a job
from tools.models import Job
base_queryset = Job.objects
from tools.runapp import launch
result = launch.AsyncResult(base_queryset.filter()[1].task_id)
result.result
# list all applications
from tools.models import Application
base_queryset = Application.objects
base_queryset.filter()
# make SDF from a users compounds
from compounddb.models import Compound, SDFFile
base_queryset = Compound.objects
compoundList = base_queryset.filter(username='tbackman')
# get sdf:
compound.sdffile_set.all()[0].sdffile
#####################
# Database use #
#####################
psql chemminetools -U chemminetools -h localhost -W
\d # lists tables
\d+ <tablename> # show schema
drop table <tablename> # delete table
\q # quit