초기화 스크립트. 부트스트래핑 활동과 실행 활동의 차이점

초기화 스크립트. 부트스트래핑 활동과 실행 활동의 차이점

에 실행되고 종료되는 스크립트가 있습니다 /etc/init.d. 부팅 시 자동으로 시작되도록 /etc/rc5.d심볼릭 링크가 추가 되어 있습니다. chkconfig따라서 부팅 시 시작되며 등을 service myscript start통해 사용자가 수동으로 제어할 수 있습니다 . 장에서 설명한 순서는 시작 시 실행되는 것으로 service myscript stop알려져 있습니다 . start하지만 나도 몇 가지 활동을 수행해야 합니다.오직시스템이 이미 시작되면 시작 시 이 작업을 수동으로 수행하기 위해 사용자에게 명시적인 액세스 권한을 부여할 필요가 없습니다. 존재하다이 기사설명한 대로 boot()스크립트에 시퀀스를 추가할 수 있으며 시작 시에만 실행됩니다. 하지만 그건 작동하지 않습니다. 나는 다른 접근 방식을 시도했습니다. boot()다음과 같이 작성했지만 function boot()결과는 동일합니다. 작동하지 않습니다. 따라서 몇 가지 질문이 제기됩니다. 배포판별 기능인가요, 아니면 이 시퀀스가 ​​스크립트의 어딘가에 있어야 합니까? 둘 다 잘못된 경우(또는 모든 것이 boot()잘못되었거나 더 이상 사용되지 않는 경우) 시작 시에만 작업을 어떻게 수행할 수 있습니까? 내 시스템은 Linux Red Hat Enterprise 6.

이것은 내 스크립트입니다.

#!/bin/bash
#Some comments here

#some inclusions of another scripts here

function startService()
{
      #some activity for launching
}
boot()
{
        #That's it. Here I want to perform some preparations (remove files)
        #and then launch starting sequence:
        if [ -f "somefilename" ]
        then
            rm -f "somefilename"
        fi
        startService
}
function stopService()
{
        #Activity for stopping
}

#Some functions for service's status retrieving here

case "$1" in
        start)
                startService
                ;;
        stop)
                stopService
                ;;
        status)
                #Calls of status functions
                ;;
        *)
                echo "Usage: {start | stop | status}"
                exit 1
                ;;
esac

미리 감사드립니다.

답변1

나는 boot() 섹션이 있는 init 스크립트에 익숙하지 않으므로 OpenWRT 또는 busybox에 특정할 수 있습니다. RHEL6에서는 "boot" 매개변수가 아닌 "start" 매개변수를 통해서만 init 스크립트를 호출할 수 있습니다.

RHEL6에서 시작 시 스크립트를 실행하려면 /etc/init 디렉터리에서 Upstart에 대한 "conf 파일"을 구성해야 합니다. 시작 예제로 /etc/init/rc.conf를 권장합니다. 다음과 같이 이름을 지정하십시오.myscript.conf, 다음과 같이 채우십시오.

# adjust the runlevels if you don't want to run myscript in every runlevel
start on runlevel [0123456]

# this tells init to just run this once and let it exit
task

# if you want to see the output from your script on the console, use the following line; otherwise remove it
console output

# call myscript with a boot flag (to keep one copy of your script in /etc/init.d; adjust this if you'd rather have a separate boot-script)
exec /etc/init.d/myscript boot

upstart의 init 에 대한 자세한 정보를 확인하세요 man -s5 init.

관련 정보