• linux.jpgMany system 5 UNIX variants use scripts in the /etc/rcN.d/ directories to control which services should be started in the various runlevels. If, for instance, you wanted the secure shell daemon to run in runlevel 4, you would put a script named something like “S55sshd” in “/etc/rc4.d”. This script would usually accept the “start” “stop” and “restart” arguments, as well as the commands to perform these functions. When the system came up, it would execute “/etc/rc4.d/S55sshd start” when it transitioned into runlevel 4. On the way down, it would execute “/etc/rc4.d/S55sshd stop” as the system passed from runlevel 4 to runlevel 3. If you had made some changes to the sshd configuration file, and wanted to restart the service, you could manually execute “/etc/rc3.d/sshd restart” to kill and then restart the daemon.

    Since this model involved having multiple copies of the same script in many different directories, Linux and others have adopted the standard of putting all service control scripts in “/etc/init.d/”, and using symbolic links to these scripts in the various “/etc/rcN.d/” directories. This allowed for the SGI IRIX innovation of the “chkconfig” command, which is command line tool that manages the symbolic links for you.

    How to use “chkconfig” in Red Hat Enterprise Linux:

    First, all your service control scripts need to be in the “/etc/init.d/” directory. They should reflect the name of the service they control. In our example, the file is named /etc/init.d/sshd”.

    Secondly, they have a tag at the head of the script that looks something like this so that “chkconfig” understands that it can controll it:

    # Basic support for IRIX style chkconfig
    ###
    # chkconfig: 2345 55 25
    # description: Manages the services you are controlling with the chkconfig command
    ###

    The first set of numbers “2345″ is are the default runlevels for the service, and “55″ and “25″ represent the name of the “S” and “K” symbolic links, and the order in which the service will be started and stopped in the respective runlevel. You will need to change these last two numbers, making them unique.

    Once these requirements are met, using the command is fairly simple. When we go into /etc/rc3.d, we see a file called “S55sshd”.

    [root@calvin rc2.d]# cd /etc/rc3.d
    [root@calvin rc2.d]# ls -al S55sshd
    lrwxrwxrwx 1 root root 14 Nov 15 15:10 S55sshd -> ../init.d/sshd

    We see this file is a symbolic link to “../init.d/sshd”. Let’s run the “chkconfig” command to turn sshd off.

    [root@calvin init.d]# /sbin/chkconfig sshd off
    [root@calvin init.d]# /sbin/chkconfig –list sshd
    sshd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

    chkconfig --list sshd confirms that sshd has been disabled in all runlevels, and the symbolic link has been removed from all “/etc/rcN.d/” directories.

    Let’s turn sshd back on:

    [root@calvin init.d]# /sbin/chkconfig sshd on
    [root@calvin rc2.d]# /sbin/chkconfig –list sshd
    sshd 0:off 1:off 2:on 3:on 4:on 5:on 6:off

    chkconfig --list sshd confirms that sshd has now been enabled in runlevels 2, 3, 4 and 5, and we see s symbolic link to “/etc/init.d/sshd” named “S55sshd” in “/etc/rc2.d/”, “/etc/rc3.d/”, “/etc/rc4.d/” and “/etc/rc5.d/”.

    Let’s imagine now that we only want sshd to be enabled in runlevel 5. We run the following command to accomplish this:

    [root@calvin rc2.d]# /sbin/chkconfig sshd –level 234 off
    cd /etc/[root@calvin rc2.d]# /sbin/chkconfig –list sshd
    sshd 0:off 1:off 2:off 3:off 4:off 5:on 6:off

    chkconfig --list sshd confirms that sshd has been disabled in all runlevels except 5, and the “S55sshd” has been removed from “/etc/rc2.d/”, “/etc/rc3.d/” and “/etc/rc4.d/”.

    There is, of course, more to it, but this should get you well on your way to happily managing your system services with “chkconfig”.

    This entry was posted on Wednesday, November 15th, 2006 at 7:46 pm and is filed under Data and Technology. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
  • 13 Comments

    Take a look at some of the responses we've had to this article.

    1. Posted on November 15th

      Nice article Cliff.

      Any insight on what the numbers on this line are for?

      #chkconfig: 235 19 08

    2. Posted on November 16th

      Sure… Good question.

      The “chkconfig: 235″ section indicates the the default runlevels. For instance, if we ran “chkconfig sshd on”, it would be active in runlevels 2,3 and 5.

      The “19″ and “08″ numbers indicate the order of startup and kill. This means that using this tag, the startup symbolic link would be named “S19sshd” and the symbolic link to kill the process would be named “K08sshd”.

    3. Posted on November 16th

      Update:

      I have changed “#chkconfig: 235 19 08″ in the story to “#chkconfig: 2345 55 25″ so that it works with the rest of the examples.

      “#chkconfig: 235 19 08″ actually came from the VmWare script, but it was nicely crafted, making it easy to understand what it is doing.

      I’ve also included a quick explanation of what these numbers mean.

    4. Posted on November 21st

      Yeah, “chkconfig” is a nice management tool. Run level 4 is unused, so your example might confuse some n00bs (lol h4×0r!)

    5. [...] That should pretty much do it. If you don’t have autofs configured to start up, you can use chkconfig to enable it. “/misc/backups” will now be mounted whenever a user or process attempts to access data on it, and it will be automatically disconnected after 120 seconds of inactivity. Last, but not least, you can always confirm that it is running with the “service” command: [...]

    6. [...] Remember to use “chkconfig” to make sure “ntpd” is enabled to come up when the system starts. [...]

    7. anonymous
      Posted on March 7th

      Thanks for the nice explanation of how-to do it.

    8. Posted on May 10th

      what is the difference between run level 3 and run level 4 in linux.

    9. Posted on May 10th

      Well, by default, runlevel 4 is unused. If you were to enter runlevel 4 on a new system, it would look exactly the same as runlevel 5. It is there, however, so you can controll custom items with it in case you find yourself needing a middle ground between runlevel 3 and 5. 3, of course is full multiuser mode without X, while 5 is full multiuser mode with X. You would use runlevel 4 if you still wanted X running, but not everything normally running in 5.

    10. [...] asterisk service with chkconfig and service.) [...]

    11. [...] script is chkconfig compatible, so call it the name of your new service and put it in [...]

    12. [...] script is chkconfig compatible, so call it the name of your new service and put it in [...]

    13. zawmn
      Posted on August 21st

      I’m starting openoffice as startup service according the follow url
      http://little.bluethings.net/2008/05/30/automating-document-conversion-in-linux-using-jodconverterooo/

      [root@suse ~]# sudo service openoffice start
      openoffice: unrecognized service

      What is this error?

  • Post a Comment

    Let us know what you thought.

  • Name:

    Email (required):

    Website:

    Message:

