我使用Go尝试使用IBM的BlueMix创建一个简单的hello world' -eque脚本。我已经能够使用他们的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}
答案 0 :(得分:1)
我写的上述程序是正确的,并按预期运行。问题是procfile没有正确设置。蓝色混搭在其示例中使用的proc文件是web: gohelloworld
。
gohelloworld
可以在godeps / Godeps.json文件中找到,作为ImportPath
值。因此,在生成godep文件时,ImportPath
生成的值是您应该放在procfile中的值。
就我而言,应该是:web: test
。