使用经典的azure管道在Windows服务器上运行PM2

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

我正在尝试使用经典的azure管道为nextjs项目构建发布管道,以将其部署在自托管Windows服务器上,并且我使用iis作为nextjs应用程序的重定向服务器,我的问题是如何保持nextjs应用程序运行以启用重定向从 iis 到它?

  • 我在 CMD 中尝试了 npm run start ,它使发布管道保持运行
  • 我尝试了iisnode,它导致错误
  • 我尝试使用 PM2/ PM2-runtime,它使发布管道保持运行状态。

我使用过的任务

 steps:
    - task: NodeTool@0
      displayName: 'Use Node 20.x'
      inputs:
        versionSpec: 20.x
    steps:
- powershell: |
   npm i
  workingDirectory: 'some directory'
  displayName: 'npm i'

steps:
- powershell: |
   npm install pm2 -g
   
  workingDirectory: 'some directory'
  displayName: 'npm install pm2 -g'

steps:
- powershell: 'pm2-runtime start ecosystem.config.js --env production'
  workingDirectory: 'some directory'
  displayName: 'pm2-runtime start ecosystem.config.js --env production'
  env:
    HOME: ~
node.js windows next.js azure-devops pm2
1个回答
0
投票

使用相同的 pm2-runtime start 命令时,我可以重现相同的情况。

管道将在应用程序启动后继续运行。

据我所知,pm2-runtime是为Docker容器设计的,它将应用程序保留在前台以保持容器运行,

pm2 专为正常使用而设计,您可以在后台发送或运行应用程序。

要解决此问题,您可以更改为在 Windows 上对 React.js 应用程序使用 pm2 命令:

pm2 start ecosystem.config.js --env production --watch
© www.soinside.com 2019 - 2024. All rights reserved.