傀儡如何使傀儡等待几秒钟

时间:2013-01-23 00:51:08

标签: wait puppet

我想运行一个Web服务并等待几秒钟后才能得到结果。

在木偶中等待的最佳方式是什么?

2 个答案:

答案 0 :(得分:14)

您可以将linux sleep命令与exec一起使用并将其暂存以在Web服务之后运行。类似的东西:

exec { 'wait_for_my_web_service' :
  require => Service["my_web_service"],
  command => "sleep 10 && /run/my/command/to/get/results/from/the/web/service",
  path => "/usr/bin:/bin",
}

答案 1 :(得分:1)

我采用本地等待+可配置重试。

define wait_for_port ( $protocol = 'tcp', $retry = 10 ) {
  $port = $title
  exec { "wait-for-port${port}":
    command  => "until fuser ${port}/${protocol}; do i=\$[i+1]; [ \$i -gt ${retry} ] && break || sleep 1; done",
    provider => 'shell',
  }
}

wait_for_port { '3000': }
相关问题