본문 바로가기
OS 운영체제/LINUX

chkconfig (실행 프로그램 설정 도구)

by yororing 2024. 4. 30.

00 개요

  • 문서 작성 목적: 서비스를 실행하는 shell script (si-service.sh)에서 윗 칸에 # chkconfig 2345 20 80 라고 적혀있는데 이것이 무엇을 의미하는지 알고자 함

01 chkconfig란

1. 정의

  • updates and queries runlevel info for system services
  • 명령어로 사용되거나 .init 또는 .sh 등의 파일 윗부분에 설정하여 사용 가능

2. 문법

  • name = 서비스명
chkconfig [--list] [--type type][name]
chkconfig --add name
chkconfig --del name
chkconfig --override name
chkconfig [--level levels] [--type type] name <on|off|reset|resetpriorities>
chkconfig [--level levels] [--type type] name

3. 설명

  • chkconfig provides a simple command-line tool for maintaining the /etc/rc[0-6].d directory hierarchy by relieving system administrators of the task of directly manipulating the numerous symbolic links in those directories.
  • This implementation of chkconfig was inspired by the chkconfig command present in the IRIX operating system. Rather than maintaining configuration information outside of the /etc/rc[0-6].d hierarchy, however, this version directly manages the symlinks in /etc/rc[0-6].d. This leaves all of the configuration information regarding what services init starts in a single location.
  • chkconfig의 5가지 기능
    • adding new services for management
    • removing services from management
    • listing the current startup information for services
    • changing the startup information for services
    • checking the startup state of a particular service
  • When chkconfig is run with only a service name, it checks to see if the service is configured to be started in the current runlevel. If it is, chkconfig returns true; otherwise it returns false. The --level option may be used to have chkconfig query an alternative runlevel rather than the current one. When chkconfig is run with the --list argument, or no arguments at all, a listing is displayed of all services and their current configuration.
  • If one of on, off, reset, or resetpriorities is specified after the service name, chkconfig changes the startup information for the specified service. The on and off flags cause the service to be started or stopped, respectively, in the runlevels being changed. The reset flag resets the on/off state for all runlevels for the service to whatever is specified in the init script in question, while the resetpriorities flag resets the start/stop priorities for the service to whatever is specifed in the init script.
  • By default, the on and off options affect only runlevels 2, 3, 4, and 5, while reset and resetpriorities affects all of the runlevels. The --level option may be used to specify which runlevels are affected.
  • Note that for every service, each runlevel has either a start script or a stop script. When switching runlevels, init will not re-start an already-started service, and will not re-stop a service that is not running.
  • chkconfig also can manage xinetd scripts via the means of xinetd.d configuration files. Note that only the on, off, and --list commands are supported for xinetd.d services.
  • chkconfig supports a --type argument to limit actions to only a specific type of services, in the case where services of either type may share a name. Possible values for type are sysv and xinetd.

4. 옵션

옵션 설명
--level levels Specifies the run levels an operation should pertain to
It is given as a string of numbers (0 to 6)
예시) --level 35 specifies runlevels 3 and 5
--add name Adds a new service for management by chkconfig
When a new service is added, chkconfig ensures that the service has either a start or a kill entry in every runlevel
If any runlevel is missing such an entry, chkconfig creates the appropriate entry as specified by the default values in the init script
Note that default entries in LSB-delimited 'INIT INFO' sections take precedence over the default runlevels in the initscript; if any Required-Start or Required-Stop entries are present, the start and stop priorities of the script will be adjusted to account for these dependencies
--del name Removes the service from chkconfig management, and any symbolic links in /etc/rc[0-6].d which pertain to it
Note that future package installs for this service may run chkconfig --add, which will re-add such links
To disable a service, run chkconfig name off
--override name If service name is configured exactly as it would be if the --add option had been specified with no override file in /etc/chkconfig.d/name, and if /etc/chkconfig.d/name now exists and is specified differently from the base initscript, change the configuration for service name to follow the overrides instead of the base configuration
--list name Lists all of the services which chkconfig knows about, and whether they are stopped or started in each runlevel
If name is specified, information in only display about service name

