PM2 Not Working for RPi 2?

734 views
Skip to first unread message

JethroNull

unread,
May 25, 2015, 12:52:34 PM5/25/15
to node...@googlegroups.com
Apologies this is more about PM2 than Node-Red but I suspect that the "starting-node-red-on-boot" instructions for setting up PM2 may need some tweaking for RPi2.  I had followed those instructions to the letter for a RPi 1 and everything was fine, but I can't get it to work on a Pi 2.  PM2 installs and operates fine, but the startup script doesn't seem to take, or at least there is no sign that PM2 itself boots on startup, and hence no Node-Red either.  Everything in the install is plain vanilla, as per the Raspian and Node-Red instructions.  Any ideas?

Dave C-J

unread,
May 25, 2015, 1:10:45 PM5/25/15
to node...@googlegroups.com
try....

after the first few steps... ie. you have started it manually using pm2...  it says 
    pm2 save

at this point it should have created a file in ~/.pm2 called dump.pm2 
mine is about 4k in size and starts....
     [{args:["-v"],name:"node-red",max_memory_restart:134217728,exec_mode:"fork_mode",exec_interpreter:"node",pm_exec_path:"/usr/bin/node-red" 
If it doesn't exist or doesn't mention node-red....  then try
   pm2 dump
to see if that creates it...

If it does exist.... try making it read-only - so I t can't get blasted by anything else....
   chmod 444 ~/.pm2/dump.pm2


Jon Richings

unread,
May 25, 2015, 1:44:06 PM5/25/15
to node...@googlegroups.com
The dump.pm2 is there and it seems to be configured OK (or at least it has references to node-red), but it seems that PM2 itself doesn't start.  After a reboot, when you'd expect PM2 to have started and then started node-red, if I enter pm2 list (which previously would just have shown node-red) it says "Spawning PM2 daemon" and then show an empty list, as though PM2 was not already running.

--
http://nodered.org
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/_dcKHpmrKrQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nicholas O'Leary

unread,
May 25, 2015, 5:33:41 PM5/25/15
to Node-RED Mailing LIst
Hi Jon,

when you ran "pm2 startup", you would have got something like:

$ pm2 startup
[PM2] Spawning PM2 daemon
[PM2] PM2 Successfully daemonized
[PM2] You have to run this command as root. Execute the following command:
      sudo env PATH=$PATH:/opt/node/node-v0.10.36-linux-x64/bin pm2 startup linux -u nol


Note the comment at the end - did you run that command it tells you to? (Don't just copy the version above.... it is specific to you environment)

If you had run it, you'll should have the file /etc/init.d/pm2-init.sh ?

Nick

--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

Jon Richings

unread,
May 25, 2015, 9:40:09 PM5/25/15
to node...@googlegroups.com
Yup, followed the instructions.  It created the following file in /etc/init.d/  .


    local shell=$(get_user_shell $USER)
    su - $USER -s $shell -c "PATH=$PATH; PM2_HOME=$PM2_HOME $*"
}

start() {
    echo "Starting $NAME"
    super $PM2 resurrect
}

stop() {
    super $PM2 dump
    super $PM2 delete all
    super $PM2 kill
}

restart() {
    echo "Restarting $NAME"
    stop
    start
}

reload() {
    echo "Reloading $NAME"
    super $PM2 reload all
}

status() {
    echo "Status for $NAME:"
    super $PM2 list
    RETVAL=$?
}

case "$1" in
    start)
        start
        ;;
    stop)
        stop
        ;;
    status)
        status
        ;;
    restart)
        restart
        ;;
    reload)
        reload
        ;;
    force-reload)
        reload
        ;;
    *)
        echo "Usage: {start|stop|status|restart|reload|force-reload}"
        exit 1
        ;;
esac
exit $RETVAL


JethroNull

unread,
May 26, 2015, 9:12:13 PM5/26/15
to node...@googlegroups.com
PM2 just doesn't seem to start itself on reboot, but manually starting PM2 doesn't start Node-Red either.  But as far as I can see there are no errors and all files that should be expected are created and look fine.  This is the sequence I get when running PM2 startup.  I didn't get this with original RPi 1's but I guess I can expect a few things to be different with RPi 2.

