Pm2: launching pm2 from crontab, script defunct

Created on 10 Jan 2014  路  6Comments  路  Source: Unitech/pm2

I am using crontab's @restart to launch pm2 on my hosted server (webfaction, which is using CloudLinux Server 6.5).

I noticed that afterwards my start_pm2.sh bash script appears as [defunct] in ps -eaf. I can "fix" it if I do something like this:

@reboot start_pm2.sh &> pm2.log &

But then I don't get stderr emailed to me if anything goes wrong (using crontab's MAILTO=).

I was hoping to get some insight on this? Am I going about it the wrong way? I don't have root access, should I be using the startup command with user option?

Thanks!!

Most helpful comment

This worked for me on CentOS6.4

$ crontab -e
@reboot /root/.nvm/v0.11.9/bin/node /root/.nvm/v0.11.9/bin/pm2 resurrect
*/5 * * * * /root/.nvm/v0.11.9/bin/node /root/.nvm/v0.11.9/bin/pm2 dump

Just replace these values by what is written on the /etc/init.d/pm2-init.sh (node and pm2)

Tell me if it worked for you also

All 6 comments

This worked for me on CentOS6.4

$ crontab -e
@reboot /root/.nvm/v0.11.9/bin/node /root/.nvm/v0.11.9/bin/pm2 resurrect
*/5 * * * * /root/.nvm/v0.11.9/bin/node /root/.nvm/v0.11.9/bin/pm2 dump

Just replace these values by what is written on the /etc/init.d/pm2-init.sh (node and pm2)

Tell me if it worked for you also

Ah, voila... that works like a charm, thank you ;-)

I was doing a pm2 start processes.json as part of my start_pm2.sh script.

The command above doesn't worked in my app. When run pm2 commands (like start, resurrect) from crontab, my app doesn't start properly. But when i manually run the command it starts well..

Here is the error i got:

maintenance-script-9 (err): 2015-09-28 05:55 +00:00: /home/ubuntu/src/maintenance-script/server/node_modules/co-bcrypt/node_modules/bcrypt/node_modules/bindings/bindings.js:83
maintenance-script-9 (err): throw e
maintenance-script-9 (err): ^
maintenance-script-9 (err): Error: Module version mismatch. Expected 14, got 44.
maintenance-script-9 (err): at Error (native)
maintenance-script-9 (err): at Module.load (module.js:349:32)
maintenance-script-9 (err): at Function.Module._load (module.js:305:12)
maintenance-script-9 (err): at Module.require (module.js:357:17)
maintenance-script-9 (err): at require (module.js:373:17)
maintenance-script-9 (err): at bindings (/home/ubuntu/src/maintenance-script/server/node_modules/co-bcrypt/node_modules/bcrypt/node_modules/bindings/bindings.js:76:44)
maintenance-script-9 (err): at Object. (/home/ubuntu/src/maintenance-script/server/node_modules/co-bcrypt/node_modules/bcrypt/bcrypt.js:3:35)
maintenance-script-9 (err): at Module._compile (module.js:449:26)
maintenance-script-9 (err): at Object.Module._extensions..js (module.js:467:10)
maintenance-script-9 (err): at Module.load (module.js:349:32)
maintenance-script-9 (err): at Function.Module._load (module.js:305:12)
maintenance-script-9 (err): at Module.require (module.js:357:17)
maintenance-script-9 (err): at require (module.js:373:17)
maintenance-script-9 (err): at Object. (/home/ubuntu/src/maintenance-script/server/node_modules/co-bcrypt/index.js:1:76)
maintenance-script-9 (err): at Module._compile (module.js:449:26)
maintenance-script-9 (err): at Object.Module._extensions..js (module.js:467:10)

On top of the it says: The app restarted 15 times so it is stopped (errored)

Was there ever a resolution to this @juliousglori ?

up

@Unitech that works for me, thaks!!,

Was this page helpful?
0 / 5 - 0 ratings