gpt4 book ai didi

amazon-web-services - 将 Go 项目文件部署到 AWS Elastic Beanstalk 时 make.service 失败

转载 作者:行者123 更新时间:2023-12-01 22:20:47 27 4
gpt4 key购买 nike

过度开花,

为了将 Go 应用程序发布到 AWS Elastic Beanstalk,我已经苦苦挣扎了几个小时。

按照我最初认为非常简单的在线教程进行操作。

One of the tutorials i followed
Another one of the tutorials i followed

An examples which actually compiles on AWS for me

我现在的项目结构是:

以下文件都在我的根文件夹中:

application.go
build.sh
Buildfile
Procfile

应用程序.go

package main

import (
"github.com/gin-gonic/gin"
)

func main() {
router := gin.Default()

router.GET("/user/:name", func(c *gin.Context) {
name := c.Param("name")
c.String(http.StatusOK, "Hello %s", name)
})
router.Run(":5000")
}

build.sh

go get "github.com/gin-gonic/gin"    //Have tried without quotation marks

go build application.go

构建文件

make: ./build.sh

简介

web: bin/application

我还阅读了 AWS 上的文档 website .据我所知,我的代码以及上面提到的演示中的代码都是正确的。

我将根文件夹的全部内容压缩为一个 .zip 文件,并通过门户网站上传到 AWS。它失败了……在错误日志中我可以读到:

2020/08/28 23:17:38.902079 [INFO] Executing instruction: RunAppDeployPreBuildHooks
2020/08/28 23:17:38.902095 [INFO] The dir .platform/hooks/prebuild/ does not exist in the application. Skipping this step...
2020/08/28 23:17:38.902100 [INFO] Executing instruction: Golang Specific Build Application
2020/08/28 23:17:38.902104 [INFO] checking Buildfile...
2020/08/28 23:17:38.902110 [INFO] building Golang application with Buildfile
2020/08/28 23:17:38.902148 [INFO] Running command /bin/sh -c systemctl show -p PartOf make.service
2020/08/28 23:17:38.908345 [WARN] Warning: process make is already registered...
Deregistering the process ...
2020/08/28 23:17:38.908368 [INFO] Running command /bin/sh -c systemctl show -p PartOf make.service
2020/08/28 23:17:38.913626 [INFO] Running command /bin/sh -c systemctl is-active make.service
2020/08/28 23:17:38.916919 [INFO] Running command /bin/sh -c systemctl disable make.service
2020/08/28 23:17:39.002192 [INFO] Running command /bin/sh -c systemctl daemon-reload
2020/08/28 23:17:39.086778 [INFO] Running command /bin/sh -c systemctl reset-failed
2020/08/28 23:17:39.092606 [INFO] Running command /bin/sh -c systemctl daemon-reload
2020/08/28 23:17:39.166648 [INFO] Running command /bin/sh -c systemctl reset-failed
2020/08/28 23:17:39.170861 [INFO] Running command /bin/sh -c systemctl is-enabled eb-app.target
2020/08/28 23:17:39.174735 [INFO] Running command /bin/sh -c systemctl enable eb-app.target
2020/08/28 23:17:39.251327 [INFO] Running command /bin/sh -c systemctl start eb-app.target
2020/08/28 23:17:39.256334 [INFO] Running command /bin/sh -c systemctl enable make.service
2020/08/28 23:17:39.338502 [INFO] Running command /bin/sh -c systemctl show -p PartOf make.service
2020/08/28 23:17:39.344691 [INFO] Running command /bin/sh -c systemctl is-active make.service
2020/08/28 23:17:39.348280 [INFO] Running command /bin/sh -c systemctl start make.service
2020/08/28 23:17:39.358198 [ERROR] startProcess Failure: starting process "make" failed: Command /bin/sh -c systemctl start make.service failed with error exit status 1. Stderr:Job for make.service failed because the control process exited with error code. See "systemctl status make.service" and "journalctl -xe" for details.

2020/08/28 23:17:39.358222 [ERROR] An error occurred during execution of command [app-deploy] - [Golang Specific Build Application]. Stop running the command. Error: build application failed on command ./build.sh with error: startProcess Failure: starting process "make" failed: Command /bin/sh -c systemctl start make.service failed with error exit status 1. Stderr:Job for make.service failed because the control process exited with error code. See "systemctl status make.service" and "journalctl -xe" for details.

不幸的是,我对这种服务器配置或任何其他部署操作没有太多经验。所以我不明白“process make is already registered...”

...也许在这些领域更有经验的人可能知道该怎么做?

干杯!

注意:该项目一直可以在我的电脑上编译运行。当我尝试在 Elastic Beanstalk 上部署它时,它就失败了。

编辑:现在还尝试使用 AWS 命令​​行界面进行部署。在这种情况下,日志文件 eb-activity 告诉我:

Executing: HOME=/tmp /opt/elasticbeanstalk/lib/ruby/bin/ruby /opt/elasticbeanstalk/lib/ruby/bin/foreman start --procfile /tmp/d20200829-3130-13cz1sh/eb-buildtask-0 --root /var/app/staging --env /var/elasticbeanstalk/staging/elasticbeanstalk.env
/opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.2.0/gems/foreman-0.78.0/lib/foreman/process.rb:54:in `spawn': Permission denied - ./build.sh (Errno::EACCES)
from /opt/elasticbeanstalk/lib/ruby/lib/ruby/gems/2.2.0/gems/foreman-0.78.0/lib/foreman/process.rb:54:in `block in run'

AWS Management Console screenshot of my failed deploy

最佳答案

当 build.sh 脚本缺少可执行权限时,可能会发生这种情况。在这种情况下,beanstalk 上的“make.service”无法执行脚本并生成错误。

如果您在 unix 机器上开发,请在部署前尝试 chmod +x build.sh

如果您在 Windows 机器上进行开发,则无法设置 unix 文件属性。但是您可以将此技巧与 Buildfile 一起使用并以这种方式进行部署。

构建文件

make: chmod +x build.sh; ./build.sh

这将使 build.sh 在 make 服务运行时可执行。

关于amazon-web-services - 将 Go 项目文件部署到 AWS Elastic Beanstalk 时 make.service 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63642231/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com