Welcome Guest ( Log In | Register )




                Web Hosting Guide

 
Reply to this topicNew Topic
Howto: Change System Runlevel Of A Process, & assign multiple runlevels to processes
miCRoSCoPiC^eaRt...
post Feb 12 2005, 04:16 PM
Post #1


PsYcheDeLiC dR3aMeR
Group Icon

Group: Admin
Posts: 2,248
Joined: 29-January 05
From: Bangkok, Thailand
Member No.: 2,411
myCENTs:19.10


Hi,
    This tutorial will be as short and sweet (hopefully) as the one on Changing Graphical Login to Text Based. Those who are using Linux regularly would have definitely come across the system runlevels and all the cryptic looking boot-up messages associated with different runlevel. Here's a short description of RunLevels from Linux Man Pages.
QUOTE
RUNLEVELS
      A  runlevel is a software configuration of the system which allows only
      a selected group of processes to exist.  The processes spawned by  init
      for each of these runlevels are defined in the /etc/inittab file.  Init
      can be in one of eight runlevels: 0-6 and S  or  s.  The  runlevel  is
      changed  by having a privileged user run telinit, which sends appropri-
      ate signals to init, telling it which runlevel to change to.

      Runlevels 0, 1, and 6 are reserved. Runlevel 0 is used to halt the sys-
      tem, runlevel 6 is used to reboot the system, and runlevel 1 is used to
      get the system down into single user mode. Runlevel  S  is  not  really
      meant  to  be used directly, but more for the scripts that are executed
      when entering runlevel 1. For more information on this,  see  the  man-
      pages for shutdown(8) and inittab(5).

      Runlevels  7-9  are  also  valid, though not really documented. This is
      because "traditional" Unix variants don't use  them.  In  case  you're
      curious,  runlevels  S and s are in fact the same.  Internally they are
      aliases for the same runlevel.


    RunLevels, thus, are a method of grouping up certain system processes so that they are able to run and peacefully coexist together (probably chipping in for a common goal). So how do you go about finding WHICH process is running in WHAT runlevel ? Of course, you can go for one of the new runlevel/process viewing utilities found in the System Tools folder under the X-Windows Start Menu. But that again, is a slow and cumbersome process - as the real power of using linux can be achieved only through the command line console. So we're going to do it the poweruser way, and believe me, it's NOT at all as scary as it sounds. In fact, this time I found out - it's not scary AT ALL and far more simpler than any of the other system configuration tasks of linux. So without further delay, lets get down and do it Hands-On smile.gif

    We are going to use this utility named chkconfig - as you can guess, it expands to Check Configuration. But it doesn't just checks your system configuration - but is able to modify it to a certain extent too. The linux man pages describe it as:
QUOTE
NAME
      chkconfig  -  updates  and queries runlevel information for system ser-
      vices

SYNOPSIS
      chkconfig --list [name]
      chkconfig --add name
      chkconfig --del name
      chkconfig [--level levels] name <on|off|reset>
      chkconfig [--level levels] name


    Chkconfig - in contrast to the other linux commands doesn't boast a huge list of options and parameters to work with. We'll start of with it's simplest form, using it to get a list of the processes that the system starts during bootup and the runlevels associated with them. In the console, just go ahead and type:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
shell> chkconfig --list
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

    The output you get is somewhat in the following format:
QUOTE

