pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

launching pm2 from crontab, script defunct

Open naartjie opened this issue 12 years ago • 6 comments

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!!

naartjie avatar Jan 10 '14 13:01 naartjie

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

Unitech avatar Jan 14 '14 19:01 Unitech

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.

naartjie avatar Jan 15 '14 10:01 naartjie

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)

juliousglori avatar Sep 28 '15 06:09 juliousglori

Was there ever a resolution to this @juliousglori ?

CodisRedding avatar Dec 12 '15 04:12 CodisRedding

up

labidiaymen avatar Feb 03 '16 14:02 labidiaymen

@Unitech that works for me, thaks!!,

MiguelSavignano avatar May 05 '16 09:05 MiguelSavignano