Skip to content

Fatal error while having multiple IP addresses through one network adapter #221

Open
@Rajdave69

Description

@Rajdave69

Description of the problem

If you have multiple IP addresses set up on a single network adapter (enp0s3 for example) it causes the DomServer Container to crash with this:

domserver  | [..] Running start script 10-timezone.sh
domserver  | 
domserver  | Current default time zone: 'Asia/Riyadh'
domserver  | Local time is now:      Tue Apr 15 17:59:03 +03 2025.
domserver  | Universal Time is now:  Tue Apr 15 14:59:03 UTC 2025.
domserver  | 
domserver  | [ok] Container timezone set to: Asia/Riyadh
domserver  | 
domserver  | [..] Running start script 50-domjudge.sh
domserver  | [..] Generating credential files
domserver  | Password file 'dbpasswords.secret' already exists, leaving untouched.
domserver  | Running 'genrestapicredentials'... file 'restapi.secret' created.
domserver  | Running 'gensymfonysecret'... file 'symfony_app.secret' created.
domserver  | Running 'genadminpassword'... file 'initial_admin_password.secret' created.
domserver  | Fix WEBAPP_BASEURL  -> /
domserver  | [ok] Generated credential files
domserver  | 
domserver  | [..] Checking database connection
domserver  |   Database not installed; installing...
domserver  | Using install...
domserver  | Database credentials read from '/opt/domjudge/domserver/etc/dbpasswords.secret'.
domserver  | DOMjudge database and user(s) created.
domserver  | PHP Fatal error:  Uncaught Symfony\Component\Dotenv\Exception\FormatException: Invalid character in variable name in ".env" at line 2.
domserver  | ...D_PROXIES=10.11.0.1\n192.168.100.1\n...
domserver  |                        ^ line 2 offset 26 in /opt/domjudge/domserver/lib/vendor/symfony/dotenv/Dotenv.php:546
domserver  | Stack trace:
domserver  | #0 /opt/domjudge/domserver/lib/vendor/symfony/dotenv/Dotenv.php(271): Symfony\Component\Dotenv\Dotenv->createFormatException()
domserver  | DOMjudge/domjudge#1 /opt/domjudge/domserver/lib/vendor/symfony/dotenv/Dotenv.php(244): Symfony\Component\Dotenv\Dotenv->lexVarname()
domserver  | DOMjudge/domjudge#2 /opt/domjudge/domserver/webapp/config/load_db_secrets.php(18): Symfony\Component\Dotenv\Dotenv->parse()
domserver  | DOMjudge/domjudge#3 /opt/domjudge/domserver/webapp/config/load_db_secrets.php(55): get_db_url()
domserver  | DOMjudge/domjudge#4 /opt/domjudge/domserver/webapp/bin/console(12): require_once('...')
domserver  | DOMjudge/domjudge#5 /opt/domjudge/domserver/lib/vendor/autoload_runtime.php(9): require('...')
domserver  | DOMjudge/domjudge#6 /opt/domjudge/domserver/webapp/bin/console(11): require_once('...')
domserver  | DOMjudge/domjudge#7 {main}
domserver  |   thrown in /opt/domjudge/domserver/lib/vendor/symfony/dotenv/Dotenv.php on line 546
domserver  | [!!] Start script 50-domjudge.sh failed
domserver exited with code 1

Note that 10.11.0.1 and 192.168.100.1 are the default gateways here

Your environment

Docker config:

services:
  domserver:
    image: domjudge/domserver:latest
    container_name: domserver
    restart: unless-stopped
    network_mode: "host"
    environment:
      CONTAINER_TIMEZONE: Asia/Riyadh
      MYSQL_HOST: 127.0.0.1
      MYSQL_USER: domjudge
      MYSQL_DATABASE: domjudge
      MYSQL_PASSWORD: "$DOMJUDGE_MYSQL_PASSWORD"
      MYSQL_ROOT_PASSWORD: "$ROOT_MYSQL_PASSWORD"
    stdin_open: true
    tty: true
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup
EOF

Steps to reproduce

Here are my exact steps of installation and setup on a fresh Ubuntu VM:

Note that the device currently already has an IP: 192.168.100.129 assigned via DHCP

sudo su

nano /etc/netplan/00-installer-config.yaml

put the following in

network:
  version: 2
  ethernets:
    enp0s3:  # replace with your interface name
      dhcp4: no
      addresses:
        - 10.11.80.201/8  # your desired static IP
      gateway4: 10.11.0.1  # your gateway
      nameservers:
        addresses:
          - 1.1.1.1
          - 8.8.8.8

run:

netplan apply

# Configure static hostname resolution
# Enter the local IPs of the servers
tee -a /etc/hosts > /dev/null <<EOF

# Custom static hostname resolution
10.11.80.201 main.domserver.local
10.11.80.202 fallback.domserver.local
EOF

