Seafile 13 Pro binary - manual pro.py virus_scan error "(2003, "Can't connect to MySQL server on 'db' ([Errno -2] Name or service not known)")"

Hi all,

I have a fresh installation of Seafile pro 13.0.18 (binary installation) on a Debian 13 system with mariadb database. I installed everything from scratch as described in the documentation including python packages.

Everything is working fine (upload without enabled virus_scan, editing, elasticsearch) but the only thing which fails is the virus_scan. I´m using clamav as virus scanner. When its enabled then the upload fails with message “file has virus“. When I run manually “pro.py virus_scan” then I get the exception “sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, “Can’t connect to MySQL server on ‘db’ ([Errno -2] Name or service not known)”)“

My .env file contains the necessary MYSQL data like SEAFILE_MYSQL_DB_HOST=127.0.0.1, SEAFILE_MYSQL_DB_PORT, SEAFILE_MYSQL_DB_USER, SEAFILE_MYSQL_DB_PASSWORT, SEAFILE_MYSQL_DB_CCNET_DB_NAME, SEAFILE_MYSQL_DB_SEAFILE_DB_NAME and SEAFILE_MYSQL_DB_SEAHUB_DB_NAME.

My seafile.conf contains also the correct database information and the virus_scan options:

[virus_scan]
scan_command = clamdscan
nonvirus_code = 0
virus_code = 1
scan_interval = 20

I don´t know why it is says that it has no database connection?

This is the full exception message:

(python-venv) seafile@edms:/srv/seafile$ seafile-server-latest/pro/pro.py virus_scan
Traceback (most recent call last):
File “/srv/seafile/seafile-server-latest/seahub/thirdpart/pymysql/connections.py”, line 661, in connect
sock = socket.create_connection(
(self.host, self.port), self.connect_timeout, **kwargs
)
File “/usr/lib/python3.13/socket.py”, line 840, in create_connection
for res in getaddrinfo(host, port, 0, SOCK_STREAM):
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/usr/lib/python3.13/socket.py”, line 977, in getaddrinfo
for res in _socket.getaddrinfo(host, port, family, type, proto, flags):
~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
socket.gaierror: [Errno -2] Name or service not known

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 143, in init
self._dbapi_connection = engine.raw_connection()
~~~~~~~~~~~~~~~~~~~~~^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 3309, in raw_connection
return self.pool.connect()
~~~~~~~~~~~~~~~~~^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 447, in connect
return _ConnectionFairy._checkout(self)
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 1264, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 711, in checkout
rec = pool._do_get()
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/impl.py”, line 177, in _do_get
with util.safe_reraise():
~~~~~~~~~~~~~~~~~^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py”, line 224, in exit
raise exc_value.with_traceback(exc_tb)
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/impl.py”, line 175, in _do_get
return self._create_connection()
~~~~~~~~~~~~~~~~~~~~~~~^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 388, in _create_connection
return _ConnectionRecord(self)
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 673, in init
self.__connect()
~~~~~~~~~~~~~~^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 899, in __connect
with util.safe_reraise():
~~~~~~~~~~~~~~~~~^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py”, line 224, in exit
raise exc_value.with_traceback(exc_tb)
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 895, in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
~~~~~~~~~~~~~~~~~~~~^^^^^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/engine/create.py”, line 661, in connect
return dialect.connect(*cargs, **cparams)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/engine/default.py”, line 630, in connect
return self.loaded_dbapi.connect(*cargs, **cparams) # type: ignore[no-any-return] # NOQA: E501
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File “/srv/seafile/seafile-server-latest/seahub/thirdpart/pymysql/connections.py”, line 365, in init
self.connect()
~~~~~~~~~~~~^^
File “/srv/seafile/seafile-server-latest/seahub/thirdpart/pymysql/connections.py”, line 723, in connect
raise exc
pymysql.err.OperationalError: (2003, “Can’t connect to MySQL server on ‘db’ ([Errno -2] Name or service not known)”)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File “”, line 198, in _run_module_as_main
File “”, line 88, in _run_code
File “/srv/seafile/seafile-server-latest/pro/python/seafevents/virus_scanner/run_virus_scan.py”, line 39, in
prepare_db_tables()
~~~~~~~~~~~~~~~~~^^
File “/srv/seafile/seafile-server-latest/pro/python/seafevents/db.py”, line 107, in prepare_db_tables
SeafBase.prepare(autoload_with=engine)
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File “”, line 2, in prepare
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/util/deprecations.py”, line 281, in warned
return fn(*args, **kwargs) # type: ignore[no-any-return]
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/ext/automap.py”, line 1265, in prepare
cls.metadata.reflect(autoload_with, **opts) # type: ignore[arg-type] # noqa: E501
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/sql/schema.py”, line 5817, in reflect
with inspection.inspect(bind)._inspection_context() as insp:
~~~~~~~~~~~~~~~~~~^^^^^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/inspection.py”, line 140, in inspect
ret = reg(subject)
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/engine/reflection.py”, line 313, in _engine_insp
return Inspector._construct(Inspector._init_engine, bind)
~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/engine/reflection.py”, line 246, in _construct
init(self, bind)
~~~~^^^^^^^^^^^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/engine/reflection.py”, line 257, in _init_engine
engine.connect().close()
~~~~~~~~~~~~~~^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 3285, in connect
return self._connection_cls(self)
~~~~~~~~~~~~~~~~~~~~^^^^^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 145, in init
Connection._handle_dbapi_exception_noconnection(
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
err, dialect, engine
^^^^^^^^^^^^^^^^^^^^
)
^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 2448, in _handle_dbapi_exception_noconnection
raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 143, in init
self._dbapi_connection = engine.raw_connection()
~~~~~~~~~~~~~~~~~~~~~^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/engine/base.py”, line 3309, in raw_connection
return self.pool.connect()
~~~~~~~~~~~~~~~~~^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 447, in connect
return _ConnectionFairy._checkout(self)
~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 1264, in _checkout
fairy = _ConnectionRecord.checkout(pool)
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 711, in checkout
rec = pool._do_get()
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/impl.py”, line 177, in _do_get
with util.safe_reraise():
~~~~~~~~~~~~~~~~~^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py”, line 224, in exit
raise exc_value.with_traceback(exc_tb)
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/impl.py”, line 175, in _do_get
return self._create_connection()
~~~~~~~~~~~~~~~~~~~~~~~^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 388, in _create_connection
return _ConnectionRecord(self)
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 673, in init
self.__connect()
~~~~~~~~~~~~~~^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 899, in __connect
with util.safe_reraise():
~~~~~~~~~~~~~~~~~^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/util/langhelpers.py”, line 224, in exit
raise exc_value.with_traceback(exc_tb)
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/pool/base.py”, line 895, in __connect
self.dbapi_connection = connection = pool._invoke_creator(self)
~~~~~~~~~~~~~~~~~~~~^^^^^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/engine/create.py”, line 661, in connect
return dialect.connect(*cargs, **cparams)
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File “/srv/seafile/python-venv/lib/python3.13/site-packages/sqlalchemy/engine/default.py”, line 630, in connect
return self.loaded_dbapi.connect(*cargs, **cparams) # type: ignore[no-any-return] # NOQA: E501
~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^
File “/srv/seafile/seafile-server-latest/seahub/thirdpart/pymysql/connections.py”, line 365, in init
self.connect()
~~~~~~~~~~~~^^
File “/srv/seafile/seafile-server-latest/seahub/thirdpart/pymysql/connections.py”, line 723, in connect
raise exc
sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, “Can’t connect to MySQL server on ‘db’ ([Errno -2] Name or service not known)”)

