Seafile server - 502 Bad Gateway

Dear all,

I have been using seafile for several years without any problems and I am very satisfied with the functionality and reliability :grinning:. But now I’m facing an issue what is beyond my knowledge and capability.

For certain reason I have to shutdown my seafile server for more than 2 months. Before the shutdown, I synchronized all my local data to the server.
This week I restarted the server for the first time and the first step was to renew Let’s Encrypt certificate via nginx proxy manager. But even with the new certificate the server was not accessible. Therefore I update the seafile server to 10.11 and added the command “MARIADB_AUTO_UPGRADE=1” to the env section of the database.

But still after these changes, I get the error message “502 Bad Gateway” for the https. For http I can access the webgui.

After checking the logs again, I found an error in the seafile logs:
“Can’t connect to MySQL server on ‘db’ ([Errno 111] Connection refused)”" (see below

*** Running /etc/my_init.d/01_create_data_links.sh...
*** Booting runit daemon...
*** Runit started as PID 25
*** Running /scripts/enterpoint.sh...
2024-09-25 06:44:42 Nginx ready 
2024-09-25 06:44:42 This is an idle script (infinite loop) to keep container running. 
[2024-09-25 06:44:44] Skip running setup-seafile-mysql.py because there is existing seafile-data folder.
**waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'db' ([Errno 111] Connection refused)")**
[09/25/2024 06:44:44][upgrade]: The container was recreated, start fix the media symlinks
[09/25/2024 06:44:44][upgrade]: Done

Starting seafile server, please wait ...
Seafile server started

Done.

Starting seahub at port 8000 ...

Seahub is started

Done.

Finally, the strangest thing. I can access the webGui via http and can see data. But the data is older than 5 months. From my point of view, this is not logical. Because how can I see data even though there is no connection to the database?
If someone have been faced a similar issue or know the potential solution I appreciate your help :slight_smile:

Thanks in advance.

Best regards,
Michael

for me it looks like you mixed something up with your database. The file/folder structure that you see in the web interface comes from the database. Only If you really access the files, then seafile requests the data from the /storage folder.

Therefore, please try to clarify what happens with your database. Did you switched from native to docker? Did you something else?

Hello,

I didn´t change anything. My seafile runs in a docker container hosted in a VM on a Proxmox server.
Below the docker-file:

version: '2.0'
services:
  db:
    image: mariadb:10.11
    container_name: seafile-mysql
    environment:
      - MYSQL_ROOT_PASSWORD=xxxxx  # Requested, set the root's password of MySQL service.
      - MYSQL_LOG_CONSOLE=true
      - MARIADB_AUTO_UPGRADE=1
    volumes:
      - /mnt/datastore/seafile-mysql/db:/var/lib/mysql  # Requested, specifies the path to MySQL data persistent store.
    restart: unless-stopped
    networks:
      - seafile-net

  memcached:
    image: memcached:1.6
    container_name: seafile-memcached
    entrypoint: memcached -m 256
    restart: unless-stopped
    networks:
      - seafile-net

  seafile:
    image: seafileltd/seafile-mc:11.0.11
    container_name: seafile
    ports:
      - "80:80"
#     - "443:443"  # If https is enabled, cancel the comment.
    volumes:
      - /mnt/datastore/seafile-data:/shared   # Requested, specifies the path to Seafile data persistent store.
    environment:
      - DB_HOST=db
      - DB_ROOT_PASSWD=xxxxx  # Requested, the value shuold be root's password of MySQL service.
      - TIME_ZONE=Europe/Berlin  # Optional, default is UTC. Should be uncomment and set to your local time zone.
#      - SEAFILE_ADMIN_EMAIL=me@example.com # Specifies Seafile admin user, default is 'me@example.com'.
#      - SEAFILE_ADMIN_PASSWORD=asecret     # Specifies Seafile admin password, default is 'asecret'.
#      - SEAFILE_SERVER_LETSENCRYPT=false   # Whether to use https or not.
#      - SEAFILE_SERVER_HOSTNAME=docs.seafile.com # Specifies your host name if https is enabled.
    depends_on:
      - db
      - memcached
    restart: unless-stopped
    networks:
      - seafile-net

networks:
  seafile-net:

That’s why I don’t understand what the problem is and therefore don’t know where to start :thinking:.

Edit:
I have tested several commands to find the root cause:

Database:

root@seafile:/seafile# docker compose exec db /bin/bash
root@432d34654d93:/# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 1401
Server version: 10.11.7-MariaDB-1:10.11.7+maria~ubu2204 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| ccnet_db           |
| information_schema |
| mysql              |
| performance_schema |
| seafile_db         |
| seahub_db          |
| sys                |
+--------------------+
7 rows in set (0.000 sec)

