Search


print PDF
Startup of applications with server setup

Introduction

When your server is installed, it needs to go through several stages, that is runlevel. During those stages different services are started on your server: network configuration, application: Apache, mail server, MySQL server.

Rule

5 runlevels:
- runlevel 0: Requested when system stops
- runlevel 1: Requested when system starts with one user
- runlevel 3: Requested when system starts with many users
- runlevel 5: Requested when system starts with many users, graphic mode
- runlevel 6: Requested during reboot

Each service or application may be configured to start or stop at certain runlevel. You need to place links in appropriate folders for runlevel, which are attach to appropriate start script.

Examples concerns named of DNS server. The service is configured to start at runlevel 3, and stop at runlevel 0.
The start script is in /etc/init.d/:

[root@julien root]# ls -al /etc/init.d/named
-rwxr-xr-x 1 root root 2281 jui 13 2004 /etc/init.d/named



Link has been created /etc/rc3.d/ (folder with files of runlevel 3):

[root@julien root]# ls -al /etc/rc3.d/S13named
lrwxrwxrwx 1 root root 22 oct 2 15:55 /etc/rc3.d/S13named -> ../init.d/named


In /etc/rc0.d/ (folder with files of 0):

[root@julien root]# ls -al /etc/rc0.d/K45named
lrwxrwxrwx 1 root root 15 oct 2 15:37 /etc/rc0.d/K45named -> ../init.d/named


For runlevel 3, link S13named executes automatically the command /etc/init.d/named start. At runlevel 0, link K5named automatically executes the command /etc/init.d/named stop. The letter S in the link means 'start', letter 'k' 'stop'. The number indicated the order in which services are started. There is no way of starting DNS server before the service which manages network configuration.

  • OVH's dedicated servers start at runlevel 3. Usually, if you'd like the service to start with the server startup you need to configure it for runlevels 2, 3, 4 and 5.

Management

Redhat has a very useful tool: chkconfig which enables listing current configuration and simple modifications.

  • Listing services configured with server startup

To list current configuration use the following command:

[root@julien root]# /sbin/chkconfig --list
webmin 0:Arrêt 1:Arrêt 2:Marche 3:Marche 4:Arrêt 5:Marche 6:Arrêt
atd 0:Arrêt 1:Arrêt 2:Arrêt 3:Marche 4:Marche 5:Marche 6:Arrêt
watchdog 0:Arrêt 1:Arrêt 2:Arrêt 3:Arrêt 4:Arrêt 5:Arrêt 6:Arrêt
syslog 0:Arrêt 1:Arrêt 2:Marche 3:Marche 4:Marche 5:Marche 6:Arrêt



For one service (in the example MySQL):

[root@julien root]# /sbin/chkconfig --list mysql
mysql 0:Arrêt 1:Arrêt 2:Marche 3:Marche 4:Marche 5:Marche 6:Arrêt


The result shows all runlevels and actions they perform - whether they run or stop a given service.

  • Modifications

For several runlevels, you need to use the command:
/sbin/chkconfig --level

The example concerns MySQL, which isn't started automatically with server startup. Configuration listing provides the information that mysql isn't started automatically. Following commands are sufficient to configure its automatic startup with the next server restart:

[root@julien root]#/sbin/chkconfig --list mysql
mysql 0:Arrêt 1:Arrêt 2:Arrêt 3:Arrêt 4:Arrêt 5:Arrêt 6:Arrêt

[root@julien root]# /sbin/chkconfig --level 2345 mysql on

[root@julien root]# /sbin/chkconfig --list mysql
mysql 0:Arrêt 1:Arrêt 2:Marche 3:Marche 4:Marche 5:Marche 6:Arrêt



  • Adding the service to start

The tool enables taking over the service by the start script and creating the links.

Example for start file MySQL:

[root@julien root]# cat /etc/init.d/mysql
  1. !/bin/sh
  2. Copyright Abandoned 1996 TCX DataKonsult? AB & Monty Program KB & Detron HB
  3. This file is public domain and comes with NO WARRANTY of any kind

  1. MySQL daemon start/stop script.

  1. Usually this is put in /etc/init.d (at least on machines SYSV R4 based
  2. systems) and linked to /etc/rc3.d/S99mysql and /etc/rc0.d/K01mysql.
  3. When this is done the mysql server will be started when the machine is
  4. started and shut down when the systems goes down.

  1. Comments to support chkconfig on RedHat? Linux
  2. chkconfig: 2345 90 20
  3. description: A very fast and reliable SQL database engine.


Line: chkconfig: 2345 90 20, enables automatic configuration of MySQL with the help of chkconfig. MySQL will be launched to runlevels 2,3,4 and 5 with the sequence number 90 (start) and 20 (stop).

Example:

[root@julien root]# /sbin/chkconfig --add mysql




Test:

[root@julien root]# /sbin/chkconfig --list mysql
mysql 0:Arrêt 1:Arrêt 2:Marche 3:Marche 4:Marche 5:Marche 6:Arrêt

[root@julien root]# ls -al /etc/rc3.d/S90mysql
lrwxr-xr-x 1 root root 15 fév 12 16:17 /etc/rc3.d/S90mysql -> ../init.d/mysql

[root@julien root]# ls -al /etc/rc0.d/K20mysql
lrwxr-xr-x 1 root root 15 fév 12 16:17 /etc/rc0.d/K20mysql -> ../init.d/mysql




  • Deleting service

Service once added to chkconfig, will be kept as long as start file exists. You may delete it in the following way:

Example:

[root@julien root]# /sbin/chkconfig --del mysql




Check if all has been deleted:

[root@julien root]# /sbin/chkconfig --list mysql
mysql 0:Arrêt 1:Arrêt 2:Arrêt 3:Arrêt 4:Arrêt 5:Arrêt 6:Arrêt

[root@julien root]# ls -al /etc/rc3.d/S90mysql
ls: /etc/rc3.d/S90mysql: Aucun fichier ou répertoire de ce type