簡體   English   中英

node.js 應用程序與 pm2 在 Azure 應用程序服務失敗時容器不響應端口 8080 上的 ping

[英]node.js app with pm2 on Azure App Service fails when container doesn't respond to ping on port 8080

我嘗試使用以下啟動命令,並且都成功啟動了 _default_docker.log 中報告的應用程序,但應用程序服務正在停止容器,因為端口 8080 的 HTTP ping 沒有得到響應。

pm2 start ecosystem.config.js 
pm2 start npm -- run serve:ssr 4000

Ecosystem.config.js 文件 - 在本地運行良好,並在端口 8080 上成功啟動 web 應用程序,我已將文件上傳到應用程序服務中的 ./site/wwwroot/ 文件夾。

module.exports = {
  apps : [{
    name: 'ssrapp',
    script: './dist/server/',
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: '2G'
  }]
};

*_default_docker.log

2019-10-21T12:16:42.286884691Z   _____                               
2019-10-21T12:16:42.287028489Z   /  _  \ __________ _________   ____  
2019-10-21T12:16:42.287036989Z  /  /_\  \___   /  |  \_  __ \_/ __ \ 
2019-10-21T12:16:42.287041089Z /    |    \/    /|  |  /|  | \/\  ___/ 
2019-10-21T12:16:42.287044689Z \____|__  /_____ \____/ |__|    \___  >
2019-10-21T12:16:42.287048489Z         \/      \/                  \/ 
2019-10-21T12:16:42.287052189Z A P P   S E R V I C E   O N   L I N U X
2019-10-21T12:16:42.287055789Z 
2019-10-21T12:16:42.287059089Z Documentation: http://aka.ms/webapp-linux
2019-10-21T12:16:42.287062489Z NodeJS quickstart: https://aka.ms/node-qs
2019-10-21T12:16:42.287066089Z NodeJS Version : v10.16.3
2019-10-21T12:16:42.287069389Z 
2019-10-21T12:16:42.318934970Z /opt/startup/init_container.sh: line 32: [: ==: unary operator expected
2019-10-21T12:16:42.325006910Z Oryx Version : 0.2.20191004.5, Commit: 95ca7f51b147da7b085922507f46106c664ae2a3
2019-10-21T12:16:42.325022210Z 
2019-10-21T12:16:42.325252207Z Cound not find build manifest file at '/home/site/wwwroot/oryx-manifest.toml'
2019-10-21T12:16:42.325267707Z Could not find operation ID in manifest. Generating an operation id...
2019-10-21T12:16:42.325272707Z Build Operation ID: a7a4fff6-536c-41b1-a328-b01a6913948f
2019-10-21T12:16:43.023896728Z Writing output script to '/opt/startup/startup.sh'
2019-10-21T12:16:43.026999997Z Running #!/bin/sh
2019-10-21T12:16:43.027017997Z 
2019-10-21T12:16:43.027023796Z # Enter the source directory to make sure the script runs where the user expects
2019-10-21T12:16:43.027028696Z cd "/home/site/wwwroot"
2019-10-21T12:16:43.027033196Z 
2019-10-21T12:16:43.027037496Z export NODE_PATH=$(npm root --quiet -g):$NODE_PATH
2019-10-21T12:16:43.027041996Z if [ -z "$PORT" ]; then
2019-10-21T12:16:43.027046596Z      export PORT=8080
2019-10-21T12:16:43.027051196Z fi
2019-10-21T12:16:43.027055496Z 
2019-10-21T12:16:43.027059696Z PATH="$PATH:/home/site/wwwroot" pm2 start npm -- run serve:ssr 8080
2019-10-21T12:16:43.988819791Z 
2019-10-21T12:16:43.988873290Z                         -------------
2019-10-21T12:16:43.988899590Z 
2019-10-21T12:16:43.988903390Z __/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\_____
2019-10-21T12:16:43.988925889Z  _\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\___
2019-10-21T12:16:43.988931389Z   _\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\__
2019-10-21T12:16:43.988936189Z    _\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/___
2019-10-21T12:16:43.988949489Z     _\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//_____
2019-10-21T12:16:43.988954289Z      _\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//________
2019-10-21T12:16:43.988976389Z       _\/\\\_____________\/\\\_____________\/\\\___/\\\/___________
2019-10-21T12:16:43.988980789Z        _\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\_
2019-10-21T12:16:43.988985089Z         _\///______________\///______________\///__\///////////////__
2019-10-21T12:16:43.988989589Z 
2019-10-21T12:16:43.988993489Z 
2019-10-21T12:16:43.989001189Z                           Runtime Edition
2019-10-21T12:16:43.989005689Z 
2019-10-21T12:16:43.989009989Z         PM2 is a Production Process Manager for Node.js applications
2019-10-21T12:16:43.989033588Z                      with a built-in Load Balancer.
2019-10-21T12:16:43.989037688Z 
2019-10-21T12:16:43.989062588Z                 Start and Daemonize any application:
2019-10-21T12:16:43.989066588Z                 $ pm2 start app.js
2019-10-21T12:16:43.989070588Z 
2019-10-21T12:16:43.989074388Z                 Load Balance 4 instances of api.js:
2019-10-21T12:16:43.989078288Z                 $ pm2 start api.js -i 4
2019-10-21T12:16:43.989082188Z 
2019-10-21T12:16:43.989085988Z                 Monitor in production:
2019-10-21T12:16:43.989089888Z                 $ pm2 monitor
2019-10-21T12:16:43.989093788Z 
2019-10-21T12:16:43.989097588Z                 Make pm2 auto-boot at server restart:
2019-10-21T12:16:43.989101488Z                 $ pm2 startup
2019-10-21T12:16:43.989105388Z 
2019-10-21T12:16:43.989109388Z                 To go further checkout:
2019-10-21T12:16:43.989113288Z                 http://pm2.io/
2019-10-21T12:16:43.989117188Z 
2019-10-21T12:16:43.989120988Z 
2019-10-21T12:16:43.989124787Z                         -------------
2019-10-21T12:16:43.989128687Z 
2019-10-21T12:16:44.101458966Z [PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
2019-10-21T12:16:44.680135188Z [PM2] PM2 Successfully daemonized
2019-10-21T12:16:44.725026740Z [PM2] Starting /usr/local/bin/npm in fork_mode (1 instance)
2019-10-21T12:16:44.741207478Z [PM2] Done.
2019-10-21T12:16:44.762611464Z ┌──────────┬────┬─────────┬──────┬─────┬────────┬─────────┬────────┬─────┬───────────┬──────┬──────────┐
2019-10-21T12:16:44.762636964Z │ App name │ id │ version │ mode │ pid │ status │ restart │ uptime │ cpu │ mem       │ user │ watching │
2019-10-21T12:16:44.762650664Z ├──────────┼────┼─────────┼──────┼─────┼────────┼─────────┼────────┼─────┼───────────┼──────┼──────────┤
2019-10-21T12:16:44.762656664Z │ npm      │ 0  │ N/A     │ fork │ 82  │ online │ 0       │ 0s     │ 0%  │ 23.4 MB   │ root │ disabled │
2019-10-21T12:16:44.762661564Z └──────────┴────┴─────────┴──────┴─────┴────────┴─────────┴────────┴─────┴───────────┴──────┴──────────┘
2019-10-21T12:16:44.763132159Z  Use `pm2 show <id|name>` to get more details about an app

*_docker.log

2019-10-21 12:16:42.471 INFO  - Starting container for site
2019-10-21 12:16:42.471 INFO  - docker run -d -p 44692:8081 --name mgssrtest__5706_0_5312eaa2_middleware -e WEBSITE_NODE_DEFAULT_VERSION=6.9.1 -e APPSETTING_WEBSITE_NODE_DEFAULT_VERSION=6.9.1 -e WEBSITE_CORS_ALLOWED_ORIGINS=https://uatservices.micksgarage.com,https://devtestservices.micksgarage.com,https://liveservices.micksgarage.com,https://www.micksgarage.com,https://mgssrlive.micksgarage.com,https://mgssrtest.micksgarage.com -e WEBSITE_CORS_SUPPORT_CREDENTIALS=False -e PORT=8080 -e WEBSITES_PORT=8080 -e WEBSITE_SITE_NAME=mgssrtest -e WEBSITE_AUTH_ENABLED=False -e WEBSITE_ROLE_INSTANCE_ID=0 -e WEBSITE_HOSTNAME=mgssrtest-live.azurewebsites.net -e WEBSITE_INSTANCE_ID=3952e083f9a0d4ead164e4cdd951561b6d2f3f64a50759e4377a1dd32b4aa296 -e HTTP_LOGGING_ENABLED=1 appsvc/middleware:1907112318 /Host.ListenUrl=http://0.0.0.0:8081 /Host.DestinationHostUrl=http://172.16.6.2:8080 /Host.UseFileLogging=true 

2019-10-21 12:16:43.116 INFO  - Initiating warmup request to container mgssrtest__5706_0_5312eaa2 for site mgssrtest__5706
2019-10-21 12:16:45.135 ERROR - Container mgssrtest__5706_0_5312eaa2 for site mgssrtest__5706 has exited, failing site start
2019-10-21 12:16:45.135 INFO  - Initiating warmup request to container mgssrtest__5706_0_5312eaa2_middleware for site mgssrtest__5706
2019-10-21 12:16:48.471 INFO  - Container mgssrtest__5706_0_5312eaa2_middleware for site mgssrtest__5706 initialized successfully and is ready to serve requests.
2019-10-21 12:16:48.478 ERROR - Container mgssrtest__5706_0_5312eaa2 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.

我曾嘗試在 App Service Application Settings 中設置以下設置(有關這些設置的文檔很難獲得且相互矛盾),但它們似乎沒有任何區別:

端口:8080

網站端口:8080

CONTAINER_AVAILABILITY_CHECK_MODE:僅報告

WEBSITES_CONTAINER_START_TIME_LIMIT:1800

注意:節點應用程序使用啟動命令“npm run serve:ssr”在應用服務中啟動正常,但我想通過 pm2 啟動它以利用監控和重啟功能。

看起來應用服務環境正在停止容器,因為它在 5 秒內沒有響應 HTTP ping,但我找不到任何方法來禁用它以確認這是實際問題。

您的docker run命令未公開端口 8080。您只有容器端口 44692 公開為端口 8081。您可以在日志中將其視為-p 44692:8081

嘗試將此添加到 docker 運行命令行:

-p 8080:8080

如果這不起作用,請嘗試-p 8080:8081 ,甚至只是-p 8080

下面評論中的建築師 Jamie建議解決了這個問題,需要 --no-daemon 參數。 謝謝!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM