8

我正在使用 Puppet 进行机器配置。我有一个在 Tomcat 6 应用服务器中运行的服务,另一个清单依赖于该服务(在安装过程中发送一些 REST 请求)。问题是,在使用以下命令启动 tomcat 后,该服务不可用:

service {"tomcat6":
  ensure  => running, enable => true, hasstatus => true, hasrestart => true;
}

所以我需要另一个清单的一些要求条件,以确保服务真正运行(例如检查某些 URL 是否可用)。如果它还没有准备好,请等待一段时间,然后再试一次,并限制重试次数。

是否有一些惯用的 Puppet 解决方案或其他解决方案可以实现这一目标?

注意 - 睡眠不是解决方案。

4

3 回答 3

19

感谢 lzap 和 Puppet irc 频道中的人们,这是一个解决方案:

exec {"wait for tomcat":
  require => Service["tomcat6"],
  command => "/usr/bin/wget --spider --tries 10 --retry-connrefused --no-check-certificate https://localhost:8443/service/",
}

在依赖清单中使用 require => Exec["wait for tomcat"] 时,在服务真正准备好之前它不会运行。

于 2011-11-23T18:30:12.927 回答
1

不是傀儡,而是贝壳……

max=30; while ! wget --spider http://localhost:8080/APP > /dev/null 2>&1; do
  max=$(( max - 1 )); [ $max -lt 0 ] && break; sleep 1
done; [ $max -gt 0 ]

这是改进版。

找到应用程序时返回 true,达到最大值时返回 false。

于 2011-11-23T16:04:57.790 回答
0

我知道这不是 Puppet,但是:

max=30; e=1; while [ $e -ne 0 -a $max -gt 0 ]; do
  wget --spider http://localhost:8080/APP > /dev/null 2>&1
  e=$?; max=$(( max - 1 )); sleep 1
done; [ $max -ne 0 ]

您可以将它放在一行上,只需将其与分号连接(“do”语句除外)。

于 2011-11-23T15:35:33.870 回答