Operating System - Linux
1829107 Members
2265 Online
109986 Solutions
New Discussion

Re: start service when system startup

 
SOLVED
Go to solution
Cheung_2
Frequent Advisor

start service when system startup

If i want to start some services eg, start db , deamon etc. when the system startup , what can i do? thx.
Andy
5 REPLIES 5
U.SivaKumar_2
Honored Contributor

Re: start service when system startup

Hi,

Edit /etc/rc.d/rc.local file and put your commands there . reboot the server now your commands will run automatically.

regards,
U.SivaKumar
Innovations are made when conventions are broken
Bill McNAMARA_1
Honored Contributor
Solution

Re: start service when system startup

see /usr/share/doc/start_up.txt for full instructions on how to creqte start up an control scripts.

Later,
Bill
It works for me (tm)
Bill McNAMARA_1
Honored Contributor

Re: start service when system startup

woops! this is linux.. in this case, it'd help to know your flavor!! You will need to modify your rc.local
It works for me (tm)
Cheung_2
Frequent Advisor

Re: start service when system startup

But i found some of system is rc3.d , what is the difference? thx.
Andy
Stuart Browne
Honored Contributor

Re: start service when system startup

As the other two who replied said, it would make it easier if we knew what distribution of Linux you are using, as to giving you credibal advice.

As it stands, here's a brief over-view.

When *nix machine boots up, it uses the process 'init' to say what should be done and in what order. If you have a look through the configuration file for init (/etc/inittab), there will be a single line starting with 'si', and then multiple lines that start with 'l' followed by the numbers 0 through 6. These are the different run-levels of a machine.

Quick explination of what the 7 different widely used run-levels:

0 : Designed to 'halt' the machine
1 : usually a Single User mode
2 : A form of Multi-User. Use differes depending on OS and Distribution.
3 : Another multi-user. See above.
4 : Not usually used at all.
5 : Most linux machines use this for X, otherwise not usually used.
6 : Shutdown the machine and restart it. A 'reboot' if you will.

Depending on what Unix/Linux you're using change the way things get started and stopped when changing run levels. For the sake of this thread, I'll keep it short.

Simple put, these levels of 'init' call a program (or shell script) checks a given directory structure (on most modern Linux boxes, it's /etc/rc.d/rc.d/) and runs start up and shut down scripts.

In RedHat, '/etc/rc.d/rc' is the shell script that does most of the work.

When booting up to Run Level 3 (standard Multi-User), it walks through the S and K files in /etc/rc.d/rc3.d/ and starts any that begin with an 'S', with the single argument 'start'. The last file (sorted alphabetically) in this structure is usually 'S99local'.

When shutting a machine down, either /etc/rc.d/rc0.d or /etc/rc.d/rc6.d gets parsed, and all files starting with a 'K' get executed, with the single argument of 'stop'.

Now. If you want to put your own scripts in this structure to start a service when the system starts, you can. Just call it 'Sblah'. This will get executed in order (detmined by it's alphabetical order, use 'echo S*' to test) when the machine hits that run level.

The other option is to use /etc/rc.d/rc.local. This gets called when the 'S99local' routine gets executed in the rc.d structure (infact, it's just a symbolic link back to it!)

I hope this helps clarify things a little for you.

(NOTE: This is based on the behaviour of RH Linux. Other distributions might behave slightly differently, and also some Unicies behave slightly differently.)
One long-haired git at your service...