PM2 with Python - Python can not find Module(works outside of pm2)
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
What's going wrong?
Using PM2 to run and monitor some Python scripts - however python throws an error :
Error: Cannot find module '/root/maintain-search-database'
13|maintai | at Function.Module._resolveFilename (internal/modules/cjs/loader.js:965:15)
13|maintai | at Function.Module._load (internal/modules/cjs/loader.js:841:27)
13|maintai | at Object. (/root/.nvm/versions/node/v12.18.3/lib/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
13|maintai | at Module._compile (internal/modules/cjs/loader.js:1137:30)
13|maintai | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1157:10)
13|maintai | at Module.load (internal/modules/cjs/loader.js:985:32)
13|maintai | at Function.Module._load (internal/modules/cjs/loader.js:878:14)
13|maintai | at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
13|maintai | at internal/main/run_main_module.js:17:47 {
13|maintai | code: 'MODULE_NOT_FOUND',
13|maintai | requireStack: []
13|maintai | }
I have several applications running successfully, also Python however 3 of them are throwing similar errors.
The projects work outside of pm2. Would rather to be able to monitor and have them auto restart with pm2.
Everything is running with root privileges
How could we reproduce this issue?
Not sure, we have several python projects, using the json config file, launching each python script with a python venv. So we have the interpreter set to the python inside the env. Other then that, not sure, We have to issues with Flask, and the issue reported above dose not sue flask. Just python script. However other Python scripts are running fine.
Supporting information
--- PM2 report ----------------------------------------------------------------
Date : Fri Jul 09 2021 13:49:39 GMT-0700 (Pacific Daylight Time)
--- Daemon --------------------------------------------------------------------
pm2d version : 4.5.5
node version : 12.18.3
node path : not found
argv : /root/.nvm/versions/node/v12.18.3/bin/node,/root/.nvm/versions/node/v12.18.3/lib/node_modules/pm2/lib/Daemon.js
argv0 : node
user : root
uid : 0
gid : 0
uptime : 28602min
--- CLI -----------------------------------------------------------------------
local pm2 : 4.5.5
node version : 12.18.3
node path : /root/.nvm/versions/node/v12.18.3/bin/pm2
argv : /root/.nvm/versions/node/v12.18.3/bin/node,/root/.nvm/versions/node/v12.18.3/bin/pm2,report
--More--
argv0 : node
--More--
user : root
--More--
uid : 0
--More--
gid : 0
--More--
--More--
--- System info ---------------------------------------------------------------
--More--
arch : x64
--More--
platform : linux
--More--
type : Linux
--More--
cpus : Intel Core Processor (Broadwell, IBRS)
--More--
cpus nb : 2
--More--
freemem : 73846784
--More--
totalmem : 1927016448
--More--
home : /root
--More--
--More--
--- PM2 list ------------------------------------------------------------------
--More--
┌─────┬─────────────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
--More--
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
--More--
├─────┼─────────────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
--More--
│ 9 │ YCBM │ default │ N/A │ fork │ 0 │ 0 │ 119 │ stopped │ 0% │ 0b │ root │ disabled │
--More--
│ 7 │ git-inactivity-backend │ default │ N/A │ fork │ 23129 │ 12m │ 26 │ online │ 0% │ 3.4mb │ root │ disabled │
--More--
│ 8 │ git-visual-backend │ default │ N/A │ fork │ 23151 │ 12m │ 26 │ online │ 0% │ 3.2mb │ root │ disabled │
--More--
│ 12 │ github-server │ default │ N/A │ fork │ 23170 │ 12m │ 4 │ online │ 0% │ 600.0kb │ root │ disabled │
--More--
│ 10 │ issue_visual_frontend │ default │ N/A │ fork │ 23169 │ 12m │ 91 │ online │ 0% │ 0b │ root │ disabled │
--More--
│ 1 │ lantern-backend │ default │ N/A │ fork │ 0 │ 0 │ 339… │ stopped │ 0% │ 0b │ root │ disabled │
--More--
│ 2 │ lantern-frontend │ default │ N/A │ fork │ 22948 │ 12m │ 27 │ online │ 0% │ 0b │ root │ disabled │
--More--
│ 13 │ maintain-search-database │ default │ N/A │ fork │ 0 │ 0 │ 162 │ errored │ 0% │ 0b │ root │ disabled │
--More--
│ 5 │ slack-search-backend │ default │ N/A │ fork │ 23076 │ 12m │ 27 │ online │ 0.1% │ 3.8mb │ root │ disabled │
--More--
│ 6 │ slack-search-frontend │ default │ N/A │ fork │ 23085 │ 12m │ 29 │ online │ 0% │ 0b │ root │ disabled │
--More--
│ 3 │ tagging-system-backend │ default │ N/A │ fork │ 23048 │ 12m │ 27 │ online │ 0% │ 4.0kb │ root │ disabled │
--More--
│ 4 │ tagging-system-frontend │ default │ N/A │ fork │ 23020 │ 12m │ 29 │ online │ 0% │ 0b │ root │ disabled │
--More--
│ 0 │ yellow-page │ default │ N/A │ fork │ 22959 │ 12m │ 27 │ online │ 0% │ 0b │ root │ disabled │
--More--
└─────┴─────────────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
--More--
--More--
--- Daemon logs ---------------------------------------------------------------
--More--
/root/.pm2/pm2.log last 20 lines:
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] exited with code [1] via signal [SIGINT]
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] starting in -fork mode-
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] online
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] exited with code [1] via signal [SIGINT]
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] starting in -fork mode-
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] online
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] exited with code [1] via signal [SIGINT]
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] starting in -fork mode-
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] online
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] exited with code [1] via signal [SIGINT]
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] starting in -fork mode-
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] online
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] exited with code [1] via signal [SIGINT]
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] starting in -fork mode-
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] online
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] exited with code [1] via signal [SIGINT]
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] starting in -fork mode-
--More--
PM2 | 2021-07-09T13:42:42: PM2 log: App [maintain-search-database:13] online
--More--
PM2 | 2021-07-09T13:42:43: PM2 log: App [maintain-search-database:13] exited with code [1] via signal [SIGINT]
--More--
PM2 | 2021-07-09T13:42:43: PM2 log: Script /root/maintain-search-database had too many unstable restarts (16). Stopped. "errored"
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Python launch from the JSON configuration with its virtual-environment interpreter, then inspect lib/ProcessContainerFork.js, the entry point named in the stack trace. Compare a failing script with the Python applications that run successfully under PM2. Done means the affected scripts start under PM2 without MODULE_NOT_FOUND and remain monitorable, with the cause and a reproducible case documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js, python
- Domain
- devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100