pi@raspberrypi ~ $ pm2 startup
[PM2] You have to run this command as root. Execute the following command:
      sudo env PATH=$PATH:/usr/bin pm2 startup linux -u pi
pi@raspberrypi ~ $ sudo env PATH=$PATH:/usr/bin pm2 startup linux -u pi
[PM2] Generating system init script in /etc/init.d/pm2-init.sh
[PM2] Making script booting at startup...
[PM2] -linux- Using the command:
      su -c "chmod +x /etc/init.d/pm2-init.sh && update-rc.d pm2-init.sh defaults"
update-rc.d: using dependency based boot sequencing
[PM2] Done.

Geoffrey Arnold

unread,
May 26, 2015, 9:59:22 PM5/26/15
to node...@googlegroups.com
Hey Jon,

Just to cover all bases, are you actually registering Node-RED with PM2 using `pm2 start ...`?  Here's our Node-RED install script for reference:


Best,
Geoff. 
--

JethroNull

unread,
May 26, 2015, 10:09:21 PM5/26/15
to node...@googlegroups.com
Yeah, actually "pm2 start /usr/bin/node-red --node-args="--max-old-space-size=128" -- -v" from the nodered.org/docs/getting-started/running.html

I'll admit that I'm the noobiest of them all as far as Linux stuff goes but didn't have any issues getting Node-Red and PM2 running a couple of weeks ago on an RPi 1.  Either something changed with RPi two or something in one of packages did.

Thanks Geoff.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

JethroNull

unread,
Jun 3, 2015, 11:14:11 AM6/3/15
to node...@googlegroups.com
Hopefully somebody is still following this thread.  More strangeness:  I discovered that Node-Red IS starting (if I leave it long enough), but PM2 doesn't seem to be the reason and doesn't show node-red in its list.  So I looked at the processes running (ps axjf) and got this (boring stuff deleted):


   
0     1     1     1 ?           -1 Ss       0   0:00 init [2]
   
1   174   174   174 ?           -1 Ss       0   0:00 udevd --daemon
 
174   287   174   174 ?           -1 S        0   0:00  \_ udevd --daemon
 
174   325   174   174 ?           -1 S        0   0:00  \_ udevd --daemon
   
1  1516  1515  1515 ?           -1 S        0   0:00 /usr/sbin/ifplugd -i eth0 -q -f -u0 -d10 -w -I
   
1  1535  1534  1534 ?           -1 S        0   0:00 /usr/sbin/ifplugd -i lo -q -f -u0 -d10 -w -I
   
1  1868  1868  1868 ?           -1 Ss       0   0:00 /bin/sh /etc/init.d/rc 2
 
1868  1877  1868  1868 ?           -1 SL       0   0:00  \_ startpar -p 4 -t 20 -T 3 -M start -P N -R 2
 
1877  2264  2264  1868 ?           -1 S        0   0:00      \_ /bin/sh /etc/init.d/rc.local start
 
2264  2270  2264  1868 ?           -1 S        0   0:00          \_ /bin/sh -e /etc/rc.local
 
2270  2272  2264  1868 ?           -1 S        0   0:00              \_ /bin/bash /usr/bin/node-red-pi --max-old-space-size=128
 
2272  2282  2264  1868 ?           -1 Sl       0   0:21                  \_ node-red
   
1  1928  1928  1928 ?           -1 Ss   65534   0:00 /usr/sbin/thd --daemon --triggers /etc/triggerhappy/triggers.d/ --socket /var/run/thd.socket --pidfile /var/run/th
   
1  1972  1894  1868 ?           -1 Sl       0   0:00 /usr/sbin/rsyslogd -c5
   
1  2092  2092  2092 ?           -1 Ss       0   0:00 /usr/sbin/cron
   
1  2105  2105  2105 ?           -1 Ss     104   0:00 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 104:107
   
1  2141  2141  2141 ?           -1 Ss     102   0:00 /usr/bin/dbus-daemon --system
   
1  2162  2162  2162 ?           -1 Ss       0   0:00 /usr/sbin/sshd
 
