I want to run a program continuously on RPi but the problem is power off. Once it is turned off and then when I turn it ON i have to do all the process of login in and running the program again. What should I do to avoid it. How can I put a program on auto run?
Auto running terminal applications (non GUI)
First ensure your program is executable by finding it in the file manager. Right click on the file and select properties. Select the permissions tab, check the ‘Make the file executable’ box and press OK. Or from the command line use:
sudo chmod +x /home/pi/projects/my_project.a Or using a different tool set its chmod to 755 (rwxr-xr-x). It doesn't matter if the user is root.
We've found that when copying a new file to the rpi using WinSCP, changing its properties to 755 and verifying all is OK that if we kill the power and power up again the executable doesn't run. However if we use sudo reboot at the command line it works as it should. It seems there is some sort of caching action going on so after doing this use sudo reboot the first time rather than cycling the power!
You can setup the auto run using a script (see here), or you can do it directly by editing the rc.local file:
sudo nano /etc/rc.local
After the initial comments (lines beginning with '#') add the following lines:
Auto run our application sudo /home/pi/projects/my_project.a & "sudo" assumes you want your application run with root user privileges
(remove if not) and the "&" says do it in the background.
Save it by pressing Ctrl+X, " Y", ENTER
Re-boot your RPi and it will run.