0

I am trying to deploy a simple NodeJS app to Azure App Service, I would like the app to run using PM2 with the option to configure multiple processes using PM2

I tried few options:

Option 1: with "start": "node index.js" in package.json, the app serves requests but does not run on PM2. No processes were running when I run PM2 list command in app service ssh console.

Although Azure docs indicate that the container automatically starts the app with PM2 when index.js file is in the root folder, this did not happen.

Option 2: with "start": "pm2 start --no-daemon index.js" in package.json, the app was started with PM2, only 1 process was running (confirmed this by running PM2 list command in app service ssh console).

How do I run multiple processes using pm2 ? on Azure App Service

Option 3: With the intention of running multiple processes, In addition to "start": "node index.js" in package.json, I also created a ecosystem.config file using pm2 init. I get this error

ERROR - Container test didn't respond to HTTP pings on port: 8080, failing site start

ecosystem.config file:

module.exports = {
  apps : [{
    script: 'index.js',
    watch: '.'
  }, {
    script: './service-worker/',
    watch: ['./service-worker']
  }],

  deploy : {
    production : {
      user : 'SSH_USERNAME',
      host : 'SSH_HOSTMACHINE',
      ref  : 'origin/master',
      repo : 'GIT_REPOSITORY',
      path : 'DESTINATION_PATH',
      'pre-deploy-local': '',
      'post-deploy' : 'npm install && pm2 reload ecosystem.config.js --env production',
      'pre-setup': ''
    }
  }
}; 

Package.JSON

{
  "name": "app-service-hello-world",
  "description": "Simple Hello World Node.js sample for Azure App Service",
  "version": "0.0.1",
  "private": true,
  "license": "MIT",
  "author": "Microsoft",
  "scripts": {
    "start": "node index.js"
  },
  "dependencies": {
    "dotenv": "^10.0.0"
  }
}

Index.js

const http = require("http");

const server = http.createServer((request, response) => {
  response.writeHead(200, { "Content-Type": "text/plain" });
  response.end("Hello World!");
});

const port = 8080;
server.listen(port);
SpaceX
  • 2,684
  • 2
  • 38
  • 62

1 Answers1

0

ERROR - Container test didn't respond to HTTP pings on port: 8080, failing site start

  • This is a limitation of the Azure Web App, it only supports to expose the port 80 and 443. So when you want to expose other ports such as 9000 and 8080, then you got the error that it didn't respond to HTTP pings on that port.

Change the code in index.js file to the below:

const port = process.env.port || 8080;

and redeploy to Azure.

  • If your container takes a long time to start you can increase the start time limit. The default time is 230 seconds for starting the container.
  • To configure , add an app setting called WEBSITES_CONTAINER_START_TIME_LIMIT and set it to the number of seconds you would like for us to wait for your container to start (up to a maximum of 1800) as shown in the image below:

41422-demo5.png

Please ensure that your container must respond to an HTTP ping and In order for us to consider a container to be successfully started, the container must start and it must respond to an HTTP ping. If the container starts but does not respond to a ping, we will eventually log an event in the Docker log saying that it didn't start.

To resolve this.

  • Use the EXPOSE instruction in your Dockerfile to expose port 3000.

  • Use the WEBSITES_PORT app setting with a value of "3000" to expose that port.

Please refer Your container must respond to an HTTP ping , this ,HTTP pings on port: 8080 and SO thread for more details.