-
- Posts: 23
- Joined: Thu Dec 19, 2013 11:38 am
Running a program automatically as the Raspberry pi boots up
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 (*_*)
Re: Running a program automatically as the Raspberry pi boot
/etc/rc.local is executed during the boot as root. Add your commands there and they will be run as root.
-
- Posts: 23
- Joined: Thu Dec 19, 2013 11:38 am
Re: Running a program automatically as the Raspberry pi boot
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...
Please send me a sample code...
Thank you shuckle...
VISWA (*_*)
Re: Running a program automatically as the Raspberry pi boot
python image.py
Quite similarly than if you call it from any shell (terminal) program. Except that you need to use full paths.
Quite similarly than if you call it from any shell (terminal) program. Except that you need to use full paths.
Re: Running a program automatically as the Raspberry pi boot
Unless you really have a reason to run your application with superuser previleges, I'd recomend using
instead, supossing "pi" is your default, non-super user previleged user.
Code: Select all
su pi -c python image.py
- 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
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.
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
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
-
- Posts: 23
- Joined: Thu Dec 19, 2013 11:38 am
Re: Running a program automatically as the Raspberry pi boot
Hello friends thanks for clarifying my doubts. It was really useful for me... I got my code running efficiently...
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...

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 (*_*)
Re: Running a program automatically as the Raspberry pi boot
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.
I think it is simpler this way.
Re: Running a program automatically as the Raspberry pi boot
I would also recommend crontab and if needing to run as su, sudo crontab: crontab -e
@reboot python /path/to/file.py &
@reboot python /path/to/file.py &
Re: Running a program automatically as the Raspberry pi boot
write an LSB init script using start-stop-daemon manpage