go - 由于运行状况检查超时,BlueMix 未启动

标签 go ibm-cloud

我正在使用 Go 尝试使用 IBM 的 BlueMix 创建一个简单的“hello world”类脚本。我已经能够使用他们运行良好的 hello world 脚本,但是在编写我自己的脚本时却失败了。

我知道您需要获取端口的环境变量,这是我所做的,但是有了这个,检查仍然无法启动服务。

package main

import (
    "io"
    "net/http"
    "log"
    "os"
    "fmt"
)

const (
    DEFAULT_PORT = "4001"
    DEFAULT_HOST = "localhost"
)

func HelloServer(w http.ResponseWriter, req *http.Request) {
    io.WriteString(w, "hello, world!\n")
}

func main() {
    http.HandleFunc("/hello", HelloServer)

    var port string
    if port = os.Getenv("VCAP_APP_PORT"); len(port) == 0 {
        port = DEFAULT_PORT
    }

    var host string
    if host = os.Getenv("VCAP_APP_HOST"); len(host) == 0 {
        host = DEFAULT_HOST
    }


    log.Printf("Using host %v+\n", host)
    log.Printf("Using port %v+\n", port)
    fmt.Println("######" + port)

    err := http.ListenAndServe(host+":"+port, nil)
    if err != nil {
        log.Printf("ListenAndServe: ", err)
    }
}

非常感谢任何关于此程序失败原因的帮助。

-- 更新--

cf logs app --recent 的输出是:

2015-08-13T16:47:36.36+0100 [DEA/10]     OUT Removing crash for app with id ae803621-0b84-48d2-b3fd-6067053b40a6
2015-08-13T16:47:36.36+0100 [DEA/10]     OUT Stopping app instance (index 0) with guid ae803621-0b84-48d2-b3fd-6067053b40a6
2015-08-13T16:47:36.36+0100 [DEA/10]     OUT Stopped app instance (index 0) with guid ae803621-0b84-48d2-b3fd-6067053b40a6
2015-08-13T16:53:38.29+0100 [DEA/87]     OUT Starting app instance (index 0) with guid ae803621-0b84-48d2-b3fd-6067053b40a6
2015-08-13T16:54:02.13+0100 [DEA/87]     ERR Instance (index 0) failed to start accepting connections
2015-08-13T16:54:02.18+0100 [API/0]      OUT App instance exited with guid ae803621-0b84-48d2-b3fd-6067053b40a6 payload: {"cc_partition"=>"default", "droplet"=>"ae803621-0b84-48d2-b3fd-6067053b40a6", "version"=>"2ed88562-d12c-4391-ae8f-5fd8475cc350", "instance"=>"e4f99db81d194b1bb865a9e55f0a1d54", "index"=>0, "reason"=>"CRASHED", "exit_status"=>127, "exit_description"=>"failed to accept connections within health check timeout", "crash_timestamp"=>1439481242}
2015-08-13T16:54:02.21+0100 [API/10]     OUT App instance exited with guid ae803621-0b84-48d2-b3fd-6067053b40a6 payload: {"cc_partition"=>"default", "droplet"=>"ae803621-0b84-48d2-b3fd-6067053b40a6", "version"=>"2ed88562-d12c-4391-ae8f-5fd8475cc350", "instance"=>"e4f99db81d194b1bb865a9e55f0a1d54", "index"=>0, "reason"=>"CRASHED", "exit_status"=>127, "exit_description"=>"failed to accept connections within health check timeout", "crash_timestamp"=>1439481242}

最佳答案

上面我写的程序是正确的,可以正常运行。问题是 procfile 没有正确设置。 blueMix 在其示例 Go 程序中使用的 procfile 是 web:gohelloworld

gohelloworld 可以在 godeps/Godeps.json 文件中找到,作为 ImportPath 值。因此,在生成 godep 文件时,从 ImportPath 生成的值就是您应该放在 procfile 中的值。

在我的例子中,它应该是:web:test

关于go - 由于运行状况检查超时,BlueMix 未启动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31992564/

相关文章:

ibm-cloud - 为什么我无法解绑该服务?

mysql - Bluemix - 将 Mobilefirst 容器绑定(bind)到 Cloud Foundry 应用程序

go - 使用 go 模块后,IDE 无法跟踪我的代码

go - Go 中的错误解析时间,微秒数可变

pointers - 理解 Go 中的指针

javascript - XMLHttpRequest 无法加载 localhost 资源,安全检查是 Chrome

go - 竞赛检测器运行时错误

docker - Bluemix Docker Container cf ic ic无法登录本地Docker守护程序以进行认证

node.js - 使用测试数据库测试 Strongloop REST api

docker - Bluemix中缺少定制的docker镜像