Where to put Elastic Beanstalk config commands that are only run once on spin-up?

我的未来我决定 提交于 2019-11-29 16:50:51

问题


I know I can put commands in my source code in .ebextensions/*.config using the commands array. These are executed on every deploy however. What about if I want to execute a configuration command only once when spinning up a new instance?


回答1:


Commands can be run conditionally using the test: modifier. You specify a test to be done. If the test returns 0, the command is run, otherwise it is not.

If the last command in your config file touches a file, and the commands above that you only want to run once check for the existence of that file, then those commands will only run the first time.

commands:
  01-do-always:
    command: run_my_script
  02-do-on-boot:
    command: script_to_run_once
    test: test ! -f .semaphore
  99-signal-startup-complete:
    command: touch .semaphore

On Windows it would be something like this

commands:
  01-do-always:
    command: run_my_script
  02-do-on-boot:
    command: script_to_run_once
    test: if exists c:\\path\\to\\semaphore.txt (exit 0) else (exit 1)
  99-signal-startup-complete:
    command: date > c:\\path\\to\\semaphore.txt



回答2:


On Windows this should work:

commands:
  01-do-always:
    command: run_my_script
  02-do-on-boot:
    command: script_to_run_once
    test: cmd /c "if exist c:\\semaphore.txt (exit 1) else (exit 0)"
  99-signal-startup-complete:
    command: echo %date% %time% > c:\\semaphore.txt

Note that I had to change the test command from Jim Flanagan's answer.



来源:https://stackoverflow.com/questions/16827417/where-to-put-elastic-beanstalk-config-commands-that-are-only-run-once-on-spin-up

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!