Convert all dqsegdb server installations from Python 2 to Python 3
The dqsegdb server code is normally installed as part of the run of the installation script, by copying the server/src/
dir from the cloned repo to /opt/dqsegdb/python_server/
. This code was modified in the repo, to improve Python 3 (P3) compatibility, but it was not deployed or tested.
The dqsegdb server repo currently has code that should work in Python 3 on Scientific Linux 7 (SL7) systems, with some additional steps. It might or might not work in Rocky Linux 8 (RL8) with those same or other steps.
Worth noting: this update is regarding P2/P3. At the same time (and related), we are upgrading the code to handle SciTokens. The summary:
- The P2 code ignores SciTokens.
- The P3 code, as installed from the recipe below but without some a small number of other changes, will probably check for SciTokens, and if a SciToken is found, queries will fail.
- Updates to accept SciTokens can only be made to the P3 code, as described here: !1 (comment 649552). After that, queries using SciTokens should work.
Steps to deploy the P3 code to an SL7 system that already has a dqsegdb installation on it:
- clone the DQSegDB server code to the machine, with the new dir
/opt/dqsegdb/python_server/dqsegdb_server/
being the preferred location [update: preferred is now:/root/git_dqsegdb_server/
; substitute that dir for/opt/dqsegdb/python_server/dqsegdb_server/
everywhere below]mkdir -p /opt/dqsegdb/python_server/dqsegdb_server/; cd /opt/dqsegdb/python_server/dqsegdb_server/
git clone https://git.ligo.org/computing/dqsegdb/server.git
- set up the machine to use the code from the cloned repo (and new log files, to make a clean break)
mv /opt/dqsegdb/python_server/src /opt/dqsegdb/python_server/src_old
mv /opt/dqsegdb/python_server/logs /opt/dqsegdb/python_server/logs_old
mkdir /opt/dqsegdb/python_server/logs; chmod 777 /opt/dqsegdb/python_server/logs
ln -s /opt/dqsegdb/python_server/dqsegdb_server/server/src /opt/dqsegdb/python_server/src
- create a virtual environment to run
pyodbc
(see #10 (closed))python3 -m venv /root/p3_for_scitokens
-
source /root/p3_for_scitokens/bin/activate
python3 -m pip install --upgrade pip
python3 -m pip install pyodbc
- check the version by activating the venv (
source /root/p3_for_scitokens/bin/activate
), then runningpython3 -c "import pyodbc; print(pyodbc.version)"
; should return4.0.35
or higher; deactivate the venv (deactivate
) - Python 3.6 packages will be in
/root/p3_for_scitokens/lib/python3.6/site-packages/
(though the venv will not be activated to use those packages)
- install P3 version of mod_wsgi and remove the P2 version (notes here: #9 (closed))
yum install python3-mod_wsgi
yum remove mod_wsgi
- this should leave
mod_wsgi_python3.so
as the only WSGI module in/etc/httpd/modules/
and leave10-wsgi-python3.conf
as the only WSGI configuration file in/etc/httpd/conf.modules.d/
- modify WSGI configuration file (notes here: #9 (closed))
-
cp -p /etc/httpd/conf.d/wsgi.conf /etc/httpd/conf.d/wsgi.conf_$(date +%Y.%m.%d-%H.%M.%S).bak
(or change to match your filename preference) - in
/etc/httpd/conf.d/wsgi.conf
- comment out the
LoadModule
line - add the line
WSGIPythonPath /root/p3_for_scitokens/lib/python3.6/site-packages/
(should match the P3 packages dir in the venv, above) - add the line
LoadModule wsgi_module modules/mod_wsgi_python3.so
(should match the file in/etc/httpd/modules/
, above)
- comment out the
- note that the config file should already have lines like these (so 4 active directives, total):
-
WSGIPassAuthorization On
(maybe - not present in that file on segments-dev, and seemingly not anywhere else; might have been added on segments-dev2 for SciTokens support) WSGIScriptAlias / /opt/dqsegdb/python_server/src/application.py
-
- note: we might be loading
mod_wsgi
twice - once in wsgi.conf and again in10-wsgi-python3.conf
(and same for the P2 setup); if so, this might produce messages containingmodule wsgi_module is already loaded, skipping
in the Apache logs [discussed here]
-
- restart Apache and check that everything is OK
-
systemctl restart httpd; systemctl status httpd
- you should see
Active: active (running) since [whenever you restarted httpd]
- you should see
-
- test the server
- Note: we've had some strange results that look like some version of the code is cached, so changes to the code don't immediately affect output, and can even show some reversions in the output for a little while. We don't know why this is or how to get around it other than re-running test commands numerous times. Restarting Apache doesn't seem to clear the cached code (or whatever it is).
- manual commands (adjust for actual segments* machine)
ligolw_segment_query_dqsegdb --ping --segment-url http://segments.ldas.cit
ligolw_segment_query_dqsegdb --ping --segment-url https://segments.ligo.org
ligolw_segment_query_dqsegdb --segment-url https://segments.ligo.org --query-segments --include-segments H1:DMT-ANALYSIS_READY:1 --gps-start-time 1200000000 --gps-end-time 1234500000 | tail
- other examples here: https://wiki.ligo.org/Computing/DQSEGDBDocumentationAndExamples
- run the test suite
For RL8, the installation script should do everything (maybe).
machine | OS | server code |
---|---|---|
segments.ligo.org | SL7 | P3 |
segments-backup | SL7 | P3 |
segments-dev | SL7 | P3 |
segments-dev2 | SL7 | P3 |
segments-temp | SL7 | P3 |
segments-RL8 | RL8 | P3 |
segments-web | SL7 | none (not used) |
Some reference notes and links: