Running script from .ebextensions folder in aws elastic bean glass

I try to run a script from the moment the war loads, so here is the contents of the 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" 

I tried everything, but deployment was always aborted when running setup.sh. In the above example, it does not work on 07_setup_script

Here is the contents of the magazine

 ] : 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) 

If ssh on the instances there is no folder or file there (/ home / dev) or (/home/dev/setup.sh), it seems that the previous commands were not executed, but the log says it is completed

I know there is a way to create a script file at runtime, but we can avoid this and just use the method described above.

0
source share
1 answer

A few questions. You should not start trying to manage your home directory / directory structure in general, which is definitely outside of the best beanstalk methods. Also do not perform actions like sudo, it performs hooks as root.

Do something like this:

in .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 

and

 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 
+2
source

Source: https://habr.com/ru/post/1241218/


All Articles