1

I am developing an application based project and I am almost done with it. Now I need to covert that to a commercial level product. As it is application specific I want my code to run as soon as I power up my pi. Is there any method to run a code without giving commands through gui or even a trigger through a gpio port will do.

4

[edit] @Ghanima's answer is way better than this one, go check it !

You could use cron and add an @reboot task: Running crontab -e as root or sudo crontab -e will allow you to edit your cron. Add this:

@reboot /path/to/script

will execute that script once your computer boots up.

2

To start anything on boot you just add command to /etc/rc.local

So something like:

/path/to/script

Don't forget to change permission of the script to execute (chmod +x /path/to/script)

  • Also don't forget to fork that into the background with & unless it is something that does so itself, or exits immediately. – goldilocks Jun 5 '15 at 14:37
1

There is nothing wrong with the aformentioned solutions of cron and rc.local but there are also other nice tools out there that help you do that and bring additional benefit.

supervisor is such a system to monitor and control a number of processes on UNIX-like operating systems. Nice benefit is that it not only starts programs at boot time but also tries to restart them if they fail and crash. Follow the excellent documentation to set it up and configure multiple conditions according to the needs of the project.

  • This is indeed way better than using cron ! Thanks for the info ! – Zabka Nov 27 '15 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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