AWS弹性豆柄部署后脚本问题



在我的应用程序部署到AWS Elasticbeanstall后,我正在尝试运行芹菜工作者。

99_celery_start.sh

#!/usr/bin/env bash
#make dirs
sudo mkdir -p /usr/etc/
sudo chmod 755 /usr/etc/
sudo touch /usr/etc/celery.conf
sudo touch /usr/etc/supervisord.conf
# Get django environment variables
celeryenv=`cat /var/app/rootfolder/myprject/.env | tr 'n' ',' | sed 's/export //g' | sed 's/$PATH/%(ENV_PATH)s/g' | sed 's/$PYTHONPATH//g' | sed 's/$LD_LIBRARY_PATH//g' | sed 's/%/%%/g'`
celeryenv=${celeryenv%?}
# Create celery configuration script
celeryconf="[program:celery-worker]
user=root
directory=/var/app/rootfolder
; Set full path to celery program if using virtualenv
command=/var/app/venv/*/bin/celery -A myprject worker -P solo --loglevel=INFO        
.
.
.
.

芹菜.config

container_commands:
01_celery_configure:
command: "mkdir -p /.platform/hooks/postdeploy/ && cp .ebextensions/99_celery_start.sh /.platform/hooks/postdeploy/ && chmod 774 /.platform/hooks/postdeploy/99_celery_start.sh"
02_run_celery:
command: "sudo /.platform/hooks/postdeploy/99_celery_start.sh"

因此,我正在尝试将celener worker脚本复制到.eextension文件夹中,并将其粘贴到部署后挂钩文件夹中,以便在实例上部署应用程序后运行该脚本。但是,在提取应用程序并将其部署到实例上之前,正在执行命令02_run_celery。由于脚本需要应用程序文件夹/var/app/rootfolder/myprjct/.env,因此部署过程会出现错误cat:/var/app/rootfolder/myprjct/.ev:没有这样的文件或目录

如果您的假设是正确的,并且这是一个竞争条件(第二个命令在部署应用程序之前执行(,那么等待应用程序部署呢?或者等待你感兴趣的特定文件?

...
# Wait for the app deployment
while [ ! -f /var/app/rootfolder/myprject/.env ]
do
sleep 1
echo "Waiting for the application deployment"
done

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

如果有人还在寻找答案,那么我就是这样做的:

文件夹结构:

|-- .ebextensions/
|   |-- celery.config        # Option settings
|   `-- cloudwatch.config     # Other .ebextensions sections, for example files and container commands
`-- .platform/
|-- nginx/                # Proxy configuration
|   |-- nginx.conf
|   `-- conf.d/
|       `-- custom.conf
|-- hooks/                # Application deployment hooks
|   `-- postdeploy/
|       `-- 99_celery_start.sh

现在在celery.config:中添加99_celery_start.script的权限

01_celery_perm:
command: "sudo chmod +x .platform/hooks/postdeploy/99_celery_start.sh"
02_dos2unix:
command: "perl -i -pe's/r$//;' .platform/hooks/postdeploy/99_celery_start.sh"

重要信息:请确保脚本应保存为LF行结尾,而不是CRLF。

相关内容

  • 没有找到相关文章

最新更新