Search code examples
linuxubuntugithubpm2github-actions-self-hosted-runners

Error: RROR] Process or Namespace not found. PM2 Error Linux Server with github actions


I recently updated my self-hosted linux server on compute engine. Pm2 had been working perfectly along my github actions previously. However after update when i restart a pm2 instance from my ssh terminal it works fine. But when I try to restart pm2 instance from github actions jobs then it throws me this error. I've uninstall and reinstalled pm2 but still the same error. Previously it worked fine but now it shows me this error.

So if i run the github action then this error shows enter image description here

But when i run the same command from ssh termianl connected to my server then it works fine enter image description here

Any help would be appreciated


Solution

  • This problem may be caused by not setting the environment variable PM2_HOME correctly.

    • What is PM2_HOME from ChatGPT: PM2_HOME is an environment variable that specifies the directory where PM2 stores its configuration files and data, including log files, process lists, and keys. By default, if PM2_HOME is not set, PM2 uses the .pm2 folder in the user's home directory (e.g., ~/.pm2 on Linux or macOS).

    Problems I encountered

    • I encountered the same problem when using our company's internal CI tool. The root of this problem is that the CI tool also uses PM2 to manage its own services. When you use the CI tool to execute a script, if the environment variable PM2_HOME is not set, the CI tool will use its own PM2 process (which is different from the PM2 process in your ssh), so the PM2 of the process cannot find the target service.

    Two solutions

    • Check this doc.
    1. Temporarily set PM2_HOME: PM2_HOME='<your pm2 home>' pm2 <command>
    2. Setting PM2_HOME in .bashrc/.shrc/.zshrc

    Way to find PM2_HOME location of a running PM2 thread

    • run command ps aux|grep PM2
    • you will see something like this picture
    • the path in the red box in the figure is the path of PM2_HOME of this pm2 process
    • Next, you can specify PM2_HOME as these paths and view the services managed by these pm2 processes.
      • like PM2_HOME='.pm2' pm2 ls