# Set persistent variables (!!! DO NOT MODIFY IPs !!!)
# Check network interface with `ip -brief address show`
tee -a /etc/environment > /dev/null <<EOF
ROOT_MYSQL_PASSWORD=""
DOMJUDGE_MYSQL_PASSWORD=""
REPL_PASS="DWtScwOpHfBZ"
SERVER_1_IP="main.domserver.local"
SERVER_2_IP="fallback.domserver.local"
virtual_ip='10.11.80.200/8'
keepalived_pass=''
network_interface='enp0s3'
EOF

# Log out and re-login as root user to set the persistent variables
exit

# Enter root user terminal
sudo su

# Update packages
apt update && apt upgrade -y

# Install Docker
curl -sSL https://get.docker.com/ | CHANNEL=stable bash
systemctl enable --now docker

# Install MariaDB
apt install mariadb-server -y

# Install keepalived
apt install keepalived -y

# Install required package
apt install cifs-utils -y

# Install samba
apt install samba -y

# Edit `/etc/mysql/mariadb.conf.d/50-server.cnf` and change `bind-address` to `0.0.0.0`
sed -i 's/^bind-address\s*=.*/bind-address = 0.0.0.0/' /etc/mysql/mariadb.conf.d/50-server.cnf

# First, add the configuration without applying it yet
tee -a /etc/mysql/mariadb.conf.d/60-domjudge.cnf > /dev/null <<EOF
[mysqld]
max_connections = 1000
max_allowed_packet = 100M
EOF

systemctl stop mariadb

# Move to MariaDB data directory
cd /var/lib/mysql

# Backup the old log files (just in case)
mkdir -p /tmp/mysql_log_backup
cp ib_logfile* ibdata1 /tmp/mysql_log_backup/

# Now remove the old log files
rm -f ib_logfile* ibdata1

# Add the innodb_log_file_size setting now
echo "innodb_log_file_size = 512M" >> /etc/mysql/mariadb.conf.d/60-domjudge.cnf

systemctl start mariadb
ufw allow 3306/tcp

# Secure the MariaDB installation
mysql --user=root <<EOF
ALTER USER 'root'@'localhost' IDENTIFIED BY "${ROOT_MYSQL_PASSWORD}";
DELETE FROM mysql.user WHERE User='';
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
DROP DATABASE IF EXISTS test;
DELETE FROM mysql.db WHERE Db='test' OR Db='test\_%';
FLUSH PRIVILEGES;
EOF

# Logging into MariaDB, and creating the user for domjudge
mysql -u root -p${ROOT_MYSQL_PASSWORD} -e "
CREATE USER 'domjudge'@'%' IDENTIFIED BY '${DOMJUDGE_MYSQL_PASSWORD}';
GRANT ALL PRIVILEGES ON domjudge.* TO 'domjudge'@'%';
FLUSH PRIVILEGES;"

# Logging into MariaDB, and creating the user for replication
mysql -u root mysql -u root -p${ROOT_MYSQL_PASSWORD} -e "
CREATE USER 'replicator'@'%' IDENTIFIED BY '$REPL_PASS'; 
GRANT REPLICATION SLAVE ON *.* TO 'replicator'@'%';
FLUSH PRIVILEGES;"

# Create docker container
cd /
mkdir docker-containers
cd docker-containers

# Creating a file `docker-compose.yml` with the Docker Compose
cat >> docker-compose.yml <<EOF
services:
  domserver:
    image: domjudge/domserver:latest
    container_name: domserver
    restart: unless-stopped
    network_mode: "host"
    environment:
      CONTAINER_TIMEZONE: Asia/Riyadh
      MYSQL_HOST: 127.0.0.1
      MYSQL_USER: domjudge
      MYSQL_DATABASE: domjudge
      MYSQL_PASSWORD: "$DOMJUDGE_MYSQL_PASSWORD"
      MYSQL_ROOT_PASSWORD: "$ROOT_MYSQL_PASSWORD"
    stdin_open: true
    tty: true
    volumes:
      - /sys/fs/cgroup:/sys/fs/cgroup
EOF


# Creating the required database
mysql -u root -p${ROOT_MYSQL_PASSWORD} -e "CREATE DATABASE domjudge;"

docker compose up -d

It errors out as soon as I start the container and shows this error.

Expected behaviour

For the generated trusted proxies to be formatted maybe like "192.168.100.1, 10.11.0.1" instead of having \n

Actual behaviour

domserver  | PHP Fatal error:  Uncaught Symfony\Component\Dotenv\Exception\FormatException: Invalid character in variable name in ".env" at line 2.
domserver  | ...D_PROXIES=10.11.0.1\n192.168.100.1\n...
domserver  |                        ^ line 2 offset 26 in /opt/domjudge/domserver/lib/vendor/symfony/dotenv/Dotenv.php:546

The formatting seems to be incorrect.

Undoing the IP address setup part seems to fix it

Any other information that you want to share?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions