Mamochi
Mamochi

Reputation: 151

Hangs on build using nestjs, pm2

I want to provide uninterrupted service using nestjs, pm2.

I download the changes via git pull origin master command. After that, save the new changes through the yarn build command. At this time, the service stops with an error saying dist/main.js cannot be found.

I tried to move the dist folder that was build outside the operating folder using mv, but it stopped and the service started again after entering the reload command.

Below is my code. How can I operate uninterrupted service?

//ecosystem.config.js
name: 'my_api',
      script: 'dist/main.js',
      watch: '.',
      instances: 2,
      exec_mode: 'cluster',
      wait_ready: true,
      listen_timeout: 20000,
      kill_timeout: 5000


//package.json
"prebuild": "rimraf dist",
"start": "yarn build && pm2 start ecosystem.config.js",

Upvotes: 1

Views: 945

Answers (3)

Kirill Oficerov
Kirill Oficerov

Reputation: 2300

In my case the reason of the hang was opened pm2 logs on the same server. Stopping the logs allowed me to fix the problem

Upvotes: 0

Mamochi
Mamochi

Reputation: 151

I removed the watch:'.', the service did not stop during build, and I was able to run it normally through the command pm2 reload myApp.

Upvotes: 0

Malik Aleem
Malik Aleem

Reputation: 1

You need to remove the dist folder before creating the build of the application. Stop the pm2 service and create a fresh build. After creating a fresh build. Restart the pm2 service. It will be fine.

Upvotes: 0

Related Questions