langgenius / dify

Dify is an open-source LLM app development platform. Dify's intuitive interface combines AI workflow, RAG pipeline, agent capabilities, model management, observability features and more, letting you quickly go from prototype to production.
https://dify.ai
Other
51.51k stars 7.44k forks source link

Celery not starting correctly when LOG_FILE is empty #10555

Closed fdb02983rhy closed 1 day ago

fdb02983rhy commented 2 days ago

Self Checks

Dify version

0.11.1

Cloud or Self Hosted

Self Hosted (Docker)

Steps to reproduce

Keep the LOG_FILE environment variable empty then run docker compose

✔️ Expected Behavior

Celery can starts successfully even the LOG_FILE is not set or empty.

❌ Actual Behavior

Celery cannot starts successfully even the LOG_FILE is not set or empty.

worker-1      | Traceback (most recent call last):
worker-1      |   File "/app/api/.venv/bin/celery", line 8, in <module>
worker-1      |     sys.exit(main())
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/__main__.py", line 15, in main
worker-1      |     sys.exit(_main())
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/bin/celery.py", line 236, in main
worker-1      |     return celery(auto_envvar_prefix="CELERY")
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/click/core.py", line 1157, in __call__
worker-1      |     return self.main(*args, **kwargs)
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/click/core.py", line 1078, in main
worker-1      |     rv = self.invoke(ctx)
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/click/core.py", line 1688, in invoke
worker-1      |     return _process_result(sub_ctx.command.invoke(sub_ctx))
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/click/core.py", line 1434, in invoke
worker-1      |     return ctx.invoke(self.callback, **ctx.params)
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/click/core.py", line 783, in invoke
worker-1      |     return __callback(*args, **kwargs)
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/click/decorators.py", line 33, in new_func
worker-1      |     return f(get_current_context(), *args, **kwargs)
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/bin/base.py", line 135, in caller
worker-1      |     return f(ctx, *args, **kwargs)
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/bin/worker.py", line 348, in worker
worker-1      |     worker = app.Worker(
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/worker/worker.py", line 98, in __init__
worker-1      |     self.setup_instance(**self.prepare_args(**kwargs))
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/worker/worker.py", line 131, in setup_instance
worker-1      |     self.on_init_blueprint()
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/apps/worker.py", line 116, in on_init_blueprint
worker-1      |     self._custom_logging = self.setup_logging()
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/apps/worker.py", line 180, in setup_logging
worker-1      |     return self.app.log.setup(
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/app/log.py", line 63, in setup
worker-1      |     handled = self.setup_logging_subsystem(
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/app/log.py", line 117, in setup_logging_subsystem
worker-1      |     self._configure_logger(
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/app/log.py", line 150, in _configure_logger
worker-1      |     self.setup_handlers(logger, logfile, format,
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/app/log.py", line 216, in setup_handlers
worker-1      |     handler = self._detect_handler(logfile)
worker-1      |   File "/app/api/.venv/lib/python3.10/site-packages/celery/app/log.py", line 226, in _detect_handler
worker-1      |     return WatchedFileHandler(logfile, encoding='utf-8')
worker-1      |   File "/usr/local/lib/python3.10/logging/handlers.py", line 479, in __init__
worker-1      |     logging.FileHandler.__init__(self, filename, mode=mode,
worker-1      |   File "/usr/local/lib/python3.10/logging/__init__.py", line 1169, in __init__
worker-1      |     StreamHandler.__init__(self, self._open())
worker-1      |   File "/usr/local/lib/python3.10/logging/__init__.py", line 1201, in _open
worker-1      |     return open_func(self.baseFilename, self.mode,
worker-1      | IsADirectoryError: [Errno 21] Is a directory: '/app/api'
dosubot[bot] commented 2 days ago

Celery fails to start when the LOG_FILE setting is empty because it defaults to a directory path instead of a file path, leading to an "IsADirectoryError". To resolve this, ensure that the LOG_FILE environment variable is set to a valid file path where logs can be written. This can be done by specifying a file path in your docker-compose.yaml configuration under the LOG_FILE environment variable [1].

To continue talking to Dosu, mention @dosu.

fujita-h commented 2 days ago

I'm confirming the same issue.

xiandan-erizo commented 1 day ago

可以在环境变量中修改LOG_FILE,临时解决

yuzp-work commented 1 day ago

+1, this issue looks still here in 0.11.1

nicklhy commented 1 day ago

+1

rxue92 commented 1 day ago

FYI: If you don't need log file persistence and just want the worker container to start correctly, you can set the LOG_FILE variable in the .env file as shown below and run docker compose up -d.

# ------------------------------
# Server Configuration
# ------------------------------

# The log level for the application.
# Supported values are `DEBUG`, `INFO`, `WARNING`, `ERROR`, `CRITICAL`
LOG_LEVEL=INFO
# Log file path
LOG_FILE=/app/logs/server.log
# Log file max size, the unit is MB
LOG_FILE_MAX_SIZE=20
# Log file max backup count
LOG_FILE_BACKUP_COUNT=5
# Log dateformat
LOG_DATEFORMAT=%Y-%m-%d %H:%M:%S