Probably just a noob mistake but I've followed these instructions (http://nodered.org/docs/getting-started/running.html#starting-node-red-on-boot) to the letter on a Raspberry Pi 2 but PM2 just doesn't start up, and then obviously neither does node-red. Also, if I manually start PM2, the node-red still doesn't start. Yes, I've done the pm2 save, pm2 startup, all according to the instructions. Strangely when I did all this on an RPi 1 it all worked like a charm. Any ideas?
I just tried it myself, the problem I had is that my user doesn't have the permissions to run pm2 startup. When I run sudo pm2 startup it runs but I don't get any pm2 processes started on startup. The way it works for me is when I do it all as root.
sudo pm2 start /home/pi/app.js
sudo pm2 save
sudo pm2 startup
Yep, tried everything with and without sudo. No errors reported. dump.pm2 is there and references node-red (can't tell if the whole of dump.pm2 is correct though). Weird huh?
Still trying to figure this out. I've installed on clean setups a couple of dozen times with various simple variations, all get the same result: PM2 does not auto-start. Manually starting PM2 is fine but does not start the app that was saved. PM2 appears to be working in every other way. Would uploading my dump.pm2 and pm2-init.sh help anybody help me?
Have you tried with pm2 startup systemd ?
Finally got around to trying it. Got this:
_pi@raspberrypi ~ $ pm2 startup systemd_
_[PM2] You have to run this command as root. Execute the following command:_
_----- Are you sure you use the right platform command line option ? centos
/ red hat, amazon, ubuntu, gentoo, systemd or darwin?_
_pi@raspberrypi ~ $_
On the node-red site though a clever chap suggesting editing pm2-init.sh to
say:
export PM2_HOME="/root/pi/.pm2"
instead of
export PM2_HOME="/root/.pm2"
And that seems to do the trick.
Jon Richings | Original Design & Development | 801-704-9166 | _www.anoddco.com
http://www.anoddco.com_
This email and it's attachments may be confidential and are intended solely
for the use of the individual to whom it it addressed. If you are not the
intended recipient of this email and it's attachments, you must take no
action based upon them, nor must you copy or show them to anyone.
Please contact the sender if you believe you have received this email in
error.
On Wed, Jun 10, 2015 at 5:04 AM, Alexandre Strzelewicz <
[email protected]> wrote:
Have you tried with pm2 startup systemd ?
—
Reply to this email directly or view it on GitHub
https://github.com/Unitech/PM2/issues/1316#issuecomment-110700864.
Heh, I ran into the same issue and it looks like the original node-red instructions you linked to were updated with the following, which worked for me:
_Temporary Note:_ There's an open issue on PM2 on GitHub which highlights an issue that has been introduced recently. Linux users need to manually edit the generated /etc/init.d/pm2-init.sh file and replace
export PM2_HOME="/root/.pm2"
to point at the correct directory, which would be like:
export PM2_HOME="/home/{youruser}/.pm2"
Two things:
1) The solution by @GlennGeenen worked for me; sudo everything. However, that means your node scripts are running as user "root" (never good)
2) Ultimately I had to use the fix by @elmedico27
I've found either way it takes a few moments for the scripts/services to restart (up to a minute or so after boot)
Hey guys,
autostart does not work here... I've tried (almost) everything...
Machine: Raspberry 2 (Raspbian Jessie)
This is what I've ended up with:
Installed pm2
$ npm install -g pm2
Ran install script as pi user
$ sudo pm2 startup raspberry -u pi
[PM2] Generating system init script in /etc/init.d/pm2-init.sh
[PM2] Making script booting at startup...
[PM2] -raspberry- Using the command:
su -c "chmod +x /etc/init.d/pm2-init.sh && update-rc.d pm2-init.sh defaults"
[PM2] Done.
As you've mentioned, the script refers to the wrong .pm2 folder (looks in the root folder, not the user's folder), so I changed that
$ sudo vi /etc/init.d/pm2-init.sh
Changed export PM2_HOME="/root/.pm2" to export PM2_HOME="/home/pi/.pm2"
Went into my project's folder
$ cd /opt/mycoolnodeproject
Started my node project with pm2
$ pm2 start server.js -x --name "cool-node-project"
Saved active processes for restart
$ pm2 save
So now the server is up and running and works fine... until I reboot! I thought that pm2 would autostart my node application, but for some reason it doesn't... :( No chance...
Any idea what the problem might be?
Btw: I've also tried to call the startup cmd like this sudo env PATH=$PATH:/usr/local/bin pm2 startup raspberry -u pi, but that didn't work either.
Regards,
Sascha
I'm also having this problem, even after the fix in /etc/init.d/pm2-init.sh
I'm on raspberry pi.
EDIT: If you are on Raspbian Jesse, solution here: https://github.com/Unitech/pm2/issues/1654
I was just about to post my whole pm2-init.sh here -- glad you all got it figured out. And thanks for alerting me to Raspbian Jessie, I hadn't realized there was a new version!
I had the problems mentioned here where PM2 was running as root and deploy users.
The fix from @elmedico27 worked fine :)
Thanks!
Thanks @elmedico27 , i think this issues has solved , yay :+1:
im not sure which fix worked for me - but we tried teh fix from @elmedico27 and a fix in another bug report that set the .pm2/dump.pm2 to immutable:
chattr +i /home/
it seems that we need to do both for pm2 to survive a restart. yeah for the internet!
Will be fixed on the next PM2 release #1035
:+1:
In my case, for this issue when i want start a script whith PM2 as deploy user :
As root
npm uninstall pm2
As deploy (su deploy)
sudo npm i -g pm2
End now, deploy can use PM2.
Enjoy :)
I had this issue when the disk was 100% full. Had to clear the logs to start the pm2 as non root user and worked for me.
Most helpful comment
I just tried it myself, the problem I had is that my user doesn't have the permissions to run
pm2 startup. When I runsudo pm2 startupit runs but I don't get any pm2 processes started on startup. The way it works for me is when I do it all as root.