MariaDB [(none)]> SELECT host, user FROM mysql.user;
+-----------+-------------+
| Host      | User        |
+-----------+-------------+
| %         | root        |
| %.%.%.%   | seafile     |
| 127.0.0.1 | healthcheck |
| ::1       | healthcheck |
| localhost | healthcheck |
| localhost | mariadb.sys |
| localhost | root        |
+-----------+-------------+
7 rows in set (0.001 sec)

MariaDB [(none)]> EXIT;
Bye

Network:

docker network ls
NETWORK ID     NAME                  DRIVER    SCOPE
5c6deac6d889   bridge                bridge    local
e33b519f14e2   host                  host      local
d900e0751f40   none                  null      local
780a332fe413   seafile_seafile-net   bridge    local

Connection from seafile server to the database:

root@seafile:/seafile# docker compose exec seafile /bin/bash
root@3c5f3ca08638:/opt/seafile# mysql -h db -u root -p
bash: mysql: command not found

But I still haven´t an idee :exploding_head:

Your docker-file looks ok, except from your ports. Your server can not be reachable via https, because only port 80 is exposed. Therefore I assume that you have any kind of reverse proxy…

But the problem is: your docker setup should not result in two month old data in your seafile. I would take a closer look into /mnt/datastore. Is this folder really mounted? Did you changed anything here?

Yes, I´m using nginx proxy manager for the deploying the ssl certificate.

Following you find some details of the /mnt/datastore

root@seafile:~# lsblk
NAME   MAJ:MIN RM  SIZE RO TYPE MOUNTPOINTS
sda      8:0    0   10G  0 disk 
├─sda1   8:1    0    9G  0 part /
├─sda2   8:2    0    1K  0 part 
└─sda5   8:5    0  975M  0 part [SWAP]
sdb      8:16   0  250G  0 disk 
└─sdb1   8:17   0  250G  0 part /mnt/datastore
sr0     11:0    1 1024M  0 rom  
root@seafile:~# cd /mnt/datastore/
root@seafile:/mnt/datastore# ls -la
insgesamt 32
drwxr-xr-x 5 root root  4096  9. Jan 2023  .
drwxr-xr-x 3 root root  4096  1. Okt 2023  ..
drwx------ 2 root root 16384  9. Jan 2023  lost+found
drwxr-xr-x 5 root root  4096  9. Jan 2023  seafile-data
drwxr-xr-x 3 root root  4096  9. Jan 2023  seafile-mysql
root@seafile:/mnt/datastore# cd seafile-data/
root@seafile:/mnt/datastore/seafile-data# ls -la
insgesamt 20
drwxr-xr-x 5 root root 4096  9. Jan 2023  .
drwxr-xr-x 5 root root 4096  9. Jan 2023  ..
drwxr-xr-x 3 root root 4096  9. Jan 2023  logs
drwxr-xr-x 3 root root 4096  9. Jan 2023  nginx
drwxr-xr-x 7 root root 4096  9. Jan 2023  seafile
root@seafile:/mnt/datastore/seafile-data# date
Sa 28. Sep 23:58:32 CEST 2024

During this task I have notied the timestamp of the folders :scream_cat:. Thererfore I checked the last database entry:

MariaDB [seahub_db]> DESCRIBE UserActivity;
+-------------+--------------+------+-----+---------+----------------+
| Field       | Type         | Null | Key | Default | Extra          |
+-------------+--------------+------+-----+---------+----------------+
| id          | int(11)      | NO   | PRI | NULL    | auto_increment |
| username    | varchar(255) | NO   | MUL | NULL    |                |
| activity_id | int(11)      | YES  | MUL | NULL    |                |
| timestamp   | datetime     | NO   | MUL | NULL    |                |
+-------------+--------------+------+-----+---------+----------------+
4 rows in set (0.001 sec)


MariaDB [seahub_db]> SELECT username, MAX(timestamp) AS latest_activity
    -> FROM UserActivity
    -> GROUP BY username;
+--------------------------+---------------------+
| username                 | latest_activity     |
+--------------------------+---------------------+
| User1   | 2024-04-24 00:17:36 |
| User2   | 2024-04-24 00:17:36 |
| User3   | 2024-04-24 00:17:36 |
+--------------------------+---------------------+
3 rows in set (0.014 sec)

Edit:

I have checked my paperless VM protocols and the timestamps fits to my memory :grinning:. Both VMs hosted on the same proxmox server.