Learn chkconfig command to list, turn on or turn off system services during different run levels. Also see how to control xinetd managed system service.
The chkconfig utility in Linux is command line tool to manage system services startups in run levels starting from 0 to 6. Run levels are different system stages in which system can run with different number and combination of services available for its users. There are mainly 7 run levels defined in kernel world whereas 0,1 and 6 are not relative in this post. 0,6 run levels are boot/shut related whereas 1 is single user mode and we are seeing service management here which is normally comes in a picture for multi user mode. So only 2,3,4,5 are the run levels which are covered by chkconfig utility when you are altering any services.
chkconfig controls which system service starts in which run level. It can even completely shuts off service so that it wont run in any run level too. There are
xinetd controlled system services which can be turned on or off irrespective of run level. These can be managed through
Chkconfig is capable of below tasks:
- Overview of list of services and their run-level wise availability
- Details of individual system service
- Enable service at certain/all run levels
- Disable service
If you are on Ubuntu server then probably chkconfig wont work on Ubuntu. You can alternatively use
update-rc.d command there.
We will see each of above option in detail with related options and examples.
1. Overview of services and their run-level availability :
For this task, chkconfig displays list of system services. Against every service, it displays all run levels 0 to 6 and on/off parameter. On means service is enabled at that run level and off means service is disabled at that run level. To view this you can run
chkconfig command without any argument or with
# chkconfig --list NetworkManager 0:off 1:off 2:off 3:off 4:off 5:off 6:off abrt-ccpp 0:off 1:off 2:off 3:on 4:off 5:on 6:off abrt-oops 0:off 1:off 2:off 3:on 4:off 5:on 6:off abrtd 0:off 1:off 2:off 3:on 4:off 5:on 6:off acpid 0:off 1:off 2:on 3:on 4:on 5:on 6:off atd 0:off 1:off 2:off 3:on 4:on 5:on 6:off auditd 0:off 1:off 2:on 3:on 4:on 5:off 6:off autofs 0:off 1:off 2:off 3:on 4:on 5:on 6:off -----output clipped----- xinetd based services: chargen-dgram: off chargen-stream: off time-stream: off ----- output clipped -----
In above output for example system service
autofs is enabled for run level 3,4,5 and disabled for 0,1,2,6. It also shows
xinetd based service status at the bottom. These services only have on or off status (no run level based status)
2. Details of individual service
In this task same output as above can be obtained only for particular service. It is as good as grepping out that service line from above output. This task can be accomplished by using service name as argument to
# chkconfig --list nfs nfs 0:off 1:off 2:off 3:off 4:off 5:off 6:off # chkconfig --list rsync rsync off
3. Enable service at certain/all run levels :
Let’s see how to enable service for particular/all run level. For this task you need to specify levels (
--level) on which services needs to enable, followed by service name and lastly on a state.
# chkconfig --level 34 autofs on
In above example we are enabling autofs service in run level 3 and 4.
To enable it in all run levels i.e. 2,3,4,5 you can skip –level option.
# chkconfig autofs on
Above example enables autofs system service in all run levels. You can verify if service state is set properly as specified in command, by viewing chkconfig
4. Disable service
To disable service at certain/all run levels, sane above command can be used only ‘off’ state needs to be specified at then end instead of ‘on’ state.
# chkconfig --level 34 autofs off <<turns off at run level 3 & 4 # chkconfig autofs off <<turns off on all run levels
Make a note that this change is not immediate. Enabling or disabling services will change settings but takes effect only when system will enter specific run level after execution of command.
5. Enable xinetd managed service:
Since xinetd managed services cant be tagged to run-levels, you can not specify –level option with commands associated to them. To enable xinetd managed service, you need to mention service name followed by ‘on’ state.
# chkconfig rsync on
Make a note that, change in xinetd managed services will be instant after execution of command.
6. Disable xinetd managed service:
To disable xinetd managed services opt ‘off’ state in above command.
# chkconfig rsync off
Observe state change in
chkconfig --list output.