首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Launchctl启动间隔

Launchctl启动间隔
EN

Stack Overflow用户
提问于 2014-01-11 13:43:11
回答 1查看 2.6K关注 0票数 1

我知道在启动守护进程文件夹中使用plist时,有一个名为<StartInterval>的键。我更喜欢在可能的时候使用launchctl,因为它比写一个完整的plist要快得多,但是我还没有弄清楚如何在进程被杀死后重新启动它。我已经看过手册了,在那里什么也没有发现。有办法吗?通常,我使用以下命令:

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

但是,如果程序在任何时间间隔后被终止,这将不会重新启动程序。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-01-15 23:34:11

如果程序因某种原因终止,launchctl submit应该已经再次运行了:

代码语言:javascript
复制
 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.

若要再次运行程序(如果程序退出时有错误),请将用于SuccessfulExit的KeepAlive条件设置为false:

代码语言:javascript
复制
<?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>

启动节流作业,所以程序需要10秒左右才能恢复。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21062972

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档