我有一個簡單的 GO 服務(wù)器,我試圖將它推送到 Bosh lite(Vagrant + Virtual box)上的云代工廠。這是我的 go 應(yīng)用程序的源代碼設(shè)置:~/workspace/src/github.com/me/(父目錄)-Godeps-weight weight.go <-- 主文件。清單文件.yml配置文件我的 weight.go 是一個簡單的服務(wù)器,可以監(jiān)聽 9000。1) manifest.yml 看起來像這樣。applications:- name: weight memory: 128MB instances: 12 ) Procfile 看起來像這樣。worker: bin/weight3)我使用默認(rèn)的buildpack。4 ) 當(dāng)我用 cf push weight -c "./bin/weight;sleep 1d" 推送我的應(yīng)用程序時,我得到:我試過設(shè)置cf set-env weight PORT 9000沒有成功,我是不是在用 manifest 和 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}我確實得到了隨機(jī) 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}*已修復(fù):問題是在本地主機(jī)上偵聽,我沒有指定 IP,我很高興 *
1 回答

慕容3067478
TA貢獻(xiàn)1773條經(jīng)驗 獲得超3個贊
來自關(guān)于故障排除的 Cloud Foundry 文檔:
確保您的應(yīng)用程序代碼使用
PORT
環(huán)境變量。您的應(yīng)用程序可能會失敗,因為它正在偵聽錯誤的端口。不要對應(yīng)用程序偵聽的端口進(jìn)行硬編碼,而是使用PORT
環(huán)境變量。[來源]
來自關(guān)于環(huán)境變量的 Cloud Foundry 文檔:
應(yīng)用程序應(yīng)在其上偵聽請求的端口。Cloud Foundry 運行時為應(yīng)用程序的每個實例動態(tài)分配一個端口,因此獲取或使用應(yīng)用程序端口的代碼應(yīng)通過 PORT 環(huán)境變量引用它。[來源]
因此,與其將您的應(yīng)用程序硬編碼為偵聽端口 9000,它應(yīng)該偵聽PORT
環(huán)境變量指定的端口,如果未設(shè)置該環(huán)境變量,則可以默認(rèn)為 9000。
- 1 回答
- 0 關(guān)注
- 207 瀏覽
添加回答
舉報
0/150
提交
取消