Can't start app when using autostart = false
What's going wrong?
I can't start any apps when using the 'autostart' parameter
How could we reproduce this issue?
ecosystem.config.js
module.exports = [{
name: 'testapp',
script: `test.js`,
autostart: false
}];
test.js
console.log('Hello World!');
Supporting information
# Run the following commands
$ pm2 start ecosystem.config.js
$ pm2 start testapp
$ pm2 logs testapp
# Logs are empty
I made a PR to fix this in the forked repo but it didn't get merged: https://github.com/ultimate-tester/pm2/pull/1
I can reproduce the issue.
Why don't you make a PR to pm2 directly?
From what I understand, autostart: false is for adding the app to the pm2 list as "stopped" so it makes sense it does not run. I didn't find any documentation on it though (the closest is this : #5782). Maybe there is some confusion with autorestart ?
On the other hand, I thought it was useful to get a cron task running without the initial run off-schedule, but the app does not run at all when using cron_restart: "* * * * *" and autostart: false
The issue is that, if pm2 is started with autostart false, the app won't start after even with pm2 start app or pm2 restart app.
For example, running the following
pm2 start --no-autostart app.js
pm2 start app
pm2 ls
gives
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ app │ fork │ 0 │ stopped │ 0% │ 0b │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
The same happens if autostart: false is set in ecosystem.config.js.
I thought this was expected behaviour, and that the point of it was that only cron_restart could start the app. But cron-restart can't start the app either so you are probably right. (oh, and I just understood that you are a regular contributor)
The lack of documentation makes it difficult to talk about this, the expected behaviour is unclear to me.
Related issue about --cron-restart #5807
I have the same issue.
Tried out autostart: false because my cron jobs ran on every ecosystem reload, and I wanted them to only get triggered by cron_restart: "* * * * *". Now they don't run at all anymore.
I came across an old issue that had a fallback solution. Maybe this will help someone else with he same need. But I hope that this can be solved within the pm2 itself soon 🙏
The comment I talked about 👉🏻 https://github.com/Unitech/pm2/issues/5479#issuecomment-1981808662.