5. Runlevel 파일

0) Runlevel이란

  • 런레벨 (Runlevel)은 리눅스 종류 별로 정의된 부팅시 단계를 의미
CentOS, RedHat, Fedora 런레벨
레벨 설명
0 시스템 종료 (shutdown)
1 단일 사용자 모드 (single-user mode, 시스템 복구 모드)
2 다중 사용자 모드 (네트워크 서비스 미포함)
3 다중 사용자 모드 (네트워크 서비스 포함, CUI - 터미널에서 실행, GUI 미포함)
4 사용되지 않음 (커스텀 설정 가능)
5 다중 사용자 모드 (네트워크 서비스 및 GUI - X 윈도우 포함)
6 시스템 재부팅 (reboot)
  • 런레벨은 시스템이 어떤 상태에서 작동할지 결정하는 중요한 요소
  • 예) 데스크톱 환경을 사용하는 일반적인 사용자는 런레벨 5에서 작업하며, 서버 환경에서는 GUI가 필요 없는 런레벨 3을 주로 사용함 
  • Each service which should be manageable by chkconfig needs two or more commented lines added to its init.d script. 
    • The first line 
      • tells chkconfig what runlevels the service should be started in by default, as well as the start and stop priority levels
      • If the service should not, by default, be started in any runlevels, a - should be used in place of the runlevels list.
    • The second line
      • contains a description for the service, and may be extended across multiple lines with backslash continuation.

1) 일반 형식

  • 예시) random.init 이라는 파일 안에 다음 3 줄이 있음
# chkconfig: 2345 20 80
# description: Saves and restores system entropy pool for \
#              higher quality random number generation.
  • 설명:
    • # chkconfig: 2345 20 80
      • random script should be started in levels 2, 3, 4, and 5, that its start priority(시작 우선순위) should be 20, and that its stop priority (종료 우선순위) should be 80
      • 시작 우선순위: 서비스가 시스템 부팅 시 얼마나 빨리 실행되는지를 결정. 숫자가 작을수록 다른 서비스들보다 먼저 시작됨.
        • 예) 시작 우선순위가 10인 서비스는 우선순위가 20인 서비스보다 먼저 시작됨
      • 종료 우선순위: 시스템이 종료되거나 런레벨이 변경될 때 서비스가 얼마나 빨리 종료되는지를 결정. 종료 우선순위는 숫자가 클수록 먼저 종료됨.
        • 예) 종료 우선순위가 70인 서비스는 우선순위가 80인 서비스보다 늦게 종료됨 
    • # description: Saves and restores system entropy pool for \
    • #              higher quality random number generation.
      • 파일에 대한 설명을 나타냄
      • \ → 줄바꿈
      • 공백은 무시됨

2) LSB-Style

  • chkconfig also supports LSB-style init stanzas, and will apply them in preference to "chkconfig:" lines where available.
  • 예시) random.init 이라는 파일 안에 다음 7줄이 있음
### BEGIN INIT INFO
# Provides: foo
# Required-Start: bar
# Defalt-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Foo init script
### END INIT INFO
  • 설명:
    • In this case, the start priority of "foo" would be changed such that it is higher than the "bar" start priority, if "bar" is enabled.
    • Care must be taken when adding dependencies, as they can cause vast shifts in the start and stop priorities of many scripts.

6. Override 파일

  • File in /etc/chkconfig.d/servicename are parsed using the same comments that chkconfig notices in init service scripts, and override values in the init service scripts themselves.

참조

  1. https://linux.die.net/man/8/chkconfig
  2. (런레벨) https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=diceworld&logNo=220295874000#:~:text=chkconfig%20는%20리눅스서버가,확인하거나%20설정할%20수%20있습니다.
  3.  
  4.