2162  2293  2293  2293 ?           -1 Ss       0   0:00  \_ sshd: pi [priv]
 
2293  2307  2293  2293 ?           -1 S     1000   0:00  |   \_ sshd: pi@pts/0
 
2307  2308  2308  2308 pts/0     2327 Ss    1000   0:00  |       \_ -bash
 
2308  2322  2322  2308 pts/0     2327 T     1000   0:00  |           \_ top
 
2308  2327  2327  2308 pts/0     2327 R+    1000   0:00  |           \_ ps axjf
 
2162  2297  2297  2297 ?           -1 Ss       0   0:00  \_ sshd: pi [priv]
 
2297  2305  2297  2297 ?           -1 S     1000   0:00      \_ sshd: pi@notty
 
2305  2306  2306  2306 ?           -1 Ss    1000   0:00          \_ /usr/lib/openssh/sftp-server
   
1  2189  2188  2188 ?           -1 S      103   0:00 avahi-daemon: running [raspberrypi-2.local]
 
2189  2191  2188  2188 ?           -1 S      103   0:00  \_ avahi-daemon: chroot helper
   
1  2213  2213  2213 ?           -1 Ssl      0   0:03 PM2 v0.12.15: God Daemon
   
1  2262  2262  2262 ?           -1 Ss       0   0:00 /sbin/dhcpcd



Running pm2 list got this, which looks to me like PM2 was not responsible for Node-Red running....
 
pi@raspberrypi
~ $ pm2 list
[PM2] Spawning PM2 daemon
[PM2] PM2 Successfully daemonized
+----------------------------------------------------------------------------+
¦ App name ¦ id ¦ mode ¦ pid ¦ status ¦ restart ¦ uptime ¦ memory ¦ watching ¦
+----------------------------------------------------------------------------+
 
Use `pm2 show <id|name>` to get more details about an app
pi@raspberrypi
~ $ ^C
pi@raspberrypi
~ $


Or is PM2 actually running but not showing it's processes correctly?

Really, really need to get to the bottom of this, hope someone can help.

Jon

Nicholas O'Leary

unread,
Jun 3, 2015, 11:18:41 AM6/3/15
to Node-RED Mailing LIst
Any references to node-red in   /etc/rc.local   ? Looks to me like something has added a command to start node-red in there.

Nick

--
http://nodered.org
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

JethroNull

unread,
Jun 3, 2015, 1:46:25 PM6/3/15
to node...@googlegroups.com
Yes:

pi@raspberrypi /etc $ nano rc.local
  GNU nano
2.2.6                                             File: rc.local


# By default this script does nothing.


# Print the IP address
_IP
=$(hostname -I) || true
if [ "$_IP" ]; then
  printf
"My IP address is %s\n" "$_IP"
fi


/usr/bin/node-red-pi --max-old-space-size=128
exit 0

I'm pretty sure I didn't do this, or at least not by hand.  I don't know how that got there.  Could PM2 have done that under some circumstance.  This is still a pretty much vanilla setup and, as I said before, the same setup worked fine on an earlier Pi 1.

Also, do you think I'm right in now thinking that PM2 does appear to be running (PM2 v0.12.15: God Daemon)?

I had previously assumed that because I got something like "PM2 daemon starting" when I ran "PM2 list" at startup meant that it was not already running.  Maybe that was faulty logic.  In which case we've narrowed it down to PM2 running but not fulfilling it task list?

JethroNull

unread,
Jun 3, 2015, 3:59:52 PM6/3/15
to node...@googlegroups.com
I've lost count of the number of times I tried this from a clean Raspbian install, but I noticed something that maybe I should not have been ignoring:

When I get to the pm2 startup bit I get:

pi@raspberrypi ~ $ pm2 startup
[PM2] You have to run this command as root. Execute the following command:
      sudo env PATH
=$PATH:/usr/bin pm2 startup linux -u pi
pi@raspberrypi
~ $  sudo env PATH=$PATH:/usr/bin pm2 startup linux -u pi
[PM2] Spawning PM2 daemon
[PM2] PM2 Successfully daemonized
[PM2] Generating system init script in /etc/init.d/pm2-init.sh
[PM2] Making script booting at startup...
[PM2] -linux- Using the command:
      su
