阅读背景:

部署AWS Beanstalk后执行命令

来源:互联网 

I have problem with execute command after deploy, i have some node.js project and script, this script use some bin from node_modules, if i write my command for script in .ebextensions/.config he execute before npm install and return error ("node_modules/.bin/some": No such file or directory). How i can execute command after deploy. Thanks.

我有部署后执行命令的问题,我有一些node.js项目和脚本,这个脚本使用来自node_modules的一些bin,如果我在.ebextensions / .config中编写我的脚本命令,他会在npm install之前执行并返回错误(“ node_modules / .bin / some“:没有这样的文件或目录)。我如何在部署后执行命令。谢谢。

3 个解决方案

#1


9  

I found the following solution

我找到了以下解决方案

I add to beanstalk config next command:

我添加到beanstalk config next命令:

commands:
  create_post_dir:
    command: "mkdir /opt/elasticbeanstalk/hooks/appdeploy/post"
    ignoreErrors: true
files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/some_job.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      cd /var/app/current
      export PATH=$PATH:$(ls -td /opt/elasticbeanstalk/node-install/node-* | head -1)/bin
      npm run some_script

This commands create(if not exist) folder for post-hooks scripts and adds bash script. Scripts in this folders execute only after npm install, this very important for my problem.

此命令为post-hooks脚本创建(如果不存在)文件夹并添加bash脚本。此文件夹中的脚本仅在安装npm后执行,这对我的问题非常重要。

Thanks to this guy https://junkheap.net/blog/2013/05/20/elastic-beanstalk-post-deployment-scripts/

感谢这个家伙https://junkheap.net/blog/2013/05/20/elastic-beanstalk-post-deployment-scripts/

#2


1  

create a file called .ebextensions/post_actions.config:

创建一个名为.ebextensions / post_actions.config的文件:

container_commands:
 <name of container_command>:
    command: "<command to run>"

this will be executed after the code was extracted, but before it was launched.

这将在提取代码之后但在启动之前执行。

#3


-1  

If you read the AWS ebextensions documentation they mention the execution, specifically where they mention that all commands are executed before the application version is deployed.

如果您阅读AWS ebextensions文档,他们会提到执行,特别是在他们提到在部署应用程序版本之前执行所有命令的情况下。

"You can use the container_commands key to execute commands for your container. The commands in container_commands are processed in alphabetical order by name. They run after the application and web server have been set up and the application version file has been extracted, but before the application version is deployed."

“您可以使用container_commands键来执行容器的命令.container_commands中的命令按名称的字母顺序处理。它们在应用程序和Web服务器设置完毕后运行,并且应用程序版本文件已被提取,但在部署了应用程序版本。“

If you deploy it for a second time it should work; this is because your application is already unpacked. This however is not a working solution because every new instance that is spawned will error.

如果你再次部署它应该工作;这是因为您的应用程序已经解压缩。然而,这不是一个有效的解决方案,因为每个生成的新实例都会出错。


分享到: