LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   What's the best way to run a conitnuous program at boot? (https://www.linuxquestions.org/questions/linux-software-2/whats-the-best-way-to-run-a-conitnuous-program-at-boot-712364/)

bt101 03-17-2009 06:51 PM

What's the best way to run a conitnuous program at boot?
 
Hi - I need to run a program at boot. It is a perl script that talks to a serial device. The program needs to run forever (never stops). I see there are several ways to start such a program, but can't understand which is the best, especially considering that the program runs forever (not sure if that affects the decision).

I see there is:
-start it in rc.local
-start it in an init.d script
-start it with cron
-make a daemon

No matter what method is used, I am concerned as to whether I need to use an ampersand to run the program in the background so it will detach from the caller so that the caller does not get blocked (dunno if that matters). So I'm leaning to just using cron. If so, do I have it call a script with the ampersand (does it matter).

Thanks

jlinkels 03-17-2009 07:06 PM

It would have been great if you had posted your distro, policy as where to put a program run a boot time varies from one distro to the other.

rc.local is a good candidate I would say.

The cleanest way to do this is like this:

- create a start/stop/restart script. Plenty of examples simple and complicated in init.d. You should be able to pick one and use it.

- it is best to call your script from the script mentioned above, and background it with '&'

- be sure your script does not produce output, or redirect it to /dev/null

- store the pid of the backgrounded process, and store the pid (in a file) so you are able to stop and restart the process. (you don't want to reboot your computer for that, do you?)

jlinkels

bt101 03-17-2009 10:23 PM

Quote:

Originally Posted by jlinkels (Post 3478811)
It would have been great if you had posted your distro, policy as where to put a program run a boot time varies from one distro to the other.

rc.local is a good candidate I would say.

The cleanest way to do this is like this:

- create a start/stop/restart script. Plenty of examples simple and complicated in init.d. You should be able to pick one and use it.

- it is best to call your script from the script mentioned above, and background it with '&'

- be sure your script does not produce output, or redirect it to /dev/null

- store the pid of the backgrounded process, and store the pid (in a file) so you are able to stop and restart the process. (you don't want to reboot your computer for that, do you?)

jlinkels

Ah yes, good point... I'm running Ubuntu Server. No nice interface, but webmin is available for some config stuff. I was most worried about whether to run the script in the backgound (&), so it looks like I had better so it that way. I'll try as you recommend. Thanks.

jlinkels 03-17-2009 10:32 PM

Once you created the script in init.d, don't forget to run update-rc.d to link the correct runlevels to the script. If Ubuntu works the same as Debian.

jlinkels


All times are GMT -5. The time now is 03:46 AM.