Skip to content

PM2 start Fails When Command Contains "yaml" Or "json" #5945

Open
@nossonCotlar

Description

@nossonCotlar

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:

pm2/lib/Common.js

Lines 283 to 294 in e3a327f

Common.isConfigFile = function (filename) {
if (typeof (filename) !== 'string')
return null;
for (let extension in Common.knonwConfigFileExtensions) {
if (filename.indexOf(extension) !== -1) {
return Common.knonwConfigFileExtensions[extension];
}
}
return null;
};

which is called when starting the service

pm2/lib/API.js

Line 328 in e3a327f

if (Common.isConfigFile(cmd) || (typeof(cmd) === 'object')) {

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions