Skip to content

PM2 Pid file is not being create. #5966

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
HamidShaikh1499 opened this issue Mar 21, 2025 · 2 comments
Open

PM2 Pid file is not being create. #5966

HamidShaikh1499 opened this issue Mar 21, 2025 · 2 comments

Comments

@HamidShaikh1499
Copy link

I installed node and pm2(globally) as root user.

I setup all my project as non sudo user and setup ecosystem files for start applications using pm2

When i run pm2 startup. it provides command that command i run as root user. and then pm2 save.

After restart server, then pm2 is not able to restart all applications.

I checked pm-user.service is failing because pm2.pid file not found

I tried many times but PM2.PID is not creating So pm-nonuser.service is failing

Any solution??

@HamidShaikh1499
Copy link
Author

?

@rohankamble103
Copy link

Reason:-

Yes, this is a common PM2 + systemd + multiple user context issue.

When you install Node.js and PM2 as root, but run your apps and ecosystem setup as a non-root user, PM2 gets confused during pm2 startup because it mixes context between the root and non-root user environments.

Let’s fix it step-by-step so that your PM2 setup works reliably across reboots for the non-root user.

Step-by-Step Solution

  1. Clean Existing PM2 Root Setup (Optional But Recommended) This avoids conflict between root and non-root PM2 environments.

Run this commands as root:

pm2 unstartup
pm2 kill
  1. Switch to Your Non-root User
    Let’s assume your non-root user is devuser. Switch if you're not already:
su - devuser

Or if you're logged in directly as devuser, skip this step.

  1. Install PM2 Locally (Non-root)
    Make sure pm2 is installed in this user’s environment.
npm install -g pm2
  1. Run PM2 Startup for the Current User
    This is crucial: Run pm2 startup as the non-root user.
pm2 startup

It will show a command like this:

sudo env PATH=$PATH:/home/devuser/.nvm/versions/node/vXX/bin pm2 startup systemd -u devuser --hp /home/devuser

Copy and paste that command and run it as root (with sudo).

sudo env PATH=$PATH:/home/devuser/.nvm/versions/node/vXX/bin pm2 startup systemd -u devuser --hp /home/devuser

This sets up a proper pm2-devuser.service with the correct environment.

  1. Save the Current PM2 Process ListStill as devuser:
pm2 save

This saves the process list that should be auto-started on reboot.

  1. Reboot and Test
sudo reboot

After reboot, log in as devuser and run:

pm2 ls

Your apps should be running automatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants