AWS编码器未运行挂钩脚本

发布于 2025-01-21 17:12:13 字数 965 浏览 4 评论 0原文

我正在学习如何使用Codepipeline并在小型测试节点应用程序中遇到CodeDeploy的问题。我的目标是实现大型Express + React应用程序的CD,我需要使用AppSpec.yml的钩子。 目前,其他所有内容都在起作用,复制文件等,它只是没有触发脚本。我从启动之前(从pm2删除进程)和applicationstart(使用pm2启动应用程序)挂钩开始,但是现在我切换到使用脚本使用applicationstart将其从pm2中删除PM2,以查看它是否有效。

我的appspec.yml:

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ubuntu/api
permissions:
  - object: /home/ubuntu/api/
    owner: ubuntu
    group: ubuntu
    mode: "777"
# I use appStop.sh just to check if this works:
ApplicationStart:
  - location: scripts/appStop.sh
    runas: ubuntu
# I tried also running as root, still nothing
    timeout: 60

appstop.sh:

#!/bin/bash
cd /home/ubuntu/api
pm2 delete 0

我尝试了很多事情,也将所有内容都作为根(尽管我更喜欢使用ubuntu用户)。

在/var/log/aws/codedeploy-agent中,日志文件中没有错误。

我还可以在Revieev中看到所有文件和脚本DIR/opt/opt/codedeploy-agent/deployment-root/...

当我在家中手动运行appstop脚本时,我可以正常工作。 看起来编码eploy代理只是没有运行脚本。

I'm learning how to use CodePipeline and have problem with CodeDeploy for small testing node app. My target is to implement CD for large express + react app and I need to use hooks from AppSpec.yml.
For now everything else is working, files are copied etc, it just doesn't fire script. I started with BeforeInstall (delete process from pm2) and ApplicationStart (start app with pm2) hooks, but now I switched to using ApplicationStart with script to remove process from pm2 just to see if it works.

My AppSpec.yml:

version: 0.0
os: linux
files:
  - source: /
    destination: /home/ubuntu/api
permissions:
  - object: /home/ubuntu/api/
    owner: ubuntu
    group: ubuntu
    mode: "777"
# I use appStop.sh just to check if this works:
ApplicationStart:
  - location: scripts/appStop.sh
    runas: ubuntu
# I tried also running as root, still nothing
    timeout: 60

appStop.sh:

#!/bin/bash
cd /home/ubuntu/api
pm2 delete 0

I tried many things, also running everything as root (though I prefer to use ubuntu user).

There are no ERRORs in log file in /var/log/aws/codedeploy-agent.

I can also see all files and scripts dir in reviev in /opt/codedeploy-agent/deployment-root/...

When I manually run appStop script in home dir it works.
It looks like CodeDeploy agent is just not running script.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生活了然无味 2025-01-28 17:12:13

好的,看来我使它起作用。
首先,我通过删除/opt/opt/deployment-root/< exployment droup id> dir and /opt/opt/deployment-root/deployment-instructions

也 清洁了编码EPLOY-ADENT数据更改了位置,不知道这是否有帮助,但是必须这样做,因为我决定与Root用户一起使事情变得更容易。应用程序现在在/var/www/api中。

我还使用sudo

my working appspec.yml:

version: 0.0
os: linux

files:
  - source: /
    destination: /var/www/api

permissions:
  - object: /var/www/api/
    mode: 775
    type:
      - file
      - directory
hooks:
  ApplicationStop:
    - location: scripts/appStop.sh
      runas: root
  ApplicationStart:
    - location: scripts/appStart.sh
      runas: root

and working scripts:

appstop.sh:

#!/bin/bash
cd /var/www/api
sudo pm2 delete 0

appstart.sh:

#!/bin/bash
cd /var/www/api
sudo pm2 start server.js

Ok it seems I made it work.
First I cleaned codedeploy-agent data by removing /opt/deployment-root/<deployment droup id> dir and /opt/deployment-root/deployment-instructions

I also changed location, don't know if this helped, but had to do it since I decided to go with root user to make things easier. App is now in /var/www/api.

I also reinstalled all js software (node, pm2, npm) using sudo

My working AppSpec.yml:

version: 0.0
os: linux

files:
  - source: /
    destination: /var/www/api

permissions:
  - object: /var/www/api/
    mode: 775
    type:
      - file
      - directory
hooks:
  ApplicationStop:
    - location: scripts/appStop.sh
      runas: root
  ApplicationStart:
    - location: scripts/appStart.sh
      runas: root

and working scripts:

appStop.sh:

#!/bin/bash
cd /var/www/api
sudo pm2 delete 0

appStart.sh:

#!/bin/bash
cd /var/www/api
sudo pm2 start server.js
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文