|
This article is based on using a Centos 5 linux virtual machine. See also my article on the setup tool for Redhat.
Running services on linux at startup can be achieved with the command chkconfig. Such services are similar to Windows services (2000, XP).
On linux one has to specify the run level with chkconfig. Normally a service will run with levels 3, 4 and 5. Runlevel 2 is for services that do not need any network connections.
The command chkconfig expects a file with the service name in directory /etc/init.d. This file specifies an extra line with default settings. This is the line in my script /etc/init.d/mysqld for the mysql daemon:
# chkconfig: - 64 36
The dash (-) means that the service should not be started in any run levels by default. It replaces a list of run levels (e.g. 345) as shown below. The start priority will be "64" and the stop priority will be "36". Lower numbers mean that the service will be started/stopped sooner when changing runlevels. So all chkconfig lines in init.d scripts together specify the order in which services will be started and stopped.
I could bring the mysql daemon under control of chkconfig using the following command:
[root@mycentos ~]# chkconfig --list | grep mysqld
mysqld 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@mycentos ~]# chkconfig --level 345 mysqld on
The first command checks the runlevels currently configured. If no chkconfig commands have been issued for the mysql daemon before then this command won't output anything. The second command sets runlevels for the service mysqld.
Instead of directly setting runlevels from the command line I could change the chkconfig line in /etc/init.d/mysqld into the following:
# chkconfig: 345 64 36
After editing the mysqld file I have to issue the following command, without runlevels: [root@mycentos ~]# chkconfig mysqld --add
This is slightly better than directly specifying runlevels via the command line. When configuring init.d files it is easier to transfer configuration between servers. In that case it won't be necessary to think about runlevels when configuring the same services again. And temporarily disabling the service is easier too. Services can be disabled with the del option:
[root@mycentos ~]# chkconfig mysqld --del
To enable the service later just issue the chkconfig command with the add option again. Note that no runlevels need to be specified.
|