azure应用程序服务容器(容器名称)未响应端口8080上的HTTP pings

问题描述 投票:0回答:1

我创建了一个非常简单的Discord机器人,并试图将其托管在Azure上。当我在本地运行它时,它工作正常。当我部署它时,它可以正常工作一段时间,然后崩溃并重新启动。

我得到


2020-03-23T21:41:50.738748919Z   _____
2020-03-23T21:41:50.738817719Z   /  _  \ __________ _________   ____
2020-03-23T21:41:50.738824419Z  /  /_\  \___   /  |  \_  __ \_/ __ \
2020-03-23T21:41:50.738828419Z /    |    \/    /|  |  /|  | \/\  ___/
2020-03-23T21:41:50.738832119Z \____|__  /_____ \____/ |__|    \___  >
2020-03-23T21:41:50.738836019Z         \/      \/                  \/
2020-03-23T21:41:50.738839619Z A P P   S E R V I C E   O N   L I N U X
2020-03-23T21:41:50.738843319Z
2020-03-23T21:41:50.738846719Z Documentation: http://aka.ms/webapp-linux
2020-03-23T21:41:50.738850119Z NodeJS quickstart: https://aka.ms/node-qs
2020-03-23T21:41:50.738853619Z NodeJS Version : v12.13.0
2020-03-23T21:41:50.738857019Z Note: Any data outside '/home' is not persisted
2020-03-23T21:41:50.738873019Z
2020-03-23T21:41:51.030040223Z Oryx Version: 0.2.20191105.2, Commit: 67e159d71419415435cb5d10c05a0f0758ee8809, ReleaseTagName: 20191105.2
2020-03-23T21:41:51.030978923Z Found build manifest file at '/home/site/wwwroot/oryx-manifest.toml'. Deserializing it...
2020-03-23T21:41:51.038540817Z Build Operation ID: |Nl1fjNBjXG0=.86fc023f_
2020-03-23T21:41:52.164947961Z Environment Variables for Application Insight's Codeless Configuration exists..
2020-03-23T21:41:52.165846260Z Writing output script to '/home/site/wwwroot/oryx-appinsightsloader.js'
2020-03-23T21:41:52.523126320Z Writing output script to '/opt/startup/startup.sh'
2020-03-23T21:41:52.729416182Z Running #!/bin/sh
2020-03-23T21:41:52.729893482Z
2020-03-23T21:41:52.729904682Z # Enter the source directory to make sure the script runs where the user expects
2020-03-23T21:41:52.729909382Z cd "/home/site/wwwroot"
2020-03-23T21:41:52.729913282Z
2020-03-23T21:41:52.729916782Z export NODE_PATH=$(npm root --quiet -g):$NODE_PATH
2020-03-23T21:41:52.729920482Z if [ -z "$PORT" ]; then
2020-03-23T21:41:52.730906381Z      export PORT=8080
2020-03-23T21:41:52.730917481Z fi
2020-03-23T21:41:52.730921481Z
2020-03-23T21:41:52.730925081Z echo Found tar.gz based node_modules.
2020-03-23T21:41:52.730928781Z extractionCommand="tar -xzf node_modules.tar.gz -C /node_modules"
2020-03-23T21:41:52.731720380Z echo "Removing existing modules directory from root..."
2020-03-23T21:41:52.731731380Z rm -fr /node_modules
2020-03-23T21:41:52.731735380Z mkdir -p /node_modules
2020-03-23T21:41:52.731738880Z echo Extracting modules...
2020-03-23T21:41:52.737901476Z $extractionCommand
2020-03-23T21:41:52.737914876Z export NODE_PATH="/node_modules":$NODE_PATH
2020-03-23T21:41:52.737919576Z export PATH=/node_modules/.bin:$PATH
2020-03-23T21:41:52.737931076Z if [ -d node_modules ] || [ -L node_modules ]; then
2020-03-23T21:41:52.737935076Z     mv -f node_modules _del_node_modules || true
2020-03-23T21:41:52.737938676Z fi
2020-03-23T21:41:52.738335276Z
2020-03-23T21:41:52.738348276Z if [ -d /node_modules ]; then
2020-03-23T21:41:52.738352876Z     ln -s /node_modules ./node_modules
2020-03-23T21:41:52.738356776Z fi
2020-03-23T21:41:52.738635876Z
2020-03-23T21:41:52.738700276Z echo "Done."
2020-03-23T21:41:52.738743776Z export NODE_OPTIONS='--require ./oryx-appinsightsloader.js ' $NODE_OPTIONS
2020-03-23T21:41:52.738885175Z npm start
2020-03-23T21:41:53.504769761Z Found tar.gz based node_modules.
2020-03-23T21:41:53.505139861Z Removing existing modules directory from root...
2020-03-23T21:41:53.515730254Z Extracting modules...
2020-03-23T21:41:53.800945462Z Done.
2020-03-23T21:41:55.412480180Z
2020-03-23T21:41:55.412504880Z > [email protected] start /home/site/wwwroot
2020-03-23T21:41:55.412521380Z > node stonksbot.js
2020-03-23T21:41:55.412525880Z
2020-03-23T21:41:56.623960067Z Logged in as Mr.Stonks#0654!
2020-03-23 21:45:42.618 ERROR - Container stonksbot1_0_0cecfd85 for site stonksbot1 did not start within expected time limit. Elapsed time = 231.774951 sec
2020-03-23 21:45:42.620 ERROR - Container stonksbot1_0_0cecfd85 didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2020-03-23 21:45:42.642 INFO  - Stoping site stonksbot1 because it failed during startup.

我没有设置docker,所以我猜azure正在为我做这件事。

我的包裹看起来像这样

{
  "name": "my-bot",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "start": "node stonksbot.js"
  },
  "dependencies": {
    "discord.js": "^11.6.3"
  },
  "devDependencies": {}
}

我的代码如下所示。

const Discord = require('discord.js');
const client = new Discord.Client();


client.login(my token);

client.on('ready', () => {
  console.log(`Logged in as ${client.user.tag}!`);
});

client.on('message', msg => {

  // do something
});

有人知道解决方案吗?

azure discord.js azure-web-app-service azure-app-service-plans
1个回答
0
投票

您需要让您的应用在指定的端口上响应来自Azure App Service的ping。

此处为示例:https://github.com/Azure-Samples/nodejs-docs-hello-world/blob/master/index.js

您还需要将环境变量WEBSITES_PORT设置为端口的值。

如果不响应ping,Azure会认为该应用程序已关闭并尝试重新启动它。

© www.soinside.com 2019 - 2024. All rights reserved.