-c "chmod +x /etc/init.d/pm2-init.sh && update-rc.d pm2-init.sh defaults"
update
-rc.d: using dependency based boot sequencing
[PM2] Done.



Now is that line -
su -c "chmod +x /etc/init.d/pm2-init.sh && update-rc.d pm2-init.sh defaults"

saying that it's done that, or that I need to?  It's grayed out like the previous request to execute:
sudo env PATH=$PATH:/usr/bin pm2 startup linux -u pi

(which I run) but reads just like a notice not a command.

Out of curiosity I've tried to run it but get errors with any variation (the chmod stuff is ok).

Clutching at straws here.  Has anybody actually tried the complete by-the-book raspbian/node/node-red/pm2 install on a Rpi 2 with success?
...

austin sandford

unread,
Jun 3, 2015, 6:43:07 PM6/3/15
to node...@googlegroups.com
I tried it a few months ago, but PM2 wouldn't start on boot.

I thought that it might have something to do with systemd not running thru' the init scripts like sysv init does (loads of messages on the 'upgrade' to jessie saying that init scripts are depricated).

Jon Richings

unread,
Jun 3, 2015, 6:46:21 PM6/3/15
to node...@googlegroups.com
I'm not Linuxie enough yet to understand that but really pleased to know it's not me thats mad.  From your experience does that mean I'm wasting my time?  Should I be using Forever or something else?

--
http://nodered.org
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/_dcKHpmrKrQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.

Dave C-J

unread,
Jun 4, 2015, 2:38:28 AM6/4/15
to node...@googlegroups.com

Pm2 should now also support systems, but has to be configured slightly differently. I think you need
    pm2 startup systemd
to configure it.. I haven't yet tried this. Can anyone confirm, provide feedback, etc ?

Mark Setrem

unread,
Jun 4, 2015, 6:06:47 AM6/4/15
to node...@googlegroups.com

There appears to be a recent change in pm2, within the pm2-init.sh file it is pointing to the incorrect .pm2 file
If you edit the /etc/init.d/pm2-init.sh file and replace

export PM2_HOME="/root/.pm2"

to point at the correct directory,which in my case is:

export PM2_HOME="/home/myuser/.pm2"

save and reboot you should find it now works.

The other thing to remember is on startup pm2 restarts the apps that were previously running the last time the PM2 server was shutdown.
So it is important to go through the step of running

Mark Setrem

unread,
Jun 4, 2015, 6:09:44 AM6/4/15
to node...@googlegroups.com
Should have said this is on Rasbian Wheezy, I'm leaving Rasbian Jessie for people with far more spare time on their hands than I have!

Dave C-J

unread,
Jun 4, 2015, 9:20:50 AM6/4/15
to node...@googlegroups.com
Thanks Mark... is that a "bug" they are going to fix ? or because they added the -u flag ? (which allows you to set the user... which if you don't and run it as root will then be /root... ? - just guessing). ie would running 
    pm2 startup -u pi
do the right thing ? 


Dave C-J

unread,
Jun 4, 2015, 10:19:52 AM6/4/15
to node...@googlegroups.com
hmm - just tried it myself and no...  so for Wheezy ... read Mark's fix 3 post above.

Mark Setrem

unread,
Jun 4, 2015, 10:38:52 AM6/4/15
to node...@googlegroups.com
There's an open issue on pm2 on GitHub
Which acknowledges the issue https://github.com/Unitech/PM2/issues/1321

But thought it was easier just to edit the file



Dave C-J

unread,
Jun 4, 2015, 12:42:30 PM6/4/15
to node...@googlegroups.com
great - and thanks.

Jon Richings

unread,
Jun 4, 2015, 12:46:59 PM6/4/15
to node...@googlegroups.com

Guys, thank you.  I can't try this out till later today, but I really appreciate the input.  I'll report back asap.

On Jun 4, 2015 10:42 AM, "Dave C-J" <dce...@gmail.com> wrote:
great - and thanks.

Jon Richings

unread,
Jun 4, 2015, 6:24:07 PM6/4/15
to node...@googlegroups.com
Yup, that worked - thanks Mark!.  Took me a while to find .pm2 (for future ref. a standard PM2 installation following the Node-Red instructions on a standard RPi 2 with Wheezy puts .pm2 in /home/pi).  Dave & Nick, might be worth creating a link to this thread in the Node-Red/Pm2 install instructions till PM2 get's sorted out.

Thank you all so much:)

Dave C-J

unread,
Jun 4, 2015, 6:41:26 PM6/4/15
to node...@googlegroups.com

Docs already updated :-)

JethroNull

unread,
Jun 4, 2015, 9:59:41 PM6/4/15
to node...@googlegroups.com
OK, not sure if this is a related symptom or something I messed up while blundering around in the dark:  PM2 now start fine, Node-Red starts fine, everything runs as it did on RPi 1, except that file writes from flows (which don't happen very often so I didn't see it straight away) are getting eaccess errors.  Could the PM2 issue/fix have caused this?

On Thursday, June 4, 2015 at 4:41:26 PM UTC-6, Dave C-J wrote:

Docs already updated :-)

Mark Setrem

unread,
Jun 5, 2015, 7:25:23 AM6/5/15
to node...@googlegroups.com
One reason for EACCESS errors are permissions.

Where are you trying to write to?  Does the user who is running pm2 have permission to write to that directory or file?

For example if I try to write to /home/bob/output.txt as user "myuser" I get the following error as it doesn't have permission to write to that directory

Failed to append to file : Error: EACCES, open '/home/bob/output.txt'

However if I write to  '/home/myuser/output.txt' I can confirm it works under a NR on a RPi2 using pm2.  

Jon Richings

unread,
Jun 5, 2015, 12:50:16 PM6/5/15
to node...@googlegroups.com
I have a vague grasp on permissions when doing stuff in the shell but not how permissions apply to PM2/node-red.  Since I installed pm2 and node-red in the prescribed fashion (sudo'ing things that would care) I assume they would inherit sudo-like (or pseudo-sudo?) permissions, hence root permissions (?).  The same setup had worked all the time I was manually starting node-red via PM2.  The flow in node-red used a file node with a filename, no path at all.  So I guess wherever node-red would put that by default had become verboten to pm2/node-red.  So I followed your logic and added /home/pi/ to the file name and, yippee, it works.  I'm not fussed about where the file is saved so this has me happy.  But I am still curious as to whether the issue/fix with PM2 had something to do with this change in behaviour.

--

Dave C-J

unread,
Jun 5, 2015, 1:47:50 PM6/5/15
to node...@googlegroups.com
hmmm ... will investigate...

Mark Setrem

unread,
Jun 5, 2015, 2:29:16 PM6/5/15
to node...@googlegroups.com
So where was it writing the file previously? To your home account or to the root directory?

I've always found I had to list the full path name to use the file-out node (although my main Node-red instance runs on a Mac Mini and I just used the same flows on my "test" node-red instances.


You are running node-red through pm2 you will be running under which ever user you set it up under in your case I'm guessing is the user pi.

You can check this by running the command to list the processes running ps -ef
and to whittle out the stuff you don't need send that ( called piping it) to the grep command to only show lines that include node
so the command becomes

"ps -ef | grep node"

when the lines are displayed the first bit is the user running the command and the processID some other stuff and eventually the command name node-red.

If you hadn't included the path running as pi it would have been trying to write to the root directory as the user pi.
As that user wouldn't have permission to write there you got the error.

Jon Richings

unread,
Jun 5, 2015, 3:36:26 PM6/5/15
to node...@googlegroups.com
"ps -ef | grep node" returned "pi" as you suspected.  Thanks for that useful tidbit Mark.

I'm not sure where it was writing the file previously, since it's purpose was just to save some configuration for my flow, as long as it worked I didn't take any notice.  Apart from the PM2 fix I was running it the same way before without error so I'm still suspecting that the PM2 change or editing that PM2 file changed the permissions or where node-red defaults to saving files.

Reply all
Reply to author
Forward
0 new messages