[英]My Go server fails to start in cloud foundry
我有一個簡單的GO服務器,我正在嘗試將其推送到Bosh lite(“ Vagrant + Virtual”框)上的Cloud Foundry。
這是我的go應用程序中的源代碼設置:
〜/ workspace / src / github.com / me /(父目錄)
-神鷹
-weight weight.go <-主文件。
manifest.yml
程序文件
我的weight.go是一個簡單的服務器,可監聽9000。
1)manifest.yml看起來像這樣。
applications:
- name: weight
memory: 128MB
instances: 1
2)Procfile看起來像這樣。
worker: bin/weight
3)我使用默認的buildpack。
4)當我用cf push weight -c“ ./bin/weight;sleep 1d”推送我的應用程序時,我得到:
a-424e-b509-6df11fb32cc7 ({"state"=>"STOPPED"})
2016-03-13T11:02:45.70-0700 [DEA/0] OUT Got staging request for app with id 16d3795a-8cda-424e-b509-6df11fb32cc7
2016-03-13T11:02:46.84-0700 [API/0] OUT Updated app with guid 16d3795a-8cda-424e-b509-6df11fb32cc7 ({"state"=>"STARTED"})
2016-03-13T11:02:46.89-0700 [STG/0] OUT -----> Downloaded app package (12K)
2016-03-13T11:02:48.76-0700 [STG/0] OUT -----> Downloaded app buildpack cache (78M)
2016-03-13T11:02:48.82-0700 [STG/0] ERR Cloning into '/tmp/buildpacks/go-buildpack'...
2016-03-13T11:03:05.66-0700 [STG/0] OUT Submodule 'compile-extensions' (https://github.com/cloudfoundry/compile-extensions.git) registered for path 'compile-extensions'
2016-03-13T11:03:05.68-0700 [STG/0] ERR Cloning into 'compile-extensions'...
2016-03-13T11:03:07.59-0700 [STG/0] OUT Submodule path 'compile-extensions': checked out '26a578c06a62c763205833561fec1c5c6d34deb6'
2016-03-13T11:03:07.61-0700 [STG/0] OUT -------> Buildpack version 1.7.3
2016-03-13T11:03:09.81-0700 [STG/0] OUT https://pivotal-buildpacks.s3.amazonaws.com/concourse-binaries/godep/godep-v55-linux-x64.tgz
2016-03-13T11:03:09.88-0700 [STG/0] OUT -----> Checking Godeps/Godeps.json file.
2016-03-13T11:03:09.92-0700 [STG/0] OUT -----> Using go1.5.3
2016-03-13T11:03:09.92-0700 [STG/0] OUT -----> Running: godep go install -tags cloudfoundry .
2016-03-13T11:03:11.19-0700 [STG/0] OUT -----> Uploading droplet (2.0M)
2016-03-13T11:03:25.11-0700 [DEA/0] OUT Starting app instance (index 0) with guid 16d3795a-8cda-424e-b509-6df11fb32cc7
2016-03-13T11:03:34.93-0700 [DEA/0] OUT Removing crash for app with id 16d3795a-8cda-424e-b509-6df11fb32cc7
2016-03-13T11:03:34.93-0700 [DEA/0] OUT Stopping app instance (index 0) with guid 16d3795a-8cda-424e-b509-6df11fb32cc7
2016-03-13T11:03:34.93-0700 [DEA/0] OUT Stopped app instance (index 0) with guid 16d3795a-8cda-424e-b509-6df11fb32cc7
2016-03-13T11:03:56.81-0700 [DEA/0] OUT Starting app instance (index 0) with guid 16d3795a-8cda-424e-b509-6df11fb32cc7
**2016-03-13T11:03:57.79-0700 [DEA/0] ERR Instance (index 0) failed to start accepting connections**
2016-03-13T11:03:57.80-0700 [API/0] OUT App instance exited with guid 16d3795a-8cda-424e-b509-6df11fb32cc7 payload: {"cc_partition"=>"default", "droplet"=>"16d3795a-8cda-424e-b509-6df11fb32cc7", "version"=>"2eeebbf8-e84e-412a-aeba-2adc0cffea6b", "instance"=>"910eba711c6e414bb7c6324565d0a9af", "index"=>0, "reason"=>"CRASHED", "exit_status"=>127, "exit_description"=>"failed to accept connections within health check timeout", "crash_timestamp"=>1457892237}
我嘗試設置
cf set-env weight PORT 9000
沒有成功,我對清單和Yaml做些時髦的事情嗎?
weight.go在本地運行。
代碼:
func main (){
http.HandleFunc("/weight", weightHandler)
err:=http.ListenAndServe("localhost:"+getPort(), nil)
if err != nil {
fmt.Println("got an err ")
log.Fatalln(err)
}else{
fmt.Println("Apparently it works ?")
}
//fmt.Println("Hi")
//time.Sleep(1*time.Hour)
}
func getPort() string {
var port string
if port = os.Getenv("PORT"); len(port) == 0 {
fmt.Println("Didn't Found it")
fmt.Println(port)
port = DEFAULT_PORT
}else{
fmt.Println("Gotim")
fmt.Println(port)
}
return port
}
我確實獲得了隨機PORT CF分配的日志,仍然停留在
2016-03-13T16:58:40.90-0700 [API/0] OUT App instance exited with guid e5d417bd-c38d-4239-aa61-e9ca67fce79a payload: {"cc_partition"=>"default", "droplet"=>"e5d417bd-c38d-4239-aa61-e9ca67fce79a", "version"=>"8d7e80b3-69d5-4c83-9d37-1159d5deeba8", "instance"=>"14223d325c204406b87a131c065c16cc", "index"=>0, "reason"=>"CRASHED", "exit_status"=>-1, "exit_description"=>"failed to accept connections within health check timeout", "crash_timestamp"=>1457913520}
*已修復:問題是在本地主機上偵聽,我未指定IP,所以我很高興*
來自Cloud Foundry文檔中有關故障排除的信息:
確保您的應用程序代碼使用
PORT
環境變量。 您的應用程序可能由於在錯誤的端口上偵聽而失敗。 可以使用PORT
環境變量來代替對應用程序偵聽的端口進行硬編碼。 [ 來源 ]
來自Cloud Foundry文檔中有關環境變量的信息:
應用程序應在其上偵聽請求的端口。 Cloud Foundry運行時會為應用程序的每個實例動態分配一個端口,因此獲取或使用應用程序端口的代碼應通過PORT環境變量進行引用。 [ 來源 ]
因此,您的應用程序應該在PORT
環境變量指定的PORT
上進行偵聽,而不是硬編碼以偵聽端口9000,然后如果未設置該環境變量,則可以默認為9000。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.