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

时间:2019-11-11 12:10:18

标签: linux bash amazon-ec2 aws-code-deploy

我正在尝试将代码从GitHub部署到AWS Amazon中的CodeDeploy。 我有示例HelloWorld应用程序。我有如下所示的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

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

位于指定位置的脚本:以用户ec2-user身份运行的start.sh失败,退出代码为127 日志 LifecycleEvent-ApplicationStart 脚本-start.sh [stderr] / usr / bin / env:bash:没有这样的文件或目录

请有人可以帮助我

1 个答案:

答案 0 :(得分:0)

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

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