
:+1: same here
@soyuka @Tjatse
Using _Ubuntu 14.04.1_ got similar behaviour for # sudo env PATH=$PATH:/usr/bin pm2 startup -u safeuser. Inspecting boot log I've found the following:
Starting pm2
events.js:85
throw er; // Unhandled 'error' event
^
Error: connect EACCES
at exports._errnoException (util.js:746:11)
at PipeConnectWrap.afterConnect [as oncomplete] (net.js:1010:19)
Using # sudo env PATH=$PATH:/usr/bin pm2 startup and adding the app with # sudo pm2 start app.json works perfectly after reboot, but it's not secure run pm2 as root.
A note of worth is that reading https://www.digitalocean.com/community/tutorials/how-to-use-pm2-to-setup-a-node-js-production-environment-on-an-ubuntu-vps it points to use libcap2-bin library to allow use restricted ports, but remains the same behaviour as not executing # sudo setcap cap_net_bind_service=+ep /usr/bin/node.
I'm running into the same thing.
I did come across this article, but it didn't really seem to help much. I did however get it to startup once on reboot but not since.
I'm not sure if it makes a difference, but just so you have more info; I am starting this from a config (JSON) file.
{
"apps": [
{
"name": "express-app-production",
"script": "bin/www",
"env": {
"NODE_ENV": "production",
"PORT": "3000"
}
}
]
}
I ran into this issue, and found a solution that works for me. Let's assume I've created a user named 'node' to run pm2. All of the commands below should be run by the node user, in the node user's home directory (/home/node)
% pm2 delete all% pm2 dump% pm2 start app.js --watch% pm2 save% sudo pm2 startup centos -u nodePM2_HOME path in the pm2-init script to match the home directory of the user:% sudo vi /etc/init.d/pm2-init.shexport PM2_HOME="/home/node/.pm2"I found the issue was, the user was being set appropriately in the pm2-init.sh file, but the PM2_HOME directory was set to /root/.pm2 by default
==UPDATE==
For centos, I was able to replace step 2 above with the following:
% sudo su -c "env PATH=$PATH:/usr/local/bin PM2_HOME=/home/node/.pm2 pm2 startup centos -u node"
@dibari thank you! it worked out for me too!
Update: while it worked at the first time, it stopped working right after. The issue is that dump.pm2 is being emptied on reboot so nothing is resurrected on startup. So as a workaround I followed this suggestion to make the file immutable.
@dibari
I have been stuck here for 3 days....Thank you very much for your solution!!! It also worked for me!!!
Same problem here. To me it seems like dumpfile gets emptied on reboot. If I run resurrect manually as proper user, it all works. I'm using pm2-generated init file, with non-root user who has all node tools and pm2 installed under his account.
This is somewhat suprising issue to have.
@mikalai-silivonik thanks should go to you here, on CentOS7
chattr +i [USER_HOME_DIR]/.pm2/dump.pm2 did the trick for me after the pm2 save
@ghartsho your chattr command saved my life, thanks!
@thanhthang20 I try success by this step
pm2 start start.js
pm2 save
pm2 startup centos
@meteormatt
I get this error trying to do pm2 startup centos
[PM2] Writing startup script in /etc/init.d/pm2-init.sh
[PM2] Making script booting at startup...
[PM2] /var/lock/subsys/pm2-init.sh lockfile has been added
[PM2] -centos- Using the command:
su -c "chmod +x /etc/init.d/pm2-init.sh; chkconfig --add pm2-init.sh"
internal/child_process.js:313
throw errnoException(err, 'spawn');
^
Error: spawn ENOMEM
at exports._errnoException (util.js:1036:11)
at ChildProcess.spawn (internal/child_process.js:313:11)
at exports.spawn (child_process.js:380:9)
at Object.exports.execFile (child_process.js:143:15)
at exports.exec (child_process.js:103:18)
at CLI.startup (/usr/local/lib/node_modules/pm2/lib/API/Startup.js:175:5)
at Command.<anonymous> (/usr/local/lib/node_modules/pm2/bin/pm2:548:9)
at Command.listener (/usr/local/lib/node_modules/pm2/node_modules/commander/index.js:301:8)
at emitTwo (events.js:106:13)
at Command.emit (events.js:191:7)
Any ideas?
@ubiko Maybe no enough memory?
@meteormatt that must be it!
I'm on a VPS with no control over the swap.
Thanks, I'll change my setup!
Closing in favor of #2559
To try the new startup system:
$ npm install Unitech/pm2#development -g
$ pm2 update
$ pm2 startup # Then copy / paste the command displayed
$ pm2 unstartup
Most helpful comment
@thanhthang20 I try success by this step