Unitech / Unitech/pm2

Cron tasks do not run at system startup until you manually trigger them

Open
#5,834 1 comment 4 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

What's going wrong?

Cron tasks running through PM2 do not stat at system statup/reboot and i have to manually pm2 start x them. I have a DNS-Updater task that runs every 30 minutes and this is the ecosystem file:

module.exports = {
  apps : [{
    name   : "DNS-Updater",
    namespace : "task",
    script : "python3",
    watch: false,
    instances: 1,
    args : "dnsupdater.py",
    cron_restart : "*/30 * * * *",
    autorestart : false
  }]
}

I was forced to set autorestart : false because otherwise every time the task stops it restarts so this causes it to run constantly instead of the scheduled cron.
I saw that in the new release 5.4.0 was added an autostart #5782 but this won't work either because it does not trigger at system startup

PS. It might be very well that I'm using it in a wrong way, but honestly the docs aren't very clear

How could we reproduce this issue?

Create a cron task without autorestart, start it, reboot the system and it won't run ever until you first start it with pm2 start x

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Sat Jun 01 2024 10:17:23 GMT+0200 (Central European Summer Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.4.0
node version         : 20.13.1
node path            : /root/.nvm/versions/node/v20.13.1/bin/pm2
argv                 : /root/.nvm/versions/node/v20.13.1/bin/node,/root/.nvm/versions/node/v20.13.1/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : root
uid                  : 0
gid                  : 0
uptime               : 6min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.4.0
node version         : 20.13.1
node path            : /root/.nvm/versions/node/v20.13.1/bin/pm2
argv                 : /root/.nvm/versions/node/v20.13.1/bin/node,/root/.nvm/versions/node/v20.13.1/bin/pm2,report
argv0                : node
user                 : root
uid                  : 0
gid                  : 0
===============================================================================
--- System info --------------------------------------------
arch                 : arm64
platform             : linux
type                 : Linux
cpus                 : Cortex-A53
cpus nb              : 4
freemem              : 437067776
totalmem             : 951398400
home                 : /root
===============================================================================
--- PM2 list -----------------------------------------------
┌────┬────────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name               │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├────┼────────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0  │ DNS-Updater        │ task        │ N/A     │ fork    │ N/A      │ 0      │ 0    │ stopped   │ 0%       │ 0b       │ root     │ disabled │
│ 1  │ HR-API             │ api         │ N/A     │ fork    │ 21632    │ 6m     │ 0    │ online    │ 0.6%     │ 59.4mb   │ root     │ disabled │
│ 2  │ HR-Sync            │ task        │ N/A     │ fork    │ N/A      │ 0      │ 0    │ stopped   │ 0%       │ 0b       │ root     │ disabled │
│ 3  │ PlexAPI            │ api         │ N/A     │ fork    │ 21633    │ 6m     │ 0    │ online    │ 0.1%     │ 35.3mb   │ root     │ disabled │
│ 4  │ TelegramChatBot    │ api         │ N/A     │ fork    │ 21634    │ 6m     │ 0    │ online    │ 0%       │ 42.0mb   │ root     │ disabled │
└────┴────────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/root/.pm2/pm2.log last 20 lines:
PM2        | 2024-06-01T10:11:09: PM2 log: Node.js version      : 20.13.1
PM2        | 2024-06-01T10:11:09: PM2 log: Current arch         : arm64
PM2        | 2024-06-01T10:11:09: PM2 log: PM2 home             : /root/.pm2
PM2        | 2024-06-01T10:11:09: PM2 log: PM2 PID file         : /root/.pm2/pm2.pid
PM2        | 2024-06-01T10:11:09: PM2 log: RPC socket file      : /root/.pm2/rpc.sock
PM2        | 2024-06-01T10:11:09: PM2 log: BUS socket file      : /root/.pm2/pub.sock
PM2        | 2024-06-01T10:11:09: PM2 log: Application log path : /root/.pm2/logs
PM2        | 2024-06-01T10:11:09: PM2 log: Worker Interval      : 30000
PM2        | 2024-06-01T10:11:09: PM2 log: Process dump file    : /root/.pm2/dump.pm2
PM2        | 2024-06-01T10:11:09: PM2 log: Concurrent actions   : 2
PM2        | 2024-06-01T10:11:09: PM2 log: SIGTERM timeout      : 1600
PM2        | 2024-06-01T10:11:09: PM2 log: ===============================================================================
PM2        | 2024-06-01T10:11:09: PM2 log: [PM2][WORKER] Registering a cron job on: 0
PM2        | 2024-06-01T10:11:09: PM2 log: App [HR-API:1] starting in -fork mode-
PM2        | 2024-06-01T10:11:09: PM2 log: [PM2][WORKER] Registering a cron job on: 2
PM2        | 2024-06-01T10:11:10: PM2 log: App [PlexAPI:3] starting in -fork mode-
PM2        | 2024-06-01T10:11:10: PM2 log: App [HR-API:1] online
PM2        | 2024-06-01T10:11:10: PM2 log: App [TelegramChatBot:4] starting in -fork mode-
PM2        | 2024-06-01T10:11:10: PM2 log: App [PlexAPI:3] online
PM2        | 2024-06-01T10:11:10: PM2 log: App [TelegramChatBot:4] online

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

The issue provides an ecosystem configuration using cron_restart, autorestart, and autostart, but names no source files or tests. Start by tracing PM2's startup restore path and cron task handling, then reproduce the reboot scenario with the supplied configuration. Done means a dumped task starts or runs at the expected schedule after system startup without manual intervention, with regression coverage or clarified documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, python
Domain
cli, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.