Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I always forget how to do this, how to I change the inittab run level of a server/daemon?

share|improve this question
    
Do you mean the run level of the server itself or a specific daemon (e.g. httpd)? These are different things. –  Mark Jun 4 '09 at 15:38
    
I wasn't sure when I asked the question so I added a bunch of words I thought I'd remember as keywords. –  Peter Turner Jun 9 '09 at 13:08

7 Answers 7

up vote 2 down vote accepted

There are a few different places. However, the following should cover most of the them:

check in /etc/inittab use the "chkconfig" command to update the rcX.d directories with symbolic links to the /etc/init.d entries.

share|improve this answer

To see the previous and current runlevel,

[root@example ~]# runlevel
N 3

Here, there was no previous runlevel, and the current runlevel is 3.

To change the runlevel temporarily,

[root@example ~]# init RUNLEVEL

To permanently change the default runlevel of the machine, change /etc/inittab's

id:5:initdefault:

Change 5 to your preferred level.

If you're using RHEL or one of the clone distributions like CentOS, the default runlevel will be 3 for servers, and 5 for desktops where X should be started automatically.

If you're using Debian or its various offshoots, the default runlevel will be 2.

Ubuntu has moved to the upstart task selection program, so it may lack /etc/inittab and will use runlevel 2 by default. Create one if you want to change the default runlevel, or you can pass the runlevel as part of startup through grub.

To change the runlevel of a daemon:

If you're using RHEL or another RPM-based distro, chkconfig will probably be the most convenient way.

[root@example ~]# chkconfig --list ntpd
ntpd            0:off   1:off   2:on    3:on    4:on    5:on    6:off

[root@example ~]# chkconfig ntpd on
[root@example ~]# chkconfig ntpd off
[root@example ~]# chkconfig --level 2,5 ntpd on

If you're using Debian, I usually manually change the status of a daemon per runlevel.

[root@example ~]# ls /etc/rc2.d/*ntp*
/etc/rc2.d/S23ntp
[root@example ~]# cd /etc/rc2.d/
[root@example rc2.d]# mv K23ntpd S23ntpd

If the symlink for the daemon begins with K, it's stopped at that runlevel. If it starts with S, it is started at that runlevel.

share|improve this answer
    
+1. covers both server and daemon runlevel aspect. great. –  viky Jun 5 '09 at 3:38

You're really asking two questions.

  1. How to change the default runlevel of a server
  2. How to change which runlevels a daemon runs.

1 is answered by Mark (His Answer)

2 is going to be system dependent. On RedHat based systems (RH, YDL, Fedora, etc) then you'll use chkconfig to configure everything. As an example, to have apache start at runlevels 3, 4, and 5, you would run:

chkconfig --levels 345 httpd on

On a gentoo system you would use the rc-update tool, and run these commands:

rc-update add apache2 default
share|improve this answer

I really like sysv-rc-conf

DESCRIPTION:
sysv-rc-conf gives an easy to use interface for manag‐ ing "/etc/rc{runlevel}.d/" symlinks.

alt text

If you have ubuntu : sudo apt-get install sysv-rc-conf

share|improve this answer

Daemons are usually started from scripts in /etc/rc.d/ or /etc/init.d There are symlinks to the corresponding startscript from a runlevel specific directory (e.g. /etc/rc0.d to /etc/rc6.d)

In short: create a link from the respective directory in /etc/rc.d to the startscript of the daemon. The location of the link determins the runlevel.

share|improve this answer

For RHEL, look for the following line in /etc/inittab

id:5:initdefault:

The number in this line if the default run level. You can set it to the following options:

# Default runlevel. The runlevels used by RHS are:
#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)
share|improve this answer

For the server part, i normally use telinit <runlevel> or you can do init <runlevel>

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.