--cron not seemingly working #496

Closed
stockholmux opened this Issue Jun 2, 2014 · 6 comments

6 participants

@stockholmux

I can't seem to get pm2's cron to actually restart a process - take this example:

kyle@--------------:~/nodeSites/gustavus$ date
Mon Jun  2 08:34:58 EDT 2014
kyle@--------------:~/nodeSites/gustavus$ pm2 start wpServices.node.js -n wpService --cron 36 8 * * * -x
36
PM2 Process launched
┌─────────────┬────┬─────────┬───────┬────────┬──────┬───────────┬────────┬───────────┬────────────────────────────────────────────┐
│ App Name    │ id │ mode    │ PID   │ status │ port │ Restarted │ Uptime │    memory │ err logs                                   │
├─────────────┼────┼─────────┼───────┼────────┼──────┼───────────┼────────┼───────────┼────────────────────────────────────────────┤
│ wpService   │ 17 │ fork    │ 3228  │ online │      │         0 │ 0s     │  4.719 MB │ /home/kyle/.pm2/logs/wpService-err-17.log  │
└─────────────┴────┴─────────┴───────┴────────┴──────┴───────────┴────────┴───────────┴────────────────────────────────────────────┘
kyle@--------------:~/nodeSites/gustavus$ date
Mon Jun  2 08:35:17 EDT 2014
kyle@--------------:~/nodeSites/gustavus$ date
Mon Jun  2 08:36:09 EDT 2014
kyle@--------------:~/nodeSites/gustavus$ pm2 list
┌─────────────┬────┬─────────┬───────┬────────┬──────┬───────────┬────────┬───────────┬────────────────────────────────────────────┐
│ App Name    │ id │ mode    │ PID   │ status │ port │ Restarted │ Uptime │    memory │ err logs                                   │
├─────────────┼────┼─────────┼───────┼────────┼──────┼───────────┼────────┼───────────┼────────────────────────────────────────────┤
│ wpService   │ 17 │ fork    │ 3228  │ online │      │         0 │ 69s    │ 25.773 MB │ /home/kyle/.pm2/logs/wpService-err-17.log  │
└─────────────┴────┴─────────┴───────┴────────┴──────┴───────────┴────────┴───────────┴────────────────────────────────────────────┘

(other process were redacted)

Am I doing something wrong or is this an actual bug?

@soyuka
Collaborator

#559
@Unitech @rlidwka should we remove the cron feature?

@rlidwka
Collaborator

Yes, I don't see why someone would need it if he has an actual cron (other than for b/w compatibility).

That said, @stockholmux 's error is just about escaping strings in bash command line. This should work better (didn't test though):

$ pm2 start wpServices.node.js -n wpService --cron '36 8 * * *'
@stockholmux

@rlidwka thanks for the update. I'll try that.

Just to chime in on the need of this - it's nice to be able to do everything with PM2 for deployment instead of having to setup the pm2 start then edit the crontab file. It took a minute to figure out the directories for using crontab. It's not really that straight forward:

58 10 * * * /home/user-name/local/bin/node /home/user-name/local/lib/node_modules/pm2/bin/pm2 restart wpService

If I had a vote, I'd keep it, maybe just document a bit better.

@soyuka soyuka closed this Aug 4, 2014
@soyuka soyuka added a commit that referenced this issue Aug 4, 2014
@soyuka soyuka Added cron link to #496 f08ba8d
@rafaelkaufmann

I'm with @stockholmux on this one. I love having cron_restart on the JSON config file.

@naggie

Yes cron-like timing is very useful. I currently have 10 processes that I run for local development at work, together with a few maintenance tasks. Having everything in one JSON file is great!

@michaelBenin

Hey, just to add to this, I've noticed that having a config where:

{
  "apps": [
    {
      "name": "cron-script",
      "cwd": ".",
      "script": "dist/server/index.js",
      "exec_mode": "fork_mode",
      "min_uptime": 1000,
      "watch": false,
      "merge_logs": true,
      "log_file": "logs/pm2_child.log",
      "error_file": "logs/pm2_error.log",
      "out_file": "logs/pm2_child_out.log",
      "exec_interpreter": "node",
      "env": {
        "NODE_ENV": "production"
      },
      "pmx": false,
      "vizion": false,
      "cron_restart": "*/1 * * * *", // restart every minute (used for testing)
      "autorestart": false // this is the problem here
    }
  ]
}

Having autorestart false disables the cron restart. I want to be able to exit the process gracefully after the script runs. My work around is to close all the db connections and sockets after the script runs but do not exit it. I feel like this is an issue with the cron_restart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment