Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Starting node app at startup on raspberry pi

EDIT: As per Jim Rush's advice I'm now using rc.local instead of init.d direclty to run forever start on boot up.

I'm wracking my head on this one.

I'm wanting to start a node app on the raspberry pi startup and reboot. I'm using forever to actually call the app and using init.d for the debian style start instructions.

I've created the kuuyi file within the /etc/init.d directory, given it a permission of 755 and, after editing the file, ran update-rc.d kuuyi defaults to hopefully trigger Raspbian to start it on restart/boot.

Here's my init.d file:

#!/bin/sh
#/etc/init.d/kuuyi

### BEGIN INIT INFO
# Provides:             kuuyi
# Required-Start:
# Required-Stop:
# Default-Start:        2 3 4 5
# Default-Stop:         0 1 6
# Short-Description:    Kuuyi
### END INIT INFO

case "$1" in
start)
/usr/local/bin/forever --sourceDir=/home/pi/kuuyi_device  -p /root/.forever run.js
;;
stop)
/usr/local/bin/forever stop --sourceDir=/home/pi/kuuyi_device run.js
;;
*)

echo "Usage: /etc/init.d/kuuyi {start|stop}"
exit 1
;;
esac
exit 0

Any ideas as to why this isn't working? I'm running Raspbian on a Raspberry Pi B+. I've run /etc/init.d kuuyi start and forever kicks and begins the app just fine. Its just not happening after booting up the machine.

Any help on this is so appreciated, I'm about as wrung out as an old cheese cloth after dairy day on this one.

like image 989
risingtiger Avatar asked May 05 '15 04:05

risingtiger


People also ask

How do I autostart a program on Raspberry Pi?

Choose Applications -> Preferences -> Default applications for LXSession from your Pi desktop. Select the Autostart tab. In the Manual autostarted applications section enter the text of your command in the box next to the Add button. Then click the Add button and your new command should be added to the list.

Is Node JS good for startup?

Node. js is a great platform for startups because it enables them to build highly scalable systems without requiring any special expertise or knowledge on server-side programming like Java or . Net. A start-up can save time and money by using Node.


1 Answers

I run node (actually nodemon) from /etc/rc.local. Just the command line with & at the end. I also redirect stderr and stdout to log files to troubleshoot startup and crash problems. Getting the permissions right, on any directory that was written to, was one of my early problems.

Example:

PATH=$PATH:/opt/node/bin
cd /var/node/RoadsterNode
/opt/node/bin/nodemon /var/node/RoadsterNode/app.js < /dev/null >/var/tmp/startup.log 2>/var/tmp/startup.err &
like image 115
Jim Rush Avatar answered Oct 11 '22 03:10

Jim Rush