3

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

Peter Turner
  • 2,048
  • 9
  • 33
  • 45
  • Do you mean the run level of the server itself or a specific daemon (e.g. httpd)? These are different things. – Mark Jun 04 '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 09 '09 at 13:08

7 Answers7

10

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.

Aaron K.
  • 464
  • 2
  • 6
3

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
Scott Pack
  • 14,717
  • 10
  • 51
  • 83
3

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

Jindrich
  • 4,958
  • 8
  • 29
  • 42
2

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)
Mark
  • 1,331
  • 1
  • 11
  • 16
2

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.

pulcher
  • 336
  • 1
  • 4
2

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.

user4260
  • 191
  • 1
  • 7
1

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

Zypher
  • 36,995
  • 5
  • 52
  • 95