我知道我可以使用commands
数组在.ebextensions/*.config文件中将命令放入我的源代码中。 然而,这些在每次部署时都会执行。 如果我想在启动新实例时仅执行一次配置命令怎么办?
我知道我可以使用commands
数组在.ebextensions/*.config文件中将命令放入我的源代码中。 然而,这些在每次部署时都会执行。 如果我想在启动新实例时仅执行一次配置命令怎么办?
使用test:
修饰符可以有条件地运行命令。您需要指定要执行的测试。如果测试返回0,则运行命令,否则不执行。
如果您配置文件中的最后一个命令触及到一个文件,并且在该命令上方的其他命令只想运行一次并检查该文件是否存在,则这些命令仅会在第一次运行。
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
在Windows上,它可能是这样的。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
在Windows上应该可以这样做:
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
test
命令。
leader-only
仅在目标组中的一个实例上执行命令。这里的问题是要在每个实例上执行一次命令,但仅限一次。 - Manuel.semaphore
对我来说不起作用,我认为当前目录是临时部署目录,每次部署都会被清除。使用不同的目录可以解决这个问题,我决定使用/var/elasticbeanstalk/...
。 - Manuel