Running an .sh file via /etc/rc.local on RPi for autostart

282 views
Skip to first unread message

George K

unread,
Jun 19, 2016, 7:25:05 AM6/19/16
to Node-RED
Hello guys

I'm in need for your help, to get some Linux stuff autorunning.

My goal is to start an .sh file from a RPi. in autostart. The .sh File looks like this and just starts a specific flow (samsung.json) with port 1882. The .sh and .json files are both in the directory.








So far I've researched and found some methods to do this. As far as I can tell, the easiest way for me would be to add an entry in the /etc/rc.local file. Unfortunately so far It doesn't work.
And this is how my /etc/rc.lcoal file looks like. I've also tried with and without bash. As my research has shown, the method without bash should be working. As a Linux Newbie, I've tried both methods.































As far as I know the /etc/rc.local will execute as root. So I've tested the .sh file both as User PI and su. Both are working as you can see. This test was important because additional flows are taken from another directory when using different users. So I've installed them and no matter which user, both are working. 

Login as user pi:






















Login as su






















Just for info, I've made the file executable as you can see here:



Maybe you guys see what I'm missing.

I know there are several methods listed to autorun node-red here: http://nodered.org/docs/getting-started/running and specific on RPi here: http://nodered.org/docs/hardware/raspberrypi. But the problem with them is, that i don't understand so far, where I can decline which flow.json file and port I want to use. That's why I created my .sh file in my repository. So, If you find any other way achieving my goal, I would also be totally satisfied. 

Thanks in advance

Julian Knight

unread,
Jun 19, 2016, 10:55:48 AM6/19/16
to Node-RED
Did you set the executable flag on the shell file?

If you are using a Jessie based version of Rasbian, you might want to look at using systemd instead of rc.local

That is the current, recommended way of ensuring services start up and remain up.

I think there are some posts in the group somewhere about using systemd to run node-red. If not, I can dig out my script later, I have to go out shortly.

Nicholas O'Leary

unread,
Jun 19, 2016, 11:01:09 AM6/19/16
to Node-RED

No need to point to random posts in the mailing list when our raspberry pi specific docs have everything you need:

http://nodered.org/docs/hardware/raspberrypi.html

Just search for 'adding Autostart capability...'. As you want it to run on a non default port, you can either do that via your settings file, or modify the systemd file config to pass the appropriate command line parameters.

Nick


--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
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.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
For more options, visit https://groups.google.com/d/optout.

George K

unread,
Jun 19, 2016, 11:52:09 AM6/19/16
to Node-RED
Hello Julin, Hello Nick

Thank you for your answers.

@Julian Yes I think I did that with "chmod u+x node-red-samsung.sh" and as shown in the last picture.

Yes, probably It would be the best thing to use the inbuilt systemd for my purpose. 

My idea originally was to create isolated repositories which can be dl on an RPi and let them autorun on startup by editing the rc.local. The flows.json would be different and the used port in the settings.js file would be different. I don't know if it was a good idea, but it was something I tried and thought I could maybe achieve with rc.local. But I've spent way too much time with it and I'm really new into the Linux Environment. So...

As I see it now, the best thing to do is to follow the recommended way :). I'll just move my flow.json and settings.js file to the directory. That way, using systemd, would also be better than setting it up on rc.local, as far as I understand it (for logging and ensuring purposed).

Thanks again and have a nice evening
Reply all
Reply to author
Forward
0 new messages