LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Using cron to start a program at reboot ? (https://www.linuxquestions.org/questions/linux-general-1/using-cron-to-start-a-program-at-reboot-24003/)

s&j 06-21-2002 03:57 PM

Using cron to start a program at reboot ?
 
:Pengy:
I have a program that I want to run as a service on my linux machine i.e. it should always be executing. After a system reboot it should start running automatically without any user intervention.

I was thinking of using cron to somehow schedule the program to launch after every reboot but I am not sure if that what I should be using.

Are there any other methods to convert existing programs into programs that get launched automatically at boot time ? I read something about daemons but do not know much about them or how to programs them.

Any suggestions or pointers will be of great help.

Thanks !!

Road 06-21-2002 05:34 PM

No that is not what your should be doing.

Linux already has built in run level's to allow to have programs start at different times. (Runlevels are like safemode for windows)
For example run level3 is normal mode why level1 is safe mode. Now if your running X windows then level 5 is normal mode.

Now depending on what flavor of linux you have you can either be using the system V init or the free bsd type.

Assuming that its a system V start up you will look in your etc directory and notice the
init.d
Look in that directory and you will notice a bunch of startup scripts these are the scripts that are used to start the proccess at different run levels.

Now look back in etc and look for directorys that start with rc
Example
rc0.d
rc1.d
rc3.d
If you look those directories you will find symbolic links to the init.d directory I showed you ealier. Depending on what runlevel you are starting (3 for consol only and 5 for xwindows) by using the name convention it will tell you what process's start and what ones should be killed.
so a symbolic link called S80httpd
means start your web service (apache in my case) after all other scripts with lower number than 80.

Get it and K would mean kill that service, and thats used if you switch from one runlevel to another. So if your going from runlevel 3 to 1 it will kill all the proccess's then go to one.

YOu can switch runlevels by typeing init "runlevelwanted".

Before I go into more detail here is a good link you can check out and come back if you need more help

http://www.penguinmagazine.com/Magazine/This_Issue/0018

One thing you will have to understand is the scripts are written in a certain way so linux can understand how to use them. You can modify there runlevels by hand or by a the chkconfig command. If this is a homade script this may not work perfectly and you may want to look into the rc.d file that will run after all the other runlevel process's.


Road

s&j 06-22-2002 04:31 PM

Road,
Thanks for such a good explanation. I understood the concept completely.


All times are GMT -5. The time now is 04:10 AM.