How do I start pm2 on startup?

How do I start pm2 on startup?

To automatically generate and configuration a startup script just type the command (without sudo) pm2 startup :

  1. $ pm2 startup [PM2] You have to run this command as root.
  2. sudo su -c “env PATH=$PATH:/home/unitech/.nvm/versions/node/v14.3/bin pm2 startup -u –hp
  3. $ pm2 unstartup.

What does pm2 startup do?

PM2 can generate startup scripts and configure them in order to keep your process list intact across expected or unexpected machine restarts.

Does pm2 start on boot?

PM2 ships with the functionality to generate startup scripts for multiple init systems. These scripts are executed on system boot and with that spawn the PM2 process itself which is required to (re)start application servers.

How do I start NPM pm2?

2 Answers. In your case, pm2 start npm — start would run node ./bin/www . Change the start script to node app. js if you want to run node app.

How do I restart pm2?

  1. Restart at cron time. Via CLI:
  2. Restart on file change. PM2 can automatically restart your application when a file is modified in the current directory or its subdirectories:
  3. Restart Delay.
  4. No Auto Restart.
  5. Skip Auto Restart For Specific Exit Codes.
  6. Exponential Backoff Restart Delay.

How run next JS with pm2?

  1. Make sure you run npm run build to build the Next.js app for production.
  2. Run npm run pm2 start pm2.json.

Does pm2 auto restart after reboot?

One of PM2’s key features is support for a startup script (generated dynamically based on the default init system on your server), that restarts PM2 and your processes at every server restart. When the server restarts, it will automatically restart PM2, which will then restart all the Node.

How do I load a saved pm2?

2 Answers. pm2 save takes a snapshot of your currently running Node applications. You can then restore these applications using pm2 resurrect . This is useful because it means you don’t have to manually restart each application when you restart pm2 (such as a machine reboot).

What user does pm2 run as?

It uses current user’s . pm2 directory which is stored under /home//.

How do I know if pm2 is running?

“check if pm2 is running with specific name” Code Answer

  1. pm2 start app. js –name “my-api”
  2. pm2 start web. js –name “web-interface”
  3. pm2 stop web-interface.
  4. pm3 restart web-interface.

How do I install pm2 globally?

Install pm2

  1. npm install pm2 -g.
  2. apt update && apt install sudo curl && curl -sL https://raw.githubusercontent.com/Unitech/pm2/master/packager/setup.deb.sh | sudo -E bash –
  3. pm2 completion install.
  4. npm install pm2 -g && pm2 update.

How do I restart a pm2 process?

How to generate a startup script in PM2?

To automatically generate and configuration a startup script just type the command (without sudo) pm2 startup: $ pm2 startup

How to start an old version of PM2?

Basically the service would start an old version of the saved process list, even though I tried pm2 delete all, pm2 start ecosystem.config.js, pm2 save. 1. Create a file pm2-resurrect.sh in C:\\, which contains the single line pm2 resurrect. 2.

How do you name an app in PM2?

As seen above, PM2 will automatically assign an app name based on the file given to PM2’s start subcommand. This can be customized after starting an app by using the restart subcommand with the name flag followed by whatever we would like the app to be named:

How do I install PM2 on my NPM?

If you are using npm as your package manager, you can install PM2 by entering: The -g flag will ensure that we are installing pm2 globally, so that is available system-wide rather than just within your project directory. Likewise, if you’re using yarn as your package manager: