如何在ubuntu中将celery作为Daemon服务运行,而不是每次都运行“celery -A projname worker -l info
”命令。
我正在使用芹菜3.1.8版....
答案 0 :(得分:4)
您可以使用芹菜回购中的init.d script将芹菜变成守护进程(将其保存到/etc/init.d/
)。您还需要为/etc/default/celeryd
中的脚本创建configuration file。
这是完整的celery doc。
答案 1 :(得分:2)
您可以使用名为supervisord的工具将芹菜工作者作为守护程序。
这是一个简单的流程经理, 您可以找到有关如何使用supevisor配置文件配置工作人员的示例here。
答案 2 :(得分:0)
这是很久以前问过的一个问题,但我认为值得给出答案。
您可以按照以下步骤操作:
from fastapi import FastAPI, Response
app = FastAPI()
@app.post("/vector_image/")
async def image_endpoint():
# img = ... # Create the image here
return Response(content=img, media_type="image/png")
sudo adduser celery
并将celeryd和过去的内容复制到创建的sudo nano celeryd
中。
然后
celeryd
chmod +x celeryd
sudo mv celeryd /etc/init.d/
sudo touch /etc/default/celeryd
sudo vim /etc/default/celeryd
# Names of nodes to start
# most people will only start one node:
CELERYD_NODES="worker1"
# but you can also start multiple and configure settings
# for each in CELERYD_OPTS
#CELERYD_NODES="worker1 worker2 worker3"
# alternatively, you can specify the number of nodes to start:
#CELERYD_NODES=10
# Absolute or relative path to the 'celery' command:
#CELERY_BIN="/usr/local/bin/celery"
#CELERY_BIN="/virtualenvs/def/bin/celery"
CELERY_BIN="/opt/django_projects/your_proj/your_env/bin/celery"
# App instance to use
# comment out this line if you don't use an app
CELERY_APP="your_proj"
# or fully qualified:
#CELERY_APP="proj.tasks:app"
# Where to chdir at start.
CELERYD_CHDIR="/opt/django_projects/your_proj/"
# Extra command-line arguments to the worker
CELERYD_OPTS="--time-limit=300 --concurrency=8"
# Configure node-specific settings by appending node name to arguments:
#CELERYD_OPTS="--time-limit=300 -c 8 -c:worker2 4 -c:worker3 2 -Ofair:worker1"
# Set logging level to DEBUG
#CELERYD_LOG_LEVEL="DEBUG"
# %n will be replaced with the first part of the nodename.
CELERYD_LOG_FILE="/var/log/celery/%n%I.log"
CELERYD_PID_FILE="/var/run/celery/%n.pid"
# Workers should run as an unprivileged user.
# You need to create this user manually (or you can choose
# a user/group combination that already exists (e.g., nobody).
CELERYD_USER="celery"
CELERYD_GROUP="celery"
# If enabled pid and log directories will be created if missing,
# and owned by the userid/group configured.
CELERY_CREATE_DIRS=1
sudo mkdir /var/log/celery
sudo chown -R celery: /var/log/celery
sudo sh -x /etc/init.d/celeryd start
好吧,希望对您有所帮助。 谢谢。