Visitors have tagged this post: t (820) - chkconfig howto (456) - rhel chkconfig (181) - chkconfig tutorial (130) - chkconfig script (99) - rhel service (73) - rhel services (67) - chkconfig rhel (56) - chkconfig examples (52) - chkconfig scripts (52) - chkconfig syntax (50) - chkconfig (49) - chkconfig: 2345 (43) - chkconfig disable (41) - chkconfig service (38) - howto chkconfig (38) - how to use chkconfig (34) - "chkconfig add service" (34) - rhel add service (34) - rhel4 services (32) - chkconfig file (32) - chkconfig order (31) - chkconfig sshd (30) - chkconfig solaris (30) - chkconfig example (30) - rhel4 chkconfig (30) - rhel service command (29) - chkconfig numbers (29) - chkconfig services (27) - f (24) - "chkconfig --add" example (23) - solaris chkconfig (21) - linux chkconfig tutorial (21) - chkconfig start (18) - chkconfig 235 (18) - chkconfig ssh (18) - chkconfig kill (17) - service rhel (17) - chkconfig runlevels (17) - how to chkconfig (16) - chkconfig runlevel (16) - chkconfig rhel4 (16) - service chkconfig (16) - rhel4 service (14) - chkconfig: 2345 55 25 (14) - linux chkconfig order (14) - chkconfig start order (14) - linux enable services (14) - add service to chkconfig (13) - chkconfig sshd on (13) - linux service enable (13) - chkconfig how to (12) - would (12) - chkconfig change order (11) - chkconfig requirements (11) - service does not support chkconfig (11) - add service to runlevel (10) - chkconfig off (10) - rhel 5 chkconfig (10) - chkconfig add service (10) - use chkconfig (9) - chkconfig +init (9) - linux chkconfig howto (9) - chkconfig files (9) - chkconfig --list (8) - chkconfig disable service (8) - rhel4 add service (8) - how to use chkconfig in linux (8) - chkconfig in solaris (8) - chkconfig adding (8) - chkconfig format (8) - chkconfig -add + examples (7) - rhel service startup (7) - RHEL service control (7) - rhel service add (7) - linux chkconfig (7) - difference between chkconfig and service (7) - rhel4 service command (7) - chkconfig script syntax (7) - script chkconfig (7) - chkconfig add example (7) - solaris chkconfig command (6) - chkconfig restart (6) - chkconfig for solaris (6) - adding services with chkconfig (6) - add service rhel (6) - chkconfig start kill (6) - chkconfig turn off service (6) - chkconfig 3 (6) - linux chkconfig add (6) - linux chkconfig syntax (6) - chkconfig turn on service (6) - chkconfig install service (6) - add service chkconfig (6) - chkconfig: 235 19 08 (5) - chkconfig: 2345 55 10 (5) - rhel service start order (5) - "chkconfig --add" (5) - chkconfig solaris 9 (5) - linux chkconfig service (5) - chkconfig turn service on (5) - chkconfig script requirements (5) - adding service to chkconfig (5) - chkconfig command in solaris (5) - chkconfig init order (5) - linux chkconfig add service (5) - "tutorial chkconfig" (5) - chkconfig sshd off (5) - chkconfig change (5) - ‘chkconfig’ and ‘service’ (5) - chkconfig tags (5) - linux enable service (5) - chkconfig in RHEL (5) - RHEL service list (5) - how to enable services in linux (5) - chkconfig compatible (5) - chkconfig solaris 8 (5) - script for chkconfig (5) - scripts chkconfig (5) - chkconfig and service command (5) - add service with chkconfig (5) - chkconfig file format (5) - disable chkconfig (5) - chkconfig unrecognized service (5) - RHEL chkconfig add service (4) - rhel4 runlevels (4) - adding service to runlevel (4) - services chkconfig (4) - chkconfig RHEL 4 (4) - RHEL service enable (4) - adding a service to chkconfig (4) - init chkconfig (4) - chkconfig on solaris (4) - rhel startup services (4) - linux chkconfig example (4) - chkconfig adding service (4) - chkconfig adding services (4) - chkconfig service order (4) - Basic support for IRIX style chkconfig (4) - examples of chkconfig (4) - rhel4 services list (4) - custom chkconfig script (4) - linux: chkconfig runlevel (4) - chkconfig change level (4) - "add service" chkconfig (4) - chkconfig example add (4) - chkconfig runlevel 6 (4) - chkconfig --levels 235 (4) - howto use chkconfig (4) - chkconfig turn service off (4) -