rcX.d 폴더에 시작 스크립트와 종료 스크립트가 쌍으로 나타나지 않는 이유는 무엇입니까?

rcX.d 폴더에 시작 스크립트와 종료 스크립트가 쌍으로 나타나지 않는 이유는 무엇입니까?

시작 시 실행되어야 하는 스크립트는 다음 위치에 있습니다./etc/init.d및 그 안에 포함된 파일/etc/rc*.d심볼릭 링크는 /etc/init.d의 파일을 가리킵니다. 또한 심볼릭 링크의 이름은 특정 실행 수준에서 서비스가 시작되었는지(S*) 또는 중지되었는지(K*) 여부를 나타냅니다. 확인하기 위해 "ls -al" 명령을 실행했습니다./etc/rc3.d, 출력은 다음과 같습니다.

drwxr-xr-x.  2 root root 4096 Apr  6 23:04 .
drwxr-xr-x. 10 root root 4096 May 22  2015 ..
lrwxrwxrwx.  1 root root   20 May 22  2015 K50netconsole -> ../init.d/netconsole
lrwxrwxrwx.  1 root root   17 May 22  2015 K90network -> ../init.d/network
lrwxrwxrwx.  1 root root   17 May 22  2015 S00livesys -> ../init.d/livesys
lrwxrwxrwx.  1 root root   16 Apr  6 23:04 S85mongod -> ../init.d/mongod
lrwxrwxrwx.  1 root root   15 May 31  2015 S95jexec -> ../init.d/jexec
lrwxrwxrwx.  1 root root   22 May 22  2015 S99livesys-late -> ../init.d/livesys-late

시작 스크립트와 종료 스크립트가 쌍으로 나와야 한다고 생각했는데 이것이 잘못된 이유는 무엇입니까?

답변1

RHEL6 또는 이와 유사한 Linux의 경우 이러한 스크립트는 일반적으로 admin 에 의해 관리됩니다 chkconfig(8). 이를 통해 쌍을 이루는 것이 아니라 각 서비스의 각 실행 수준에 대해 시작 스크립트 또는 중지 스크립트가 있는지 확인합니다. (우분투나 다른 것에 대해서는 잘 모르겠습니다).

매뉴얼 페이지에서 chkconfig:

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.

...

--add name
  This option 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.

답변실행 수준에 대한 또 다른 질문명명 규칙을 설명합니다.

이제 명명 체계도 상당히 간단해졌습니다. 이름이 S로 시작하는 스크립트는 해당 실행 수준에서 시작되고, 이름이 K로 시작하는 스크립트는 종료됩니다.

런레벨 변경 스크립트를 보면 , 런레벨이 변경될 때마다 해당 스크립트가 매개변수 로 실행된 후 입력된 매개변수로 스크립트가 실행되는 /etc/rc모습을 볼 수 있습니다 . K와 S 스크립트가 모두 있다는 것은 스크립트가 각 실행 수준에서 중지되고 시작된다는 의미입니다.S*startK*stop

# rc            This file is responsible for starting/stopping
#               services when the runlevel changes.
...
# First, run the KILL scripts.
for i in /etc/rc$runlevel.d/K* ; do
        ...
        $i stop
done
# Now run the START scripts.
for i in /etc/rc$runlevel.d/S* ; do
        ...
                exec $i start
        ...
done

저는 RHEL6 시스템만 보고 있으므로 이것이 다른 배포판에서 어떻게 다른지 확인할 수 있는 사람이 있으면 그렇게 해주세요.

관련 정보