我有一个使用 celery 执行后台任务的 Python 应用程序。我使用 SCL 提供的 Python 解释器。
我能够为应用程序创建一个 systemd 单元文件:如何通过 systemd 使用用户的 pipenv?Python 是通过 SCL 安装的
但我不明白如何为 celery 放置一个类似的 sytstemd 单元文件。
我试过了:
[Unit]
Description=app celery service
# Requirements
Requires=network.target
# Dependency ordering
After=network.target
[Service]
# Let processes take awhile to start up
TimeoutStartSec=0
Type=forking
RestartSec=10
Restart=always
Environment="APP_SITE_SETTINGS=/home/app/.config/settings.cfg"
Environment="PYTHONPATH=/home/app/.local/lib/python3.6/site-packages"
WorkingDirectory=/home/app/app-site/app
User=app
Group=app
PermissionsStartOnly=true
KillSignal=SIGQUIT
Type=notify
NotifyAccess=all
# Main process
ExecStart=/usr/bin/scl enable rh-python36 -- /home/app/.local/bin/pipenv run celery -A celery_service.celery worker
[Install]
WantedBy=multi-user.target
当我启动 systemd 单元时,在日志中我看到 celery 应用程序启动了。几秒钟后,服务失败。
Job for app_celery.service failed because a timeout was exceeded. See "systemctl status app_celery.service" and "journalctl -xe" for details.
这是一个日记条目:
Jul 17 07:43:31 some.host.com scl[5181]: worker: Cold shutdown (MainProcess)
我也尝试过 Type=oneshot 和 Type=simple 。他们都没有工作。我怀疑这与 SCL 有关。
有没有办法让 celery 应用程序与 SCL 和 systemd 一起使用?