restart api does not allow updating the env variables
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?
When using the pm2 api restart gives and error and it does not update the environment variables although the documentation states it should do it.
How could we reproduce this issue?
Create a test.js file:
console.log(process.env.MY_ENV);
Create an app.js file:
const pm2 = require("pm2");
pm2.start(
{
name: "test",
script: "./test.js",
env: {
MY_ENV: "test",
},
},
function (err, apps) {
if (err) {
console.error(err);
return pm2.disconnect();
} else {
console.log("Service test started.");
pm2.restart(
"test",
{
updateEnv: true,
env: {
MY_ENV: "restarted",
},
},
function (err) {
if (err) {
console.error(err);
} else {
console.log("Service test restarted");
}
}
);
}
}
);
run with:
$ node app.js
Produces this error:
Error: Using --env [env] without passing the ecosystem.config.js does not work
at Object.Common.retErr (/Users/manuelastudillo/Dev/taskforce/taskforce-backend/config_app/node_modules/pm2/lib/Common.js:326:10)
at API.restart (/Users/manuelastudillo/Dev/taskforce/taskforce-backend/config_app/node_modules/pm2/lib/API.js:519:31)
Using the option "env_" instead as suggested by the documentation avoids the error but the envs are not updated.
Supporting information
pm2 version 3.5.2
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 running the provided app.js and test.js reproduction with PM2 3.5.2, then inspect the restart path referenced in lib/API.js and the error in lib/Common.js. Done means pm2.restart accepts the supplied environment options without the error and the restarted process reports MY_ENV as "restarted".
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100