2014-01-11 1 views
1

시작 데몬 폴더에서 plist를 사용할 때 <StartInterval>이라는 키가 있다는 것을 알고 있습니다. 나는 훨씬 더 빨리 전체 plist를 쓰고 있기 때문에 내가 할 수있을 때 launchctl을 사용하는 것을 선호하지만, 죽은 후에 프로세스를 재 시작하는 방법을 알아낼 수 없었다. 이미 설명서 페이지를 읽었으며 아무 것도 발견하지 못했습니다. 방법이 있습니까? 일반적으로 나는 다음과 같은 명령을 사용합니다Launchctl 시작 간격

launchctl submit -l somename -p /path/to/script -o output.txt -e errors.txt

을하지만, 어떤 시간 간격 이후에 사망하면 그 프로그램을 다시 시작하지 않습니다.

+0

왜이 작업을 수행하려고합니까? 내가 당신의 정확한 문제를 안다면 또 다른 해결책이있을 수 있습니다. – jamespick

+0

'launchctl submit'을 원하셨습니까? load는 인수를 취하지 않습니다. 이 경우 submit 명령은 간격을 지원하지 않으므로 .plist 버전을 사용해야합니다. – gaige

+0

@gaige 예 죄송합니다. – 735Tesla

답변

1

launchctl submit 어떤 이유로 종료되면 이미 프로그램을 다시 실행해야합니다

submit -l label [-p executable] [-o path] [-e path] -- command [args] 
      A simple way of submitting a program to run without a configura- 
      tion file. This mechanism also tells launchd to keep the program 
      alive in the event of failure. 

      -l label 
        What unique label to assign this job to launchd. 

      -p program 
        What program to really execute, regardless of what fol- 
        lows the -- in the submit sub-command. 

      -o path Where to send the stdout of the program. 

      -e path Where to send the stderr of the program. 

false로 KeepAlive를위한 SuccessfulExit 기준이 오류로 종료하는 경우, 다시 프로그램을 실행 설정하려면 :

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict> 
    <key>Label</key> 
    <string>test</string> 
    <key>ProgramArguments</key> 
    <array> 
    <string>bash</string> 
    <string>-c</string> 
    <string>n=$((RANDOM%2));say $n;exit $n</string> 
    </array> 
    <key>KeepAlive</key> 
    <dict> 
    <key>SuccessfulExit</key> 
    <false/> 
    </dict> 
    <key>StartInterval</key> 
    <integer>60</integer> 
</dict> 
</plist> 

launchd 작업을 조절하므로 프로그램을 다시 시작하는 데 약 10 초가 걸립니다.

관련 문제