0

This question already has an answer here:

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?

marked as duplicate by Jacobm001, Ghanima Aug 2 '16 at 5:54

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • This will have been covered before. Search for 'systemd'. – Andy Lamb Aug 1 '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 2 '16 at 0: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 2 '16 at 5:54
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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.