radvd          0:off  1:off  2:off  3:off  4:off  5:off  6:off
irqbalance    0:off  1:off  2:off  3:on    4:on    5:on    6:off
mysql          0:off  1:off  2:off  3:on    4:on    5:on    6:off
syslog          0:off  1:off  2:on    3:on    4:on    5:on    6:off
httpd            0:off  1:off  2:off  3:on    4:on    5:on    6:off
network        0:off  1:off  2:on    3:on    4:on    5:on    6:off
sendmail      0:off  1:off  2:off  3:off  4:off  5:off  6:off
psacct          0:off  1:off  2:off  3:on    4:off  5:off  6:off
irda              0:off  1:off  2:off  3:off  4:off  5:off  6:off
pcmcia        0:off  1:off  2:off  3:off  4:off  5:off  6:off
isdn              0:off  1:off  2:off  3:off  4:off  5:off  6:off
dhcpd          0:off  1:off  2:off  3:off  4:off  5:off  6:off
vsftpd          0:off  1:off  2:off  3:on    4:on    5:on    6:off
mailman        0:off  1:off  2:off  3:off  4:off  5:off  6:off


    See you if can spot a couple of the more common processes like the Apache Server (httpd), FTP Server (vsftpd), Dynamic Host Configuration Protocol Server (dhcpd) etc... You'll notice most of them have 0 through 6, i.e. Seven runlevels associated with them - and most of these processes except syslog - the System Log Generator, doesn't start running before runlevel 3. In fact runlevel 0, 1 & 2 take place right at the beginning of the system booting stage - and very few processes are needed to operate here except for the Core System/Kernel Processes. Those are the ones that load first and then allow you to run services of your choice.

    So how do we set a process to run at specific runlevels ? Once again, we take a little help of our friend "chkconfig". But first, lets pick a process from the above list. Notice the THIRD process from top in the list - it's mysql - the MySQL Server Process. It's set to run at runlevels 3, 4 & 5 - as shown by the 3:on 4:on 5:on statement. Just for the heck of it, I'm going to disable it altogether and stop it from running at any of the levels. Here's what you do:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
shell> chkconfig --level 345 mysql off
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

    I don't think I need to explain much. The "--level 345 mysql off" tells chkconfig to modify the entries for MySQL on those specific runlevels (3, 4 & 5) and set all of them to OFF. As you can see, the affected runlevels are put side-by-side together to form a number and passed to chkconfig. Similarly, if you wanted it to run only on Level 2 & 4 and be OFF on all the rest, you'd execute the command above first and then follow it up by:
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
shell> chkconfig --level 24 mysql on
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

    Feel free to try your own combination of runlevels to suit your needs. Right, lets use chkconfig once more and cross-check the results.. So we run, chkconfig --list once again, and this time the result should be somewhat like:
QUOTE

...
.....
mysql          0:off  1:off  2:on    3:off    4:on    5:off    6:off
...
....


    We're done for today.. But we missed out on one very important fact - What is the necessity of changing the runlevels for different system processes ? Well, that is a topic that cannot be covered in the span of one tutorial - so we'll come back to it pretty soon, maybe in a series of short tutorials.

    All the best smile.gif
Go to the top of the page
 
+Quote Post

Reply to this topicNew Topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 

Collapse

> Similar Topics

    Topic Title Replies Topic Starter Views Last Action
No new   47 swinkid 4,739 7th November 2009 - 03:35 PM
Last post by: starscream
No New Posts   12 tansqrx 9,038 1st November 2009 - 06:02 PM
Last post by: iG-Dave
No New Posts   5 Kushika 2,419 25th October 2009 - 12:06 AM
Last post by: iG-William Archer
No New Posts   2 Ronel 1,700 24th October 2009 - 08:27 PM
Last post by: iG-firoz
No New Posts   8 soleimanian 3,724 24th October 2009 - 03:42 PM
Last post by: iG-Surendra
No New Posts   11 cyph3r 6,031 22nd October 2009 - 05:33 PM
Last post by: iG-Atom
No New Posts   2 kaaamooo 495 5th October 2009 - 09:41 AM
Last post by: iGuest
No new   21 Feelay 6,619 5th October 2009 - 05:39 AM
Last post by: iG-Ruby
No New Posts   0 willielwgg 129 2nd October 2009 - 08:06 PM
Last post by: willielwgg
No New Posts   0 Entheone 50 28th September 2009 - 10:15 AM
Last post by: Entheone
No New Posts   6 outlawguy89 93 26th September 2009 - 02:25 PM
Last post by: Entheone
No new   49 rmdort 51,155 21st September 2009 - 04:17 AM
Last post by: iG-
No New Posts   7 suicide 5,152 5th September 2009 - 02:11 PM
Last post by: iG-sam
No New Posts   4 shiv 3,874 19th August 2009 - 01:52 PM
Last post by: iG-Rahul Hanchate
No new   25 soleimanian 11,611 6th August 2009 - 05:06 AM
Last post by: iG-Bilal


Web Hosting Powered by ComputingHost.com.