0

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?

Milliways
  • 59,890
  • 31
  • 101
  • 209
  • This will have been covered before. Search for 'systemd'. – Andy Lamb Aug 01 '16 at 17:20
  • There are many posts about running programs on boot. As you have not described the program it is difficult to make a recommendation. There are many ways of doing this. You can make a systemd service but it is probably simpler to create a cron job to run on reboot. – Milliways Aug 02 '16 at 00:07
  • Welcome to Raspberry Pi! This question has been closed a duplicate. If the answers from the duplicates don't fully address your question please edit it to include why and flag this for re-opening. Thanks! Please take the tour and visit the helpcenter to see how things work here. – Ghanima Aug 02 '16 at 05:54

1 Answers1

0

See: http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs

Relevant part:

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.

Doesn't work?

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.

Dan McCoy
  • 173
  • 1
  • 2
  • 5