[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: How do I start | stop a daemon under debian

startup daemons are set up as follows:

(usually) a script is created in /etc/init.d. As an example, MySQL is 
controlled by the script /etc/init.d/mysql

A soft link is created from the run level directory that you want to 
start the daemon. These directories are /etc/rc0.d through /etc/rc6.d. 
There is also rcS.d. By convention, the link is named 'S' or 'K' 
(depending upon whether you are starting or killing the daemon) 
followed by a two digit number, followed by the name of the script 
in /etc/init.d. During the boot up process, these are processed in 
ASCII sort order, ie all ones beginning with a 'K' are processed first, 
in order of the two digit numbers after it.

For example, you might create links in rc2.d, rc3.d, rc4.d and rc5.d to 
start MySQL. The following lines would do so:

ln -s /etc/init.d/mysql /etc/rc2.d/S20mysql
ln -s /etc/init.d/mysql /etc/rc3.d/S20mysql
ln -s /etc/init.d/mysql /etc/rc4.d/S20mysql
ln -s /etc/init.d/mysql /etc/rc5.d/S20mysql

which would start MySQL whenever you entered those run levels. Since 
you want MySQL to shut down before the computer is shut off, you would 
add a "Kill" script to the appropriate run levels as follows:

ln -s /etc/init.d/mysql /etc/rc0.d/K20mysql
ln -s /etc/init.d/mysql /etc/rc1.d/K20mysql
ln -s /etc/init.d/mysql /etc/rc6.d/K20mysql

for a discussion of run levels, see the man page on init, ie type "man 
init" at the command line.

Anyway, the scripts in init.d accept a parameter whose value tells the 
script what to do. The minimum should be to accept "start" and "stop" 
as parameters. Any link starting with a "K" calls the script 
with "stop", any link starting "S" callsthe script with a "start."

That's how it works. To answer your question, simply remove the links 
from the rc?.d directory. Or, to temporarily disable a script, I will 
sometimes create a dummy script and save the original one. Such as:

mv /etc/init.d/mysql /etc/init.d/mysql.original
echo #! /bin/bash > /etc/init.d/mysql
chmod 777 /etc/init.d/mysql

in effect creating an empty script to be executed. Then, if I want 
MySQL back, I simply mv /etc/init.d/mysql.original /etc/init.d/mysql 
and it runs like it originally did.

BTW, I'm not 100% on the run levels, but this explaination has worked 
for me so far.


> How do I start | stop a daemon under debian ? I have Debian 2.2 
Potato. I
> understand that I have to use "ln -s" in order to start a daemon 
> after reboot.
> Is it the same for stopping forever a daemon that was set up to start 
> reboot ?
>                                                         Adrian Nims
> --  
> To UNSUBSCRIBE, email to debian-isp-request@lists.debian.org
> with a subject of "unsubscribe". Trouble? Contact 

R. W. Rodolico
Daily Data, Inc.
POB 140465
Dallas  TX  75214-0465

It appears I could be pursuing an untamed ornithoid to no purpose.
            --Brent Spiner as Data, Star Trek: The Next Generation

Reply to: