如何将 Django Celery 应用程序从 Elastic Beanstalk Amazon Linux 1 升级到 Amazon Linux 2

Hen*_*ryM 1 python linux django amazon-web-services django-celery

我正在尝试将运行 Celery 的 Django 应用程序从运行 Python 3.6 的 Amazon Elastic Beanstalk Linux 1 升级到使用 Python 3.8 的 Amazon Linux 2。

我在使用 Celery 应用程序时遇到问题。

在Linux 1中我有以下文件

#!/usr/bin/env bash

# Get django environment variables
celeryenv=`cat /opt/python/current/env | tr '\n' ',' | sed 's/export //g' | sed 's/$PATH/%(ENV_PATH)s/g' | sed 's/$PYTHONPATH//g' | sed 's/$LD_LIBRARY_PATH//g'`
celeryenv=${celeryenv%?}

# Create celery configuraiton script
celeryconf="[program:celeryd-worker]
; Set full path to celery program if using virtualenv
command=/opt/python/run/venv/bin/celery -A core worker -P solo --loglevel=INFO -n worker.%%h

directory=/opt/python/current/app/src
user=nobody
numprocs=1
stdout_logfile=/var/log/celery/worker.log
stderr_logfile=/var/log/celery/worker.log
autostart=true
autorestart=true
startsecs=10

; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600

; When resorting to send SIGKILL to the program to terminate it
; send SIGKILL to its whole process group instead,
; taking care of its children as well.
killasgroup=true

; if rabbitmq is supervised, set its priority higher
; so it starts first
priority=998

environment=$celeryenv
"

# Create the celery supervisord conf script
echo "$celeryconf" | tee /opt/python/etc/celery.conf

# Add configuration script to supervisord conf (if not there already)
if ! grep -Fxq "[include]" /opt/python/etc/supervisord.conf
  then
  echo "[include]" | tee -a /opt/python/etc/supervisord.conf
  echo "files: celery.conf" | tee -a /opt/python/etc/supervisord.conf
fi

# Reread the supervisord config
/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf reread

# Update supervisord in cache without restarting all services
/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf update

# Start/Restart celeryd through supervisord
/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf restart celeryd-worker
Run Code Online (Sandbox Code Playgroud)

我不确定程序在Linux 2中位于哪里,所以我修改了该文件如下:

#!/usr/bin/env bash

# Get django environment variables
celeryenv=`cat /var/app/current/env | tr '\n' ',' | sed 's/export //g' | sed 's/$PATH/%(ENV_PATH)s/g' | sed 's/$PYTHONPATH//g' | sed 's/$LD_LIBRARY_PATH//g'`
celeryenv=${celeryenv%?}

# Create celery configuraiton script
celeryconf="[program:celeryd-worker]
; Set full path to celery program if using virtualenv
command=celery -A core worker -P solo --loglevel=INFO -n worker.%%h

directory=/var/app/current/src
user=nobody
numprocs=1
stdout_logfile=/var/log/celery/worker.log
stderr_logfile=/var/log/celery/worker.log
autostart=true
autorestart=true
startsecs=10

; Need to wait for currently executing tasks to finish at shutdown.
; Increase this if you have very long running tasks.
stopwaitsecs = 600

; When resorting to send SIGKILL to the program to terminate it
; send SIGKILL to its whole process group instead,
; taking care of its children as well.
killasgroup=true

; if rabbitmq is supervised, set its priority higher
; so it starts first
priority=998

environment=$celeryenv
"

# Create the celery supervisord conf script
echo "$celeryconf" | tee /opt/python/etc/celery.conf

# Add configuration script to supervisord conf (if not there already)
if ! grep -Fxq "[include]" /opt/python/etc/supervisord.conf
  then
  echo "[include]" | tee -a /opt/python/etc/supervisord.conf
  echo "files: celery.conf" | tee -a /opt/python/etc/supervisord.conf
fi

# Reread the supervisord config
/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf reread

# Update supervisord in cache without restarting all services
/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf update

# Start/Restart celeryd through supervisord
/usr/local/bin/supervisorctl -c /opt/python/etc/supervisord.conf restart celeryd-worker
Run Code Online (Sandbox Code Playgroud)

我现在收到以下错误

2021/04/06 06:40:50.802882 [ERROR] An error occurred during execution of command [app-deploy] - [RunAppDeployPostDeployHooks]. Stop running the command. Error: Command .platform/hooks/postdeploy/03_celery-worker.sh failed with error exit status 127. Stderr:cat: /var/app/current/env: No such file or directory
tee: /opt/python/etc/celery.conf: No such file or directory
grep: /opt/python/etc/supervisord.conf: No such file or directory
tee: /opt/python/etc/supervisord.conf: No such file or directory
tee: /opt/python/etc/supervisord.conf: No such file or directory
.platform/hooks/postdeploy/03_celery-worker.sh: line 48: /usr/local/bin/supervisorctl: No such file or directory
.platform/hooks/postdeploy/03_celery-worker.sh: line 51: /usr/local/bin/supervisorctl: No such file or directory
.platform/hooks/postdeploy/03_celery-worker.sh: line 54: /usr/local/bin/supervisorctl: No such file or directory
Run Code Online (Sandbox Code Playgroud)

我环顾四周,找不到该文件现在应该如何构建。非常感谢帮助。

Vor*_*man 5

默认情况下,Amazon Linux2 中不存在主管。您只需重写此脚本即可在这样的系统的监督下运行 celery

`#!/usr/bin/env bash

# Create the celery systemd service file
echo "[Unit]
Name=Celery
Description=Celery service for My App
After=network.target
StartLimitInterval=0

[Service]
Type=simple
Restart=always
RestartSec=1
User=root
WorkingDirectory=/var/app/current
ExecStart=$PYTHONPATH/celery worker -A documerge --loglevel=INFO -n worker.%%h
EnvironmentFile=/opt/elasticbeanstalk/deployment/env

[Install]
WantedBy=multi-user.target
" | tee /etc/systemd/system/celery.service

# Start celery service
systemctl start celery.service

# Enable celery service to load on system start
systemctl enable celery.service`
Run Code Online (Sandbox Code Playgroud)