我正在尝试从上传war时运行脚本,所以这里是配置的内容
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
上失败这是日志内容
] : 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),似乎以前的命令没有被执行但是日志说它的完成
我知道有办法在运行时创建一个脚本文件,但是我们可以避免这种情况,只需使用上面的方法即可。
答案 0 :(得分:3)
有几个问题。您根本不应该开始尝试管理主目录/目录结构,这绝对不是beanstalk最佳实践。也不要像sudo一样运行它,它以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