在指定位置部署脚本失败:start.sh 运行 作为用户 ec2-user 失败,退出代码为 127

Deployment failed-Script at specified location: start.sh run as user ec2-user failed with exit code 127

我正在尝试将代码从 GitHub 部署到 AWS Amazon 中的 CodeDeploy。 我有示例 HelloWorld application.I 有 appspec.yml 看起来像这样:

os: linux

files:
  - source: /
    destination: /home/ec2-user/server

permissions:
  - object: /
    pattern: "**"
    owner: ec2-user
    group: ec2-user

hooks:
  ApplicationStop:
    - location: stop.sh
      timeout: 20
      runas: ec2-user
  ApplicationStart:
    - location: start.sh
      timeout: 20
      runas: ec2-user
  ValidateService:
    - location: validate.sh
      timeout: 120
      runas: ec2-user

和buldspec.yml:


phases:
  install:
    runtime-versions:
      java: openjdk8
  build:
    commands:
      - mvn clean package --quiet
artifacts:
  discard-paths: yes
  files:
    - target/*
    - scripts/*
    - appspec.yml

start.sh



cd /home/ec2-user/server
sudo /usr/bin/java -jar -Dserver.port=80 \
    *.jar > /dev/null 2> /dev/null < /dev/null &

stop.sh:


#!/usr/bin/env bash

sudo killall java
exit 0

和validate.sh:

#!/bin/bash

echo "Waiting for 15 seconds before checking health.."
sleep 15

status_code=$(curl --write-out %{http_code} --silent --output /dev/null http://localhost:80)
if [[ "$status_code" -ne 200 ]] ; then
  echo "App is not healthy - $status_code"
  exit 1
else
  echo "App is responding with $status_code"
  exit 0
fi

我的部署失败,错误提示:

指定位置的脚本:start.sh 运行 作为用户 ec2-user 失败,退出代码为 127 日志 生命周期事件 - ApplicationStart 脚本 - start.sh [stderr]/usr/bin/env: bash : 没有那个文件或目录

有人能帮帮我吗

您似乎在 appspec.yml 中提到了 start.sh 的错误路径。它正在尝试在根路径中查找脚本。由于您的脚本位于 "scripts" 文件夹中,因此您必须像下面那样提及它。

os: linux

files:
  - source: /
    destination: /home/ec2-user/server

permissions:
  - object: /
    pattern: "**"
    owner: ec2-user
    group: ec2-user

hooks:
  ApplicationStop:
    - location: scripts/stop.sh
      timeout: 20
      runas: ec2-user
  ApplicationStart:
    - location: scripts/start.sh
      timeout: 20
      runas: ec2-user
  ValidateService:
    - location: scripts/validate.sh
      timeout: 120
      runas: ec2-user