salt命令执行的超时机制

少于 1 分钟阅读

Contact me

或者用邮件交流 jacky.wucheng@foxmail.com

如何控制执行命令的超时?

salt cli在给发送命令的时候,有个参数”-t, –timeout”, 表面上看是超时控制,其实文档说的很明白,其意思是如果salt cli在等待了这个timeout时间后minion还是没有返回结果回来,那么就用find_job去query一下minion询问当前执行状态。如果在如果find_job超时过了gather_job_timeout设定的时间,那么salt命令会返回:Minion did not return. [No response]。 这个参数并不是我们通常所理解的超时控制。参考 saltmaster configurationSaltStack Event系统监听events测试。并且可以参看源代码salt/salt/client/__init__.py验证。

在通过cmd.run执行命令的时候,真正可以控制超时就终止命令执行的方法是:salt '*' cmd.run 'sleep 5; echo OK' timeout=1,参考这里,文中的其他命令执行方法也有超时控制。

Master中控制timeout的参数

  • gather_job_timeout: default 10,The number of seconds to wait when the client is requesting information about running jobs.
  • TIMEOUT:Default 5,Set the default timeout for the salt command and api.