LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Linking init script to specific rc0.d, rc1.d etc directories (https://www.linuxquestions.org/questions/linux-newbie-8/linking-init-script-to-specific-rc0-d-rc1-d-etc-directories-827379/)

vinaytp 08-20-2010 01:37 AM

Linking init script to specific rc0.d, rc1.d etc directories
 
Hi All,

I have written an init script which I have kept under /etc/init.d, I need to create links to the directories rc0.d, rc1.d, rc2.d, rc3.d etc..

So that I can use chkconfig command to control the starting and stopping of the script at specific runlevels.

Any good tutorials for this ? Please advice.

Thanks in advnace.

quanta 08-20-2010 02:36 AM

Simply, all you need is ln -s:
Code:

ln -s /etc/init.d/<your_script> /etc/rc3.d/S64<service_name>
ln -s /etc/init.d/<your_script> /etc/rc5.d/S64<service_name>
ln -s /etc/init.d/<your_script> /etc/rc0.d/K36<service_name>
ln -s /etc/init.d/<your_script> /etc/rc6.d/K36<service_name>

S stand for Start and K means Kill.

On the other way, if you put the description about runlevel, processname, ... at the begin of init script, something like this:
Code:

# chkconfig: - 64 36
# description:  MySQL database server.
# processname: mysqld
# config: /etc/my.cnf
# pidfile: /var/run/mysqld/mysqld.pid

and execute:
Code:

chkconfig --add <service_name>
chkconfig <service_name> on

it will automatically create symlinks for you.

vinaytp 08-20-2010 02:40 AM

Thanks a lot quanta.

I have a small doubt

Code:

# chkconfig: - 64 36
# description:  MySQL database server.
# processname: mysqld
# config: /etc/my.cnf
# pidfile: /var/run/mysqld/mysqld.pid


In the above code, Are 64 and 36 arbitrary numbers. Is their any constraint to choose these numbers ?

Thanks in advance.

quanta 08-20-2010 02:55 AM

Looking at the line begining with # chkconfig: - means all runlevel, you can change to something like 35. 64 is priority to start your service, and 36 is priority to stop. There is no contraint to choose these numbers but I often choose around the priority of common services: sshd, mysqld, httpd, ntpd, ...

vinaytp 08-20-2010 03:01 AM

Quote:

Originally Posted by quanta (Post 4072113)
Looking at the line begining with # chkconfig: - mean all runlevel, you can change to something like 35. 64 is priority to start your service, and 36 is priority to stop. There is no contraint to choose these numbers but I often choose around the priority of common services: sshd, mysqld, httpd, ntpd, ...

Thanks again for detailed explanation..


All times are GMT -5. The time now is 02:56 AM.