英文:
BlueMix not starting due to health check timeout
问题
我正在使用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}
帮助解决这个程序失败的原因将不胜感激。
英文:
I'm using Go to try create a simple 'hello world'-eque script using IBM's BlueMix. I've been able to use their hello world script which runs fine, however upon writing my own it fails.
I'm aware that you need to take the environment variable for the port, which is what I've done, however with this in place, the check is still unable to start the service.
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)
}
}
Any help as to why this program is failing is greatly appreciated.
-- update --
The output of cf logs app --recent
is:
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}
答案1
得分: 1
我写的上述程序是正确的,并按照预期运行。问题在于procfile没有正确设置。blueMix在其示例Go程序中使用的procfile是web: gohelloworld
。
gohelloworld
可以在godeps/Godeps.json文件中找到,作为ImportPath
的值。因此,在生成godep文件时,从ImportPath
生成的值是应该放在procfile中的值。
在我的情况下,应该是:web: test
。
英文:
The above program I wrote is correct and runs as it should. The issue was that the procfile was not correctly set up. The procfile blueMix uses in its example Go program is web: gohelloworld
.
gohelloworld
can be found in the godeps/Godeps.json file, as the ImportPath
value. So when generating your godep file, the generated value from ImportPath
is the value you should place in your procfile.
In my case, it should have been: web: test
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论