在AWS Elastic Beanstalk中从.ebextensions文件夹运行脚本 [英] Running a script from .ebextensions folder in aws elastic beanstalk
问题描述
我正在尝试从上载战争开始运行脚本,所以这是配置的内容
I am trying to run a script from when war is uploaded so here is the contents of configurations
container_commands:
01_setup_apache:
command: "cp .ebextensions/enable_mod_deflate.conf /etc/httpd/conf.d/enable_mod_deflate.conf"
02_setup_script:
command: "sudo su root"
03_setup_script:
command: "sudo mkdir -p /home/dev"
04_setup_script:
command: "sudo chmod 777 /home/dev -R"
05_setup_script:
command: "sudo cp .ebextensions/scripts/setup.sh /home/dev/"
06_setup_script:
command: "sudo chmod +x /home/dev/setup.sh"
07_setup_script:
command: "sudo /home/dev/setup.sh"
08-restart-apache:
command: "sudo /etc/init.d/httpd restart"
我尝试了所有事情,但是部署总是在执行setup.sh时失败.在上面的示例中,它在 07_setup_script
I tried every thing but deployment always fail on executing setup.sh. In above example it fails on 07_setup_script
这是日志内容
] : Starting activity...
/Command 01_setup_apache] : Starting activity...
/Command 01_setup_apache] : Completed activity.
/Command 02_setup_script] : Starting activity...
/Command 02_setup_script] : Completed activity.
/Command 03_setup_script] : Starting activity...
/Command 03_setup_script] : Completed activity.
/Command 04_setup_script] : Starting activity...
/Command 04_setup_script] : Completed activity.
/Command 05_setup_script] : Starting activity...
/Command 05_setup_script] : Completed activity.
/Command 06_setup_script] : Starting activity...
/Command 06_setup_script] : Completed activity.
/Command 07_setup_script] : Starting activity...
/Command 07_setup_script] : Activity execution failed, because: sudo: unable to execute /home/dev/setup.sh: No such file or directory
(ElasticBeanstalk::ExternalInvocationError)
如果实例上的 ssh 那里没有文件夹或文件(/home/dev)或(/home/dev/setup.sh),则似乎先前的命令未执行,但日志显示其完成
If ssh on instances there is no folder or file over there (/home/dev) or ( /home/dev/setup.sh) it seems previous commands were not executed but log says its completed
我知道有一种在运行时创建脚本文件的方法,但是我们可以避免这种情况,仅使用上述方法即可.
I know there is way to create a script file on run time, but can we avoid that and just use the above method.
推荐答案
几个问题.您根本不应该开始尝试管理主目录/目录结构,这绝对不是beantalk最佳实践的范围.同样不要以sudo的身份运行事物,它会以root身份执行钩子.
A couple of issues. You shouldn't start trying to manage a home directory/directory structure at all, that's definitely outside of beanstalk best-practices. Also don't run things as sudo, it executes hooks as root.
执行以下操作:
在.ebextension/foo.config
中:
container_commands:
01_restart_httpd:
command: /etc/init.d/httpd restart
files:
/etc/httpd/conf.d/enable_mod_deflate.conf:
mode: "000644"
owner: root
group: root
content: |
#content of your conf
或者也是
files:
/etc/httpd/conf.d/enable_mod_deflate.conf:
mode: "000644"
owner: root
group: root
content: |
#content of your conf
/opt/elasticbeanstalk/hooks/appdeploy/post/50_restart_httpd:
mode: "000777"
owner: root
group: root
content: |
#!/bin/sh
/etc/init.d/httpd restart
这篇关于在AWS Elastic Beanstalk中从.ebextensions文件夹运行脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!