2017-04-07 51 views
1

(更新)我在原始问题中忽略了一行重要的代码。如何确保服务在执行Exec资源之前重新启动?

我写了一个将创建本地存储的傀儡模块。这是不自动的方式。

  1. 编辑/etc/multipath.conf文件
  2. 重新启动在multipathd守护
  3. 执行pvcreate将$设备
  4. 执行的vgcreate $ VOLUME_NAME $设备

所以在我的木偶模块I如果/etc/multipath.conf文件更改,则要确保multipathd守护进程重新启动。所以我用这种方式写了我的傀儡表。

Service['multipathd'] -> Anchor['create_storage_volume::begin'] 

... 

file { '/etc/multipath.conf': 
    ensure => file, 
    content => template('local_storage::hadoop/multipath.conf.erb'), 
    owner => 'root', 
    mode => '0600', 
    notify => Service['multipathd'], 
} -> 
service { 'multipathd': 
    enable => true, 
    ensure => running, 
} 

anchor { 'create_storage_volume::begin': } -> 

exec { "pvcreate ${device}": 
    path => ['/usr/sbin', '/bin'], 
    unless => "pvs | grep ${"volume_name}, 
} -> 
exec { "vgcreate ${volume_name} ${device}": 
    path => ['/usr/sbin', '/bin'], 
    unless => "pvs | grep ${"volume_name}, 
} -> # -> do nova config stuff 
anchor { 'create_storage_volume::end': } 

... 

我的问题是,“做上面的代码保证了在multipathd守护程序被执行pvcreate和运行vgcreate指令执行前重新启动”?我是否需要添加更多类似资源的订单...

Service['multipathd'] -> Anchor['local_storage::begin'] 

回答

3

我的问题是,“上述代码是否确保multipathd守护程序在执行pvcreate和vgcreate命令之前重新启动”?

号都Service['multipathd']Exec["pvcreate ${device}"]File['/etc/multipath.conf']后,你提出什么样的服务和Exec的应用的相对顺序应用,但一无所获。

我可能会写这样的,而不是:

file { '/etc/multipath.conf': 
    ensure => file, 
    content => template('local_storage::hadoop/multipath.conf.erb'), 
    owner => 'root', 
    mode => '0600', 
} ~> 
Service['multipathd'] -> 
exec { "pvcreate ${device}": 
    path => ['/usr/sbin', '/bin'], 
    unless => "pvs | grep ${"volume_name}, 
} -> 
# ... 

注意使用the notifying chain operator;这是Puppet语言的一个较少使用的特性。


关于更新的问题,对于Service关键的要求到Exec之前被刷新被施加的是,有两者之间的顺序关系,不论是直接或传递的。在修改后的问题中,所涉及的资源已经存在这种关系。

原始答案确实在这里有一个很好的点,我在评论中提到:当资源刷新发生时,Puppet实际上没有明确记录相对于其他任何事情。记录的语义对此有一些暗示,但没有给出任何坚定的规则。在实践中,通过Puppet 4,如果发生资源刷新,它将在资源同步后立即发生 - 或者在它需要同步后立即发生。

+0

谢谢你的回答。我有几个问题。我在我原来的问题中忽略了这一行:Service ['multipathd'] - > Anchor ['create_storage_volume :: begin'](我会更新我的问题),但确保服务multipathd在我之前重新启动Exec资源执行? –

+0

从技术上讲,Puppet的文档没有明确说明资源刷新的时间。在实践中,在当前和历史版本的Puppet中,如果资源要刷新,那么它将在它(或将要)同步之后立即执行。 –

+0

@RedCricket我唯一的补充建议是检查Puppet的'lvm'模块。 –

相关问题