VISWAKUMARAN
Posts: 23
Joined: Thu Dec 19, 2013 11:38 am

Running a program automatically as the Raspberry pi boots up

Tue Dec 31, 2013 11:45 am

I just programmed the raspberry pi to capture & save images at certain regular interval. I need to know whether it is possible to run a particular program automatically whenever the raspberry pi completes booting (i.e. raspberry pi is switched 'on') without requesting any login id or password...
VISWA (*_*)

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Running a program automatically as the Raspberry pi boot

Tue Dec 31, 2013 12:30 pm

/etc/rc.local is executed during the boot as root. Add your commands there and they will be run as root.

VISWAKUMARAN
Posts: 23
Joined: Thu Dec 19, 2013 11:38 am

Re: Running a program automatically as the Raspberry pi boot

Thu Jan 02, 2014 10:50 am

Thank you for your reply... Can you please tell me how should I call the "Image.py" file (which contains the codes that must be executed as soon as the raspi boots up) from the "/etc/rc.locale"...???

Please send me a sample code...

Thank you shuckle...
VISWA (*_*)

shuckle
Posts: 565
Joined: Sun Aug 26, 2012 11:49 am
Location: Finland

Re: Running a program automatically as the Raspberry pi boot

Thu Jan 02, 2014 11:50 am

python image.py

Quite similarly than if you call it from any shell (terminal) program. Except that you need to use full paths.

tfpereira
Posts: 18
Joined: Wed Oct 30, 2013 6:07 pm

Re: Running a program automatically as the Raspberry pi boot

Fri Jan 10, 2014 3:10 pm

Unless you really have a reason to run your application with superuser previleges, I'd recomend using

Code: Select all

su pi -c python image.py 
instead, supossing "pi" is your default, non-super user previleged user.

User avatar
Richard-TX
Posts: 1549
Joined: Tue May 28, 2013 3:24 pm
Location: North Texas

Re: Running a program automatically as the Raspberry pi boot

Fri Jan 10, 2014 3:51 pm

Every startup script is run by root which makes sense if you think about it.

Most of the daemons that do not need root privs su to a different user upon execution.

If your program needs root privs then there is no special changes.

Having said that, if your program does not read any data from users, then it is acceptable to let it run as root.

Put another way. if user "ausr" hacks the account "lusr" then any process owned by "luser" is at risk.


For those critical apps that run in a hostile environment, I lock the pi account, create a new one, assign a good passwd to root and use su, not sudo as needed. Put another way, sudo is a security risk as it requires no password. Might as well just log in as root and be done with it.
Richard
Doing Unix since 1985.
The 9-25-2013 image of Wheezy can be found at:
http://downloads.raspberrypi.org/raspbian/images/raspbian-2013-09-27/2013-09-25-wheezy-raspbian.zip

VISWAKUMARAN
Posts: 23
Joined: Thu Dec 19, 2013 11:38 am

Re: Running a program automatically as the Raspberry pi boot

Thu Jan 30, 2014 12:09 pm

Hello friends thanks for clarifying my doubts. It was really useful for me... I got my code running efficiently... :D
I have a doubt... :|
If I have to stop the program from executing after sometime and to bring the RPi to halt, is it possible to do it by using the os command sudo halt inside the python code... :?:
If there is any other better solution, please let me know... :)
VISWA (*_*)

hk1963
Posts: 25
Joined: Fri Dec 06, 2013 6:06 pm

Re: Running a program automatically as the Raspberry pi boot

Thu Jan 30, 2014 12:27 pm

I've also such an application and decided to run it from the user's crontab with an @reboot entry.
I think it is simpler this way.

Craynerd
Posts: 37
Joined: Mon Nov 25, 2013 9:09 pm

Re: Running a program automatically as the Raspberry pi boot

Tue Feb 04, 2014 7:56 pm

I would also recommend crontab and if needing to run as su, sudo crontab: crontab -e

@reboot python /path/to/file.py &

sej7278
Posts: 249
Joined: Tue Jan 22, 2013 6:43 pm

Re: Running a program automatically as the Raspberry pi boot

Tue Feb 04, 2014 11:28 pm

write an LSB init script using start-stop-daemon manpage

Return to “General programming discussion”