After updating Seafile to 3.0.19 I had the same problems. In the logs I saw that OPENSSL show a message, when I upload a file:

clamdscan: /srv/seafile/seafile-pro-server-13.0.19/seafile/lib/libcrypto.so.3: version `OPENSSL_3.4.0’ not found (required by /lib/x86_64-linux-gnu/libclamav.so.12)

The error (2003, “Can’t connect to MySQL server on ‘db’ ([Errno -2] Name or service not known)”) indicates that the pro.py script is trying to connect to a database host named ‘db’. In a binary installation, the database is usually on 127.0.0.1. The hostname db is the default for Docker-based deployments 1.

It appears the script is defaulting to Docker configurations or is not correctly picking up your .env or configuration files during the manual execution.

Check Environment Variables When running pro.py virus_scan manually, the script may not automatically load the .env file. You should explicitly export the database host before running the command:

export SEAFILE_MYSQL_DB_HOST=127.0.0.1# You might also need to export other variables from your .env if they differ from defaults/srv/seafile/seafile-server-latest/pro/pro.py virus_scan

What’s the content of your conf/seafevents.conf? The database settings should be removed from seafevents.conf.

Address the OpenSSL Version Mismatch Regarding the error libcrypto.so.3: version OPENSSL_3.4.0’ not found: This happens because Seafile’s bundled libraries in seafile/lib/ may conflict with the system libraries required by Debian 13’s clamdscan.

  • Workaround: Try running the scan while bypassing Seafile’s bundled library path or ensure the system’s LD_LIBRARY_PATH prioritizes system libraries for the clamdscan command.
  • Alternatively, ensure you are running the script as the seafile user within the activated virtual environment to avoid permission or path issues

We can reproduce the bug. It is related to the way of reading database configuration from environtment. We will give it a detailed check soon.

Thanks for your answer. Good to hear that you can reproduce the error. I thougt that´s a configuration issue on my site.

With the exported environment variables from the .env file I don´t get the database error message.

My seafevents.conf file does not contain database settings.

The fix will be included in the next release.

Related PR: 13.0 pro.py load_env_file by SkywalkerSpace · Pull Request #8796 · haiwen/seahub · GitHub

1 Like