Reputation: 5681
I am trying to run pm2 at startup without success..
I am installing in ubuntu 16.04.
My npm directory is in : ~/.npm-global.
There, I can see pm2 -> ../lib/node_modules/pm2/bin/pm2
There is no dump file.
My pm2 directory is ~/.pm2:
There , I can see dump.pm2 and rpc.sock
If I do:
sudo $(which pm2) start app.js
sudo $(which pm2) startup ubuntu -u $USER
sudo $(which pm2) save
it shows me :
Generating system init script in /etc/init.d/pm2-init.sh
[PM2] Making script booting at startup...
[PM2] -ubuntu- Using the command:
su -c "chmod +x /etc/init.d/pm2-init.sh && update-rc.d pm2-init.sh defaults"
[PM2] Done.
[PM2] Saving current process list...
[PM2] Successfully saved in /home/theUser/.pm2/dump.pm2
and I can see that the app is running fine.
If I do though, sudo ~/.npm-global/bin/pm2 start /etc/init.d/pm2-init.sh
,it gives me:
events.js:160
throw er; // Unhandled 'error' event
^
Error: connect EACCES ~/.pm2/rpc.sock
at ....
The /etc/init.d/pm2-init.sh
has :
NAME=pm2
PM2=/home/theUser/.pm2
USER=theUser
DEFAULT=/etc/default/$NAME
export PATH=/usr/bin:$PATH
export PM2_HOME="/home/theUser/.npm-global/lib/node_modules/pm2/bin/"
I tried also using : export PM2_HOME="/home/theUser/.pm2
and when I start the scipt from /etc/init.d/pm2-init.sh
, it says that it cannot dump ( probably because dump exists only in ~/.pm2 directory )
If I try:
sudo $(which pm2) start app.js
sudo $(which pm2) startup systemd -u $USER
sudo $(which pm2) save
and execute manually ( because it can't find pm2 as normal user ) :
sudo ~/.npm-global/pm2 dump && ~/.npm-global/pm2 kill && systemctl daemon-reload && systemctl enable ~/.npm-global/pm2 && systemctl start ~/.npm-global/pm2
So,
1) I am not sure if I have to run sudo $(which pm2) startup systemd -u $USER
or sudo $(which pm2) startup ubuntu -u $USER
2) What PM2 and PM2_HOME should I have?
3) How can I add ~/.npm-global/bin
to sudo path ,or generally how to be able to use this path when I run pm2 as sudo.Note, that I don't want to alter /etc/sudoers.
Upvotes: 1
Views: 2494
Reputation: 11
I can't answer all your questions, but I had the same problem and this worked for me: http://www.anicehumble.com/2016/05/pm2-must-not-be-ran-with-sudo.html
Upvotes: 1