Unitech / Unitech/pm2

PM2 `start` Fails When Command Contains "yaml" Or "json"

Open
#5,945 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

I am using PM2 to manage a python web service, initiated with a bash command.
this works:

pm2 start 'cd /home/nosson/synchronize && venv/bin/uvicorn server:app --host 0.0.0.0 --reload' --name synchronize
# [PM2] Starting /usr/bin/bash in fork_mode (1 instance)
# [PM2] Done.
# ┌────┬────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
# │ id │ name           │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
# ├────┼────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
# │ 0  │ synchronize    │ default     │ N/A     │ fork    │ 4917     │ 0s     │ 0    │ online    │ 0%       │ 5.8mb    │ nosson   │ disabled │
# └────┴────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘

but when i try to specify a uvicorn log config log_config.yaml, pm2 fails to start the service:

pm2 start 'cd /home/nosson/synchronize && venv/bin/uvicorn server:app --host 0.0.0.0 --reload --log-config log_config.yaml' --name synchronize
# [PM2][ERROR] File cd /home/nosson/synchronize && venv/bin/uvicorn server:app --host 0.0.0.0 --reload --log-config log_config.yaml not found

I suspect this is due to the logic which determines if the supplied command is a pm2 config file:
https://github.com/Unitech/pm2/blob/e3a327fab7a6b385ca0d960c878347dce320ae61/lib/Common.js#L283-L294
which is called when starting the service
https://github.com/Unitech/pm2/blob/e3a327fab7a6b385ca0d960c878347dce320ae61/lib/API.js#L328

Logic for detecting config files as commands should be more precise, possibly checking if the entire command is a valid filename/path rather than a bash (or other) command

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in lib/Common.js at the config-file detection logic linked in the issue, then trace its call from lib/API.js. Reproduce the shown pm2 start command with log_config.yaml and verify that commands containing yaml or json are not treated as config-file paths while actual config-file commands still work.

Written by the indexing model from the issue text.

Assessment

Tech stack
bash, javascript, nodejs, python
Domain
cli, devops
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.