Skip to content

Add multi-instance support - #3725

Open
meisterT wants to merge 4 commits into
DOMjudge:mainfrom
meisterT:multi-instance-support
Open

Add multi-instance support#3725
meisterT wants to merge 4 commits into
DOMjudge:mainfrom
meisterT:multi-instance-support

Conversation

@meisterT

Copy link
Copy Markdown
Member

No description provided.

@meisterT

Copy link
Copy Markdown
Member Author

@vmcj this is the second half of my change

Comment thread doc/manual/develop.rst
derives an *instance name* from the name of the directory the source tree
lives in, and uses it for

* the webserver and PHP-FPM configuration file names installed into

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might have missed it, but shouldn't we also name the nginx/apache config files something with the instance in there when installing?

i.e. instead of /etc/nginx/snippets/domjudge-inner.conf (or something we did) we do /etc/nignx/snippets/domjudge-inner-{instance}.conf?

The path DOMjudge is served under was written twice and had to be kept in
sync by hand: once as --with-baseurl, which only reaches
etc/domserver-static.php and webapp/config/static.yaml, and again as a
literal /domjudge in the Apache and nginx templates. Configuring a base
URL therefore silently left the webserver configuration pointing
somewhere else.

Derive the prefix from the base URL instead. Since the two cases differ
in kind rather than in value -- Apache needs DocumentRoot instead of
Alias, and nginx has no meaningful empty-prefix form of the redirect --
add a small marker mechanism to the template substitution that keeps or
drops whole lines depending on whether the prefix is empty.

Note that nginx's 'set' directive requires two arguments, so the empty
prefix has to be written as an explicit empty string.

This changes the generated configuration for installations whose base URL
has no path: they now get a configuration serving DOMjudge from the root,
which is what their base URL says, rather than from /domjudge.
Everything DOMjudge installs outside its own prefix was named 'domjudge',
so a second installation on the same host silently took over the first
one's configuration: the Apache and nginx configuration files, the
PHP-FPM pool file and the sudoers file all have fixed names, and the
generated database credentials always name the database and its user
'domjudge'.

Name all of those after a configurable instance instead. Note that the
nginx upstream and the variable holding the HTTPS flag are global to
nginx, so a duplicate is not merely confusing but makes nginx refuse to
start.

The name is sanitized so that it is usable as a file name, an nginx
upstream name and a database user, and truncated to 24 characters since
MySQL limits user names to 32. A name that reduces to nothing is an error
rather than a silent fallback to the default instance.

The default instance keeps every historic name, and also remains the
catch-all server on port 80; only named instances take their server name
and port from the base URL. Generated files are therefore unchanged for
existing installations.
Working on several branches at once, e.g. with git worktree or jj
workspace, meant only one checkout could have a working installation,
since every in-place install used the same configuration file names and
the same database.

Derive the instance name and a matching base URL from the name of the
directory the source tree lives in, so that a worktree needs no extra
flags at all. A checkout named 'domjudge' keeps the historic defaults.

Each instance is served under its own hostname rather than its own port
or path, because browsers do not scope cookies by port and DOMjudge does
not scope its session cookie to the base path; two instances sharing a
hostname would keep invalidating each other's sessions.

An empty derived name would be passed as --with-instance-name='', which
configure treats as unset, so the tree would silently install itself as
the default instance; refuse to configure in that case instead. Likewise,
refuse to install a webserver configuration file that already belongs to
a different source tree, which catches two directory names reducing to
the same instance name.
@meisterT
meisterT force-pushed the multi-instance-support branch from 75fd423 to cc483f5 Compare September 3, 2026 20:56
Comment thread .github/jobs/configure-checks/shared_post.bats Outdated
Co-authored-by: MCJ Vasseur <14887731+vmcj@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants