我有一个Python应用程序,它使用celener执行后台任务。我使用SCL提供的Python解释器。
我能够为应用程序创建一个systemd单元文件:如何使用user';s pipenv通过systemd?Python是通过SCL 安装的
但我不明白如何为芹菜放入类似的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单元时,在日志中我看到芹菜应用程序启动了。几秒钟后,服务失败。
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有关。
有没有办法让芹菜应用程序与SCL和systemd一起工作?
Celery有一个命令行选项--detach。当您使用--detachCelery时,它会将工作进程作为后台进程启动。
这是工作的systemd单元文件:
[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=simple
RemainAfterExit=yes
RestartSec=10
Restart=always
Environment="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
LimitMEMLOCK=infinity
LimitNOFILE=20480
LimitNPROC=8192
# Main process
ExecStart=/usr/bin/scl enable rh-python36 -- /home/app/.local/bin/pipenv run celery -A celery_service.celery worker --detach
[Install]
WantedBy=multi-user.target