Any script I try running at startup does not work

@BigP0P5 I spent ages last night trying to get the script to run on reboot with the Pi. It runs fine on the Omega 2+ just in rc.local. Sometimes it worked with the Pi but sometimes it didn’t.

As pointed out by @Lichtsignaal the definitive method normally recommended is with /etc/init.d but even that sometimes fails on the Pi for node. The service in /etc/init.d will be running but not node.

So it requires the npm package forever and forever-service.

sudo cp /path_to_blynk-test.js/blynk-test.js /home/pi/app.js
sudo npm install forever -g
sudo npm install forever-service -g
sudo forever-service install BlynkService

Check if everything is working with:

sudo service BlynkService start
sudo service BlynkService status
sudo service BlynkService stop
sudo service BlynkService restart

Then you can use the easy start on reboot method:

sudo nano /etc/rc.local
sudo service BlynkService start
sudo shutdown -r now

After reboot the following will confirm the script and service is running

ps aux | grep node
sudo service BlynkService status
service --status-all | grep BlynkService

You will not see the Console but a full log will go to /var/log/BlynkService.log including any error messages for incorrect path’s etc. If the console is important you can always tail the log with:

tail -f /var/log/BlynkService.log

Tested and working flawlessly on one of my Pi’s but be patient waiting for the service to start.

See https://causeyourestuck.io/2016/04/30/run-node-js-script-startup/ and http://www.slidequest.com/q/70ang for further details

1 Like