Installing OPUS on a Server
This chapter describes bringing a complete OPUS server up from nothing.
Almost none of it is done by hand. The distribution ships the scripts that install
OPUS, import the holdings and deploy the result, and opus_deploy_scripts writes them
onto the server. What you do by hand is create one virtual environment, write them out,
and fill in one file of settings; the scripts do the rest, and they are the same scripts
that upgrade the server afterwards.
There is nothing to clone and nothing to build. Every installation the scripts create is
a virtual environment with the released rms-opus distribution in it, from PyPI.
For a development checkout rather than a server, read Environment Setup instead; it is shorter, and it installs from source.
How a server is put together
/opt/opus throughout this guide is the location it recommends, not one OPUS
requires: nothing in OPUS or in the scripts has a built-in path. The installation root
is whatever OPUS_DIR in deploy.env says, the deploy directory is wherever you
write the scripts out, and either can be anywhere the OPUS account can read and write –
/srv/opus, /var/lib/opus, a mounted volume. Substitute your own throughout, or
keep these if you have no reason to prefer another.
Two directories, and neither is inside the other’s business.
The deploy directory holds the scripts and the settings they read. It is written by
opus_deploy_scripts, it is not an OPUS installation, and nothing a deploy does
replaces it:
/opt/opus/deploy/
README.txt the short version of this chapter
CHAIN_VERSION the release these scripts came from
deploy.env.template the settings file to copy
secrets/deploy.env ... and your filled-in copy, mode 0600
import_and_deploy/*.sh the import and the two deploys
database/*.sh copying a database to a second server
log_analyzer/*_template cron templates for the log reports
The installation root holds what the scripts build. Every deploy creates a complete new installation and switches to it; nothing is ever upgraded in place:
/opt/opus/staged/<database>_<timestamp>/
opus_venv/ a virtualenv with the released rms-opus in it
opus.toml this installation's configuration, mode 0600
wsgi.py symlink to the wsgi module inside opus_venv
/opt/opus/deployed -> staged/<database>_<timestamp> what the web server serves
/opt/opus/import -> staged/<database>_<timestamp> what an import is using
/opt/opus/opus_logs/ the web application's log
/opt/opus/import_logs/ one directory per import run
/opt/opus/downloads/ zipped cart files, and
/opt/opus/manifests/ their manifests
/opt/opus/static_media/ where collectstatic gathers the static files
That shape follows from one fact about OPUS: a release that changes the table schemas
cannot read a database an earlier release imported. Every OPUS table is created by the
import pipeline from the JSON schemas that ship with a release, so the code and the
database it built have to move together. A deploy that upgraded the running installation
would serve one release’s code against another release’s database for as long as it took
to finish; instead, the new installation is built beside the running one, and the switch
is a single rename of the deployed symlink.
It also means the previous installation is still on disk after a deploy, so going back is another switch rather than a rebuild. Deployment and Operations is the full account.
Prerequisites
All of these are the machine’s, installed before OPUS is. The only Python packages you install by hand are in the next section, into a virtual environment created there; every other Python package a server needs is installed by the scripts, into the installations they build.
Python 3.12 or later. Each installation’s virtual environment is built with
python3.12 unless deploy.env names another one in OPUS_PYTHON.
MySQL 8.0.19 or later, with a user allowed to create and drop databases and tables.
The import pipeline creates every OPUS table itself – and creates the schema, if it does
not exist – and it writes its multi-row upserts with the AS new row alias that
8.0.19 added. See opus_import.importdb for why that is the floor.
The server an import writes to does its work faster with a few settings, none of which the import needs in order to run, and the server that answers searches needs its buffer pool sized from the imported database. Configuring the Database Server gives both, with what each setting does for OPUS.
The MySQL client development headers, because the mysqlclient driver ships no
Linux wheel and is compiled during every install. On Debian or Ubuntu:
sudo apt-get install pkg-config default-libmysqlclient-dev build-essential
A Unix account for OPUS, which the web server’s workers run as and which every deploy
script has to be run as. Everything a deploy creates belongs to whoever ran it, including
an opus.toml at mode 0600, so a deploy run as anyone else – root, most easily –
builds an installation the web server cannot read. The scripts refuse rather than letting
that reach the switch. That account also needs sudo for three systemctl commands:
the switch stops the web server, restarts the cache, and starts the web server again.
This is an example of making one, on a system with useradd, and of checking the
result – useradd says nothing at all when it succeeds:
sudo useradd --system --create-home --shell /bin/bash opus
id opus
opus is the name this guide uses, and OPUS_USER in deploy.env is what says
which account you actually chose. It needs a shell, because the deploys are run as
it, and a home directory, because pip writes a cache into one. An account that
already exists is fine: useradd will say so and change nothing.
A web server. Fronting OPUS with a Web Server has worked configurations for Apache with
mod_wsgi and for nginx in front of gunicorn or uWSGI. Under Apache, the deploy runs
pip install mod-wsgi inside each installation it builds, which compiles against
Apache’s own headers:
sudo apt-get install apache2 apache2-dev
memcached, strongly recommended. It is the cache several worker processes answer
from, and emptying it is how a deploy stops the new database being described by results
computed against the old one. Install the daemon here; the scripts install its
pymemcache client into every installation they build:
sudo apt-get install memcached libmemcached-tools
Without memcached running, OPUS falls back to Django’s per-process local-memory cache: it works, more slowly, and the cache-emptying step of a deploy has nothing shared to empty. Running the Web Application describes the fallback.
OPUS reaches memcached at 127.0.0.1:11211, the port the distribution’s package
listens on, unless OPUS_CACHE_LOCATION in deploy.env names another. A memcached
started with -s listens on that Unix socket alone, with no TCP port at all, so a
server set up that way names the socket there, as unix: and its path. systemctl
status memcached shows the command line memcached was started with.
Nothing else is needed to install it. Later, once the site is serving, this is how to watch the cache being used – the counters once a second, with what changed highlighted, which is how you see requests being answered from it and a deploy emptying it:
watch -n1 -d 'memcstat --servers 127.0.0.1'
For a memcached on a socket, --servers takes the socket’s path instead.
memcstat comes from libmemcached-tools rather than from memcached, which is
why the install line above takes both packages.
wkhtmltopdf, only for the help pages’ PDF downloads. Every other page works without it, and nothing else in OPUS uses it. It has to be a build with patched Qt: the pages are rendered with a page-number footer, which is one of the features a build against the system Qt does not have, so a distribution package fails on the request rather than producing a plainer PDF. That is what a machine has to say for itself:
$ wkhtmltopdf --version
wkhtmltopdf 0.12.4 (with patched qt)
Install it from the project’s own release rather than from the distribution, whose package is the unpatched build. These are the binaries the Ring-Moon Systems Node runs, for Linux on x86-64:
cd /tmp
wget https://github.com/wkhtmltopdf/wkhtmltopdf/releases/download/0.12.4/wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
tar xvf wkhtmltox-0.12.4_linux-generic-amd64.tar.xz
sudo mv wkhtmltox/bin/wkhtmlto* /usr/bin/
The download and the unpacked wkhtmltox/ are left behind in /tmp, which is where
they can be deleted or ignored; only what was moved to /usr/bin is installed. The
glob takes wkhtmltoimage along with wkhtmltopdf; they ship together, and the one
the help pages call ends up on the path either way. 0.12.4 is the release the Ring-Moon
Systems Node runs; the project is archived, so that releases page is a fixed list
rather than a moving one, and a later release from it does as well, as long as
--version says patched.
The PDS holdings, mounted read-only. The import needs them to run at all; the web
application needs them to serve product files. Both a PDS3 and a PDS4 root are
configured, and the scripts check that volumes/ exists under the first and
bundles/ under the second before doing anything.
Each root has to be a directory of a particular name: holdings for PDS3 and
pds4-holdings for PDS4. pdsfile, which reads the holdings for the import, finds a
file’s place in them by that name, and the scripts refuse a root named otherwise. It does
not resolve symbolic links, so a root mounted under another name is given a link of the
right name:
sudo ln -s /volumes/pdsdata-production/pds3-holdings /opt/opus/holdings
A mail transport, only if you want the import to mail its log when it finishes. An
import runs detached, so that mail is how anyone finds out it ended.
Without one, leave OPUS_IMPORT_MAIL_TO empty and read the log where it was written.
Step 1: the environment the scripts come from
The deploy scripts are part of rms-opus, so installing them means installing the
distribution once, by hand, into an environment of its own:
# The installation root has to exist and belong to the OPUS account. Everything
# underneath it, the scripts create.
sudo install -d -o opus -g opus -m 755 /opt/opus
# From here on, everything is run as that account.
sudo -u opus -i
python3.12 -m venv /opt/opus/deploy_venv
source /opt/opus/deploy_venv/bin/activate
python -m pip install --upgrade pip
python -m pip install "rms-opus==<release>"
opus there is the account from the prerequisites, and <release> the release you
are deploying.
To install a revision with no release – a branch under review, a tag or a commit –
name it in place of the release. Here pip is run by hand, so it takes pip’s full direct
reference to the repository; for a branch named my-branch:
python -m pip install "rms-opus @ git+https://github.com/SETI/rms-opus.git@my-branch"
pip builds it from a clone, so the server needs git and access to GitHub. Every script
below takes the short form, @ and the same name – @my-branch – wherever it shows
==<release>, and builds that direct reference from it
(Deploying a revision with no release):
./import_and_deploy/run_full_opus_import.sh @my-branch
This environment does not serve anything. It exists so that the scripts have commands
to run; the installations that serve and import are built by the scripts under
staged/. Its path is what OPUS_DEPLOY_VENV names in deploy.env below, and
every script activates it for itself – so a deploy runs the same way from a shell, from
cron and under nohup, and this is the only time it is activated by hand.
Installing the distribution puts these commands on the path. The deploy scripts run most of them for you; they are listed because the scripts’ output names them, and because a partial import or a one-off report is run directly:
Command |
What it does |
|---|---|
|
Writes out the deploy chain. The next step. |
|
The import pipeline: reads the PDS holdings and builds the OPUS database. |
|
Runs a whole full-holdings import: registers every bundle set, in order, imports
them with one or more importers it starts, tracks and restarts, and runs the
steps that finish the database. Its steps also run one at a time, so that another
computer can join an import; it erases a database only with |
|
Administers the web application – creating its tables, gathering its static files, checking that its configuration works, and pruning its stored searches (Pruning stored searches). A deploy runs it too. |
|
Writes out the annotated template of the file OPUS itself reads. On a server the deploy generates that file, so this is for reading rather than for filling in; see The configuration file OPUS reads. |
|
Turns the web server’s access logs into reports on how the site is being used. |
|
The same for the error log. |
Every one of them, except opus_config_template and opus_deploy_scripts, reads the
configuration file named by OPUS_CONFIG. The scripts export it; running one of these
commands yourself means naming the installation whose configuration you mean.
Step 2: writing out the deploy scripts
opus_deploy_scripts --directory /opt/opus/deploy
That writes the scripts, a deploy.env.template to copy in the next step, a
CHAIN_VERSION file recording the release they came from, and a plain-text
README.txt holding the short version of this chapter – so the instructions are
beside the scripts on the server, readable with less, rather than only here.
Write them outside every installation, and run them from there. A deploy installs a
new rms-opus, and these scripts are part of rms-opus: a copy living inside an
installation being replaced would be rewritten while bash was still reading it. The
filled-in settings go beside them for the same reason – credentials do not belong in a
directory a deploy replaces.
Being part of the distribution, the chain changes with it. Upgrading a server therefore starts by bringing this directory up to the release being deployed, with one of the scripts it contains – the first command of every upgrade.
Step 3: deploy.env, the one file you fill in
Everything about this server is in one file: where to install, which account to run as, which database to connect to and as whom, where the holdings are, what the site calls itself, and what to do with a finished database. Nothing in the scripts assumes a value for any of it – no host name, no URL, no path – so the same chain runs on any server that fills this in.
cd /opt/opus/deploy
install -d -m 700 secrets
install -m 600 deploy.env.template secrets/deploy.env
# ... then fill in every <PLACEHOLDER>.
Both modes are set as the thing is created rather than afterwards, and install
rather than mkdir and cp is what does that: mkdir applies the caller’s umask,
so under a permissive one the directory is created world-writable. The scripts read this
file with source, i.e. they run it as shell code with the deploy account’s
privileges, so another local account able to write it is another local account running
your deploys. It holds a database password and Django’s secret key, and secrets/ is
git-ignored.
It is shell syntax: VAR=value, no spaces around the =, and quote any value
containing a space.
Variable |
Meaning |
|---|---|
|
The installation root: any directory the OPUS account owns, |
|
The environment from step 1, which the scripts’ own commands come from. Every
script activates it for itself. It is not one of the installations under
|
|
The Unix account OPUS runs as, and the account every script has to be run as.
Everything a deploy creates belongs to whoever ran it, including an |
|
The MySQL server this installation connects to, usually |
|
The MySQL account the import pipeline and the web application connect as. It
needs most privileges, including creating and dropping tables and views
( |
|
Django’s signing key: unique to this server, and secret. |
|
The two holdings roots, which have to end in directories named |
|
The two files of site content the interface displays. Neither has to exist – an absent one means there is nothing to show. |
|
Django’s |
|
Every name and address this installation answers to, separated by spaces. Django
refuses a request whose |
|
The prefix on this installation’s keys in the shared cache. Two installations sharing one memcached need different prefixes, or each reads the other’s answers. |
|
Optional. Where the application reaches memcached, written into |
|
Optional. The import’s parallelism, written into |
|
What the site calls itself and where it serves things from. They appear in what the API returns, so they are the URLs a user’s browser has to be able to reach rather than any internal address. The last one is joined directly to a file name and needs a trailing slash. |
|
Optional. Where |
|
Has a default. The Python each installation’s virtualenv is built with,
|
|
Has a default. The systemd unit running the application’s workers, stopped for
the switch at the end of a deploy and started again after it. |
|
Has a default. The systemd unit holding the shared cache, restarted after the
switch to empty it. |
|
Optional. The MySQL server a finished database is copied to. With a host here,
an import ends by dumping what it built and loading it there, and an incremental
update is copied too: it ends by dumping the updated database and loading it there
under a new name. Empty, the dump stays where it was written. It needs
|
|
Optional. Where to mail the log when an import finishes. Empty sends nothing and leaves the log where it was written. |
Two checks run before a deploy touches anything, and both name the variable at fault:
_read_deploy_env.sh refuses a required variable that is missing, empty, or still
the <PLACEHOLDER> the template ships – emptiness as well as absence, because nothing
downstream objects to an empty value, and Django starts perfectly well with no secret key
– and it refuses to run as any account but OPUS_USER.
Step 4: the first import
cd /opt/opus/deploy
./import_and_deploy/run_full_opus_import.sh ==<release>
That one command builds an installation of that release under staged/, points the
import symlink at it, and imports the whole archive into a database of its own named
for the moment it started. It runs detached, and prints the log file it is writing
to; with OPUS_IMPORT_MAIL_TO filled in, it mails that log when it ends.
A full-holdings import measured 3,032 seconds, about 51 minutes, with six importers
sharing 24 workers at a cpu_fraction of 0.8, on the Ring-Moon Systems Node’s
development workstation. It takes longer with fewer, so set the parallelism in
deploy.env before this step (below). What it runs is opus_import_all, the
installed command. It registers every bundle set in order – Galileo and New Horizons
first, then the rest roughly from the quickest to the slowest – which fixes each
bundle’s number and the ids its observations take. It then starts importers, each
importing the registered bundles, the largest first, until none is left; it tracks
them, and returns the bundle of an importer that dies to the queue and starts another.
Last it runs the four steps that finish the database, the auxiliary tables, the
dictionary, the validation and the schema version row the web application checks for
(The schema version check), unless a bundle failed. The order lives in
the release being installed rather than in the scripts, so it cannot disagree with the
code importing.
How much of the computer it uses is [import] workers, the total of worker processes,
divided among [import] importers importers, which the generated opus.toml takes
from OPUS_IMPORT_WORKERS and OPUS_IMPORT_IMPORTERS in deploy.env. workers
defaults to 1 and the importers are capped at it, so with neither set the import uses
one process (Sharing a full import between processes or computers).
The database is new, so nothing is erased. opus_import_all erases the OPUS tables of
the database it is pointed at only when given --scorched-earth, and asks first;
without it, running it again after an interruption imports only the bundles that are not
done. opus_import_all --dry-run prints what the given arguments would run without
running it. A full-holdings run describes each step and is the reference
for every opus_import_all option, and opus_import_all --help lists them. An
option opus_import_all does not define is passed on to the opus_import
invocations that import – the erase, the registration and every importer – and not to
the ones that finish the database or return bundles to the queue. Those read the
holdings too, at the roots the configuration names, so a holdings option given to the
importers does not reach them.
The argument is a PEP 440 version specifier appended to the distribution name:
==<release> for a particular release, omitted for the newest. @ and a git branch,
tag or commit installs that revision instead (Deploying a revision with no release). Give this step and
step 5 the same one – they install rms-opus separately, so leaving it off both
means “the newest release” twice, which is two different releases if one is published
in between.
Read the log rather than the exit status. Several import steps report a failure
through the log and still exit zero, so a clean run is an empty ERRORS.log:
ls /opt/opus/import_logs/ # one directory per run, newest last
cat /opt/opus/import_logs/<run>/ERRORS.log
cat /opt/opus/import_logs/<run>/WARNINGS.log
Verifying that a run succeeded is the longer account of what to look for. The database
the run built is named by the installation import now points at:
basename "$(readlink /opt/opus/import)"
These scripts import the whole archive: what they run is opus_import_all, which
imports every bundle set. A site that wants
only part of it – Cassini and nothing else – runs the pipeline directly instead, and
then deploys the database that produced:
# A configuration of your own, naming a database of your own. This is the one
# case where opus.toml is written by hand on a server; the deploy generates the
# one the site actually serves from.
opus_config_template
install -m 600 opus.toml.template /opt/opus/partial.toml
# ... fill it in: schema = "<database>", a name of your own, and the same paths
# deploy.env names.
# Each command runs only if the one before it succeeded, so a failed step stops
# here rather than leaving a database marked ready and deployed. The last line is
# step 5 as usual, naming that database.
OPUS_CONFIG=/opt/opus/partial.toml opus_import --do-it-all CASSINI &&
OPUS_CONFIG=/opt/opus/partial.toml opus_import --import-dictionary &&
OPUS_CONFIG=/opt/opus/partial.toml opus_import --validate &&
OPUS_CONFIG=/opt/opus/partial.toml opus_import --write-schema-version &&
./import_and_deploy/deploy_new_code_and_database.sh <database> ==<release>
What --do-it-all takes is a descriptor, and several can be given, comma- or
space-separated: a bundle id (COISS_2002), a whole bundleset (COISS_2xxx), one of
the shorthands for a mission or an instrument (CASSINI, GALILEO, HST,
VOYAGER, NH, COISS, COUVIS and their relatives, matched without regard to
case), or ALL. --do-it-all imports them and then runs --finalize, which
adds the database’s indexes, keeps one copy of each observation two bundles share,
deletes the checkbox values no observation holds, and builds the tables that describe the
search form. The three steps after it finish the
database, the last of them what lets the web application serve it, and a direct
invocation is the one path that does not run them for you. opus_import --help lists
every option and works without a configuration file; Running the Import Pipeline is
the complete reference.
Step 5: the first deploy
./import_and_deploy/deploy_new_code_and_database.sh <database> ==<release>
The argument is the database from step 4. This builds the installation that will serve –
its own virtualenv, its own rms-opus, a generated opus.toml naming that database,
and the wsgi.py symlink – creates the web application’s own tables, gathers the
static files, rebuilds the dictionary and the auxiliary tables, and only then switches:
the deployed symlink is moved onto it with a single rename, the cache is emptied, and
the workers are started again. The workers are stopped for that switch alone, not for
the build, so the site goes on serving what it was serving until the moment it changes.
It asks for your sudo password at the start rather than at the end, so that a build
does not sit waiting on a prompt nobody is watching.
Step 6: the web server
Point a web server at /opt/opus/deployed/wsgi.py, once. Every later deploy moves that
symlink rather than the web server’s configuration, so this is the one step that is never
repeated. Fronting OPUS with a Web Server has the worked Apache and nginx configurations,
and the three things any of them has to arrange.
Checking the installation
Four checks, in increasing order of what they prove:
# 1. The deploy switched. This is what the web server is serving.
readlink /opt/opus/deployed
# 2. The configuration that installation generated is valid, and the database it
# names can be opened. --database default is what opens the connection.
OPUS_CONFIG=/opt/opus/deployed/opus.toml \
/opt/opus/deployed/opus_venv/bin/opus_manage check --database default
# 3. The application starts under a WSGI server. gunicorn is not an OPUS
# dependency -- install it into that installation for this check, or use
# whichever server you deploy. Do not test this one in a web browser: it
# serves no static files, so the interface will not work.
/opt/opus/deployed/opus_venv/bin/python -m pip install gunicorn
OPUS_CONFIG=/opt/opus/deployed/opus.toml \
/opt/opus/deployed/opus_venv/bin/gunicorn --bind 127.0.0.1:8001 \
opus_app.wsgi:application
# 4. It answers, with data. 127.0.0.1 has to be in OPUS_ALLOWED_HOSTS, or Django
# replies 400 however well the application and the database are working.
curl -s 'http://127.0.0.1:8001/api/meta/result_count.json?planet=Saturn'
The same four checks run against a staged installation that is not deployed yet –
substitute staged/<that installation> for deployed – which is how a new database
is exercised before the public site is switched to it. See
The import runbook.
If the third fails on an import error rather than a configuration one, the usual cause is
that OPUS_CONFIG did not reach the process; see Fronting OPUS with a Web Server.
The configuration file OPUS reads
OPUS itself reads one TOML file, named by the OPUS_CONFIG environment variable, and
there is no default location for it: a machine hosting several installations gives
each one its own file, and a process that guessed would quietly serve or overwrite a
neighbour’s database.
On a server the deploy writes that file, one per installation, from the deploy.env
values above, at mode 0600 inside the installation it belongs to. So this section is here
to be read rather than filled in: do not hand-edit ``opus.toml`` on a deployed server,
because the next deploy generates it again. Change deploy.env and run a deploy.
The four tables below are what a generated file contains, and what OPUS validates as it reads it: an unknown key, a missing key, or a value of the wrong type is reported with the table and the key at fault rather than failing later somewhere else. A misspelled key is an error, not something silently ignored. A key marked optional may be left out entirely.
[database]
Key |
Required |
Meaning |
|---|---|---|
|
optional |
|
|
yes |
The host the OPUS schema lives on. From |
|
optional |
MySQL ignores this and connects to |
|
yes |
The namespace the OPUS tables live in – the database name under MySQL. It is also part of every cache key. This is the key that says which database an installation serves, and it is what a code-only deploy reads out of the installation it is replacing. |
|
yes |
The database account, from |
[paths]
Key |
Required |
Meaning |
|---|---|---|
|
yes |
The roots of the two holdings trees. |
|
yes |
The file the web application logs to. Its directory must already exist: the
application opens the file during startup, so a missing directory stops it rather
than degrading it. The deploy creates |
|
yes |
Where the import pipeline writes |
|
yes |
Where zipped cart files and their manifests are built. Both are joined directly to a file name, so both need a trailing slash. |
|
yes |
Two files of site content maintained outside the repository. Neither has to exist – an absent one simply means there is nothing to show. |
|
optional |
Where |
|
yes |
Where the help pages’ PDF renderer reads assets from. On a server this is the
same directory as |
[django]
Key |
Required |
Meaning |
|---|---|---|
|
yes |
Django’s signing key. It must be unique to this installation and secret. |
|
yes |
Never true on anything reachable from outside the machine. |
|
yes |
The hosts and addresses Django will serve, as an array. The generator builds it
from the space-separated |
|
yes |
Prepended to every cache key, which is what lets several OPUS installations share one memcached without colliding. |
|
optional |
The memcached the web application caches in, as |
|
optional |
How many seconds each web worker thread keeps its database connection open across
requests. Default |
|
optional |
Whether a kept database connection is checked before a request reuses it, and
replaced if the server has dropped it. Default |
|
optional |
How many seconds a request waits while another web worker stores the results of
the same search, before it gives up and answers with a 500. Default |
|
optional |
The rows |
|
yes |
This installation’s public URL, used by the citation page. |
|
yes |
The root URL data products are retrieved from. |
|
yes |
The root URL of the Ring-Moon Systems Node’s file browser, which the Details tab links into. |
|
yes |
The root URL zipped cart files are retrieved from. Joined directly to a file name, so it needs a trailing slash. |
|
optional |
Defaults |
|
optional |
Default |
|
optional |
A level name to log every API call at, or false. Default false. |
|
optional |
Fault injection; see Running the Web Application. A generated file never contains it. |
|
optional |
The same. Defaults 0. |
[import]
Key |
Required |
Meaning |
|---|---|---|
|
yes |
The import pipeline’s own logs. Their directory must already exist. |
|
optional |
Whether observation rows are written with |
|
optional |
Where the bulk load writes its scratch files. Default: the system temporary directory. A large table’s load writes gigabytes, so point it at disk where the system temporary directory is memory-backed. |
|
optional |
The most rows one bulk load writes in one transaction, a whole number of at
least 1. Default |
|
optional |
How many processes compute an index’s observations: a whole number of at least
1, or |
|
optional |
The index rows one worker task covers, a whole number of at least 1. Default
|
|
optional |
How many tables the import’s finalization builds indexes on at once, each over a
connection of its own: a whole number of at least 1, or |
|
optional |
The share of the cores the ceiling allows, greater than 0 and at most 1. Default
|
|
optional |
A directory on the database server’s host, writable by |
|
optional |
How many importers |
|
optional |
How long an importer that is alive may go without committing any rows before
|
|
optional |
How often |
Where to go next
- Configuring the Database Server
The MySQL settings that matter to OPUS, and sizing the server’s memory.
- Fronting OPUS with a Web Server
Putting Apache or nginx in front of it.
- Deployment and Operations
Upgrading the server, replacing the database, and what must always happen after an import.
- Running the Import Pipeline
Every import option.
The whole template
opus_config_template writes this file, and it is what a generated opus.toml is a
filled-in version of. It documents every key, and it is reproduced here – included from
the distribution rather than retyped, so the two cannot drift – so that the file can be
read before anything is installed. A development installation is where you copy and
fill it in by hand; see Environment Setup.
################################################################################
# Settings that are local to one installation of OPUS and must be set separately
# for each installation and server.
#
# Copy this file, fill in every <PLACEHOLDER>, and point the OPUS_CONFIG
# environment variable at the copy:
#
# install -m 600 opus.toml.template opus.toml
# export OPUS_CONFIG=/absolute/path/to/opus.toml
#
# `install -m 600` rather than `cp`: the copy is about to hold a database password
# and the Django secret key, and `cp` gives it whatever the caller's umask allows.
# The copy also has to be readable by the account OPUS runs as, so create it as
# that user rather than as root.
#
# OPUS has no default location for this file. A server running several OPUS
# installations gives each one its own file and its own OPUS_CONFIG value.
#
# The schema is validated when the file is read: an unknown key, a missing key,
# or a value of the wrong type is reported with the table and key that is wrong.
################################################################################
[database]
# The brand of the back-end SQL database: "MySQL" or "PostgreSQL". Only MySQL is
# implemented. Optional; the default is "MySQL".
brand = "MySQL"
# The host the OPUS and dictionary schemas live on. Usually "localhost".
host = "<HOST_NAME>"
# The database to connect to. MySQL ignores this and connects to `schema`
# instead; PostgreSQL connects to this database. Optional; the default is "".
database = ""
# The namespace the OPUS tables live in: the database name under MySQL, the
# schema name under PostgreSQL.
schema = "<SCHEMA_NAME>"
# The database user and password. This user needs most privileges, including
# table creation and deletion.
user = "<DB_USER>"
password = "<DB_PASSWORD>"
[paths]
# The root directory of all PDS3 holdings. Under it are volumes, calibrated,
# metadata, previews, and diagrams.
pds3_holdings = "<PDS3_HOLDINGS_DIR>"
# The root directory of all PDS4 holdings. Under it are bundles, metadata,
# previews, and diagrams.
pds4_holdings = "<PDS4_HOLDINGS_DIR>"
# The file the web application logs to. Its directory must already exist.
opus_log_file = "<OPUS_LOG_DIR>/opus_log.txt"
# The directory the import pipeline writes its warning and error summaries to.
import_log_dir = "<IMPORT_LOG_DIR>"
# Where zipped cart files and their manifests are built. Both are joined
# directly to a file name, so both need a TRAILING SLASH.
tar_dir = "<TAR_FILE_DIR>/"
manifest_dir = "<MANIFEST_FILE_DIR>/"
# The file holding the date of the last blog update, and the file holding the
# HTML of any short-term notification.
last_blog_update_file = "<LAST_BLOG_UPDATE_FILE>"
notification_file = "<NOTIFICATION_FILE>"
# Where `manage.py collectstatic` gathers static files on a production server.
# Optional, and commented out because a development installation never runs
# collectstatic and wants Django's own default. Uncomment it on a server.
# static_root = "<STATIC_ROOT>"
# Where static files are served from. On a production server this is the same
# directory as static_root; in a development installation it is usually
# .../rms-opus/src/opus_app/static.
opus_static_root = "<OPUS_STATIC_ROOT>"
[django]
# Django's secret key. It must be a unique, secret string. Generator tools are
# available: https://www.google.com/search?q=django+secret+generator
secret_key = "<SECRET_KEY>"
# Django's DEBUG setting. NEVER deploy a production site with this true.
debug = true
# The hosts and IP addresses Django is permitted to serve.
allowed_hosts = ["127.0.0.1", "localhost"]
# The prefix added to every cache key, which is what lets several OPUS
# installations share one memcached without colliding.
cache_server_prefix = "<CACHE_SERVER_PREFIX>"
# The memcached server the web application caches in, as "host:port", or as "unix:"
# and an absolute path for a memcached listening on a Unix socket, such as
# "unix:/var/run/memcached/memcached.socket". Optional; the default is the value
# below, memcached's own port on this machine.
cache_location = "127.0.0.1:11211"
# How many seconds each web worker thread keeps its database connection open across
# requests; 0 opens and closes one for every request. Optional; the default is the
# value below.
conn_max_age = 300
# Whether a kept database connection is checked before a request reuses it, and
# replaced if the server has dropped it. Optional; the default is the value below.
conn_health_checks = true
# How many seconds a request building a search's results waits for another web worker
# already building the same search before it gives up. Keep it at least 30 seconds
# below the web server's worker timeout (gunicorn's --timeout, uWSGI's harakiri,
# Apache's Timeout): a worker killed partway through a build loses the build, and the
# next request waiting for it starts over. Optional; the default is the value below.
search_build_timeout = 270
# The rows "opus_manage prune" cuts the search_results table down to by default,
# removing the least recently used searches first. Optional; the default is the value
# below.
search_results_max_rows = 50000000
# The public URL of this OPUS installation.
public_url = "https://opus.pds-rings.seti.org/"
# The root URL products are retrieved from, and the root URL of the viewmaster
# file browser.
product_http_path = "https://opus.pds-rings.seti.org/"
viewmaster_url = "https://pds-rings.seti.org/"
# The root URL zipped cart files are retrieved from. It is joined directly to a
# file name, so it needs a TRAILING SLASH.
tar_file_url = "<TAR_FILE_URL>/"
# What level of message to log at each destination. Optional; the defaults are
# the values below.
log_file_level = "INFO"
log_console_level = "INFO"
log_django_level = "WARNING"
# Log every API call at this level, or false to log none. Optional; the default
# is false.
log_api_calls = false
# Fake a slow network by delaying every API response by this many milliseconds;
# a negative value delays a random amount between 0 and its magnitude. Optional;
# leaving it out delays nothing.
# fake_api_delays = 100
# The probability, from 0 to 1, of answering an API call with a fake HTTP 404 or
# HTTP 500 error. Optional; the defaults are 0.
fake_error404_probability = 0.0
fake_error500_probability = 0.0
[import]
# The log files the import pipeline writes. Their directory must already exist.
log_file = "<IMPORT_LOG_DIR>/opus_import.log"
debug_log_file = "<IMPORT_LOG_DIR>/opus_import_debug.log"
# Whether observation rows are written with LOAD DATA LOCAL INFILE from a scratch
# file, much the faster way, rather than with INSERT statements. The import falls back
# to INSERT statements on its own, and says so in its log, when the server refuses
# local files. Optional; the default is the value below.
bulk_load = true
# The directory the bulk load writes its scratch files in. A load of a large table
# writes gigabytes, so point this at disk if the system temporary directory is
# memory-backed (a tmpfs). Optional; leaving it out uses the system temporary
# directory.
# scratch_dir = "/var/tmp/opus_import"
# The most rows one bulk load writes in one transaction. Lower it for shorter
# transactions, which roll back faster when an import is killed, and less undo held
# by the server; raise it for fewer statements and commits. Optional; the default is
# the value below.
transaction_rows = 100000
# How many processes compute an index's observations. 1 is the import's own process;
# more forks a pool of that many. "max" asks for the ceiling below. Optional; the
# default is the value below.
workers = 1
# How many tables the import's finalization builds indexes on at once, each over a
# connection of its own. The database server does the work, so raise this only when
# the server has cores to spare beyond whatever else shares its computer. "max" asks for
# the ceiling below. Optional; the default is the value below.
index_workers = 1
# No request takes every core, since the database server or another user may share
# the computer: workers and index_workers above max(1, floor(cores * cpu_fraction))
# are each lowered to it, where cores is the number the import counts as available to
# it. cpu_fraction must be greater than 0 and at most 1. Optional; the default is the
# value below.
cpu_fraction = 0.75
# The index rows one worker task covers. Smaller tasks keep every worker busy closer to
# the end of an index; larger ones spend less on handing out tasks. Optional; the
# default is the value below.
worker_rows = 500
# How many importers opus_import_all starts on this computer, each an opus_import
# process drawing bundles from one queue. Its total of workers (opus_import_all
# --workers, or workers above) is divided among them, and they are capped at that
# total. opus_import_all --importers replaces it for one run. Optional; the default is
# the value below.
importers = 4
# The minutes an importer that is alive may go without committing a chunk of rows
# before opus_import_all reports it as stalled. It is never stopped for it. Optional;
# the default is the value below.
stall_warning_minutes = 30
# The minutes between opus_import_all's totals lines when its output is not a
# terminal, as under nohup. Optional; the default is the value below.
status_interval_minutes = 5
# A directory on the database server's host, writable by mysqld, where the server
# sorts the indexes finalization builds, when its own temporary directory is too
# small. It names a path on the server, not on the computer running the import.
# Setting it needs an account that may set restricted session variables. Optional;
# leaving it out keeps the server's own setting.
# server_tmpdir = "/var/tmp/mysql_ddl"