haiwen / seafile-docker

A Docker image for Seafile server
Other
547 stars 185 forks source link

Race condition between Seahub and MySQL #408

Open Kreeblah opened 1 week ago

Kreeblah commented 1 week ago

I use the following (redacted) Docker compose file for my Seafile installation. It's very similar to the official one:

services:
  seafile-db:
    image: mariadb:10.11
    container_name: seafile-mysql
    environment:
      - MYSQL_ROOT_PASSWORD=SOME_PASSWORD  # Required, set the root's password of MySQL service.
      - MYSQL_LOG_CONSOLE=true
      - MARIADB_AUTO_UPGRADE=1
    volumes:
      - /opt/seafile-mysql:/var/lib/mysql  # Required, specifies the path to MySQL data persistent store.
    networks:
      - seafile-net

  memcached:
    image: memcached:1.6.18
    container_name: seafile-memcached
    entrypoint: memcached -m 256
    networks:
      - seafile-net

  seafile:
    image: seafileltd/seafile-mc:11.0-latest
    container_name: seafile
    ports:
      - "80:80"
    volumes:
      - /opt/seafile-data:/shared   # Required, specifies the path to Seafile data persistent store.
    environment:
      - DB_HOST=seafile-db
      - DB_ROOT_PASSWD=SOME_PASSWORD  # Required, the value should be root's password of MySQL service.
      - TIME_ZONE=Etc/UTC  # Optional, default is UTC. Should be uncomment and set to your local time zone.
      - SEAFILE_ADMIN_EMAIL=seafile@mydomain.com # Specifies Seafile admin user, default is 'me@example.com'.
      - SEAFILE_ADMIN_PASSWORD=ADMIN_PASSWORD     # Specifies Seafile admin password, default is 'asecret'.
      - SEAFILE_SERVER_LETSENCRYPT=false   # Whether to use https or not.
      - SEAFILE_SERVER_HOSTNAME=seafile.mydomain.com # Specifies your host name if https is enabled.
    depends_on:
      - seafile-db
      - memcached
    networks:
      - seafile-net

networks:
  seafile-net:

I also have systemd set up to launch it:

[Unit]
Description=Seafile container
Requires=network-online.target docker.service
After=network-online.target docker.service

[Service]
Restart=always
ExecStart=/usr/bin/docker compose -f /root/seafile/docker-compose.yml up
ExecStop=/usr/bin/docker compose stop seafile; /usr/bin/docker compose stop memcached; /usr/bin/docker compose stop seafile-db

[Install]
WantedBy=default.target

However, about half the time when I start the service, Seahub fails to start because MySQL isn't quite ready by the time it checks. It doesn't seem to retry, either. The specific error I see is:

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

Done.

Starting seahub at port 8000 ...
Error:Seahub failed to start.
Please try to run "./seahub.sh start" again
Traceback (most recent call last):
  File "/scripts/start.py", line 94, in <module>
waiting for mysql server to be ready: %s (2003, "Can't connect to MySQL server on 'seafile-db' ([Errno 111] Connection refused)")
    main()
  File "/scripts/start.py", line 80, in main
    call('{} start'.format(get_script('seahub.sh')))
  File "/scripts/utils.py", line 70, in call
    return subprocess.check_call(*a, **kw)
  File "/usr/lib/python3.10/subprocess.py", line 369, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '/opt/seafile/seafile-server-11.0.12/seahub.sh start' returned non-zero exit status 1.

In those cases, I either need to stop the service and start it again, or run seahub.sh within the container manually in order to successfully start Seahub.

freeplant commented 1 week ago

We are re-designing the docker image for version 12.0. We will keep the issue in mind during the process.

If you still have the problem at that time, just let me know.