我正在使用厨师来做这件事:
我试图在前一个运行之后运行bash块,简单,我使用notify。我还希望在初始运行和第二次运行时检查锁定文件(是否有更好的方法确保它只在前一个bash块运行时运行?)。
这是我目前的厨师代码:
if not File.exist? tsm_login_lock
bash 'login_tsm' do
user tableau_user
cwd tableau_user_home
code <<-EOH
source /etc/profile.d/tableau_server.sh
tsm login -u #{tableau_user} -p #{password}
tsm settings import -f /home/analytics/setting_file.json
tsm pending-changes apply
tsm licenses activate -k #{key}
tsm register --file #{registration}
tsm pending-changes apply
EOH
notifies :run, "bash[tsm_init]", :immediately
end
file tsm_login_lock do
mode '0644'
content 'tableau server stareted'
end
end
if not File.exist? tsm_init_lock
bash 'tsm_init' do
user tableau_user
cwd tableau_user_home
code <<-EOH
tsm initialize --start-server --request-timeout 1800
EOH
notifies :run, "bash[tsm_2]", :immediately
end
file tsm_init_lock do
mode '0644'
content 'tableau server initialized'
end
end
答案 0 :(得分:1)
你想在这里结合几种方法:
:nothing
。这样他们就不会自己运行,然后被通知有条件地再次运行。您在subscribe中定义的操作是通知时将采取的操作。:create
操作通知。bash 'login_tsm' do
user tableau_user
cwd tableau_user_home
code <<-EOH
source /etc/profile.d/tableau_server.sh
tsm login -u #{tableau_user} -p #{password}
tsm settings import -f /home/analytics/setting_file.json
tsm pending-changes apply
tsm licenses activate -k #{key}
tsm register --file #{registration}
tsm pending-changes apply
EOH
notifies :run, "bash[tsm_init]", :immediately
notifies :create, "file[#{tsm_login_lock}]", :immediately
not_if { ::File.exist?(tsm_login_lock) }
end
file tsm_login_lock do
mode '0644'
content 'tableau server stareted'
action :nothing
end
bash 'tsm_init' do
user tableau_user
cwd tableau_user_home
code <<-EOH
tsm initialize --start-server --request-timeout 1800
EOH
action :nothing
not_if { ::File.exist?(tsm_init_lock) }
notifies :run, "bash[tsm_2]", :immediately
notifies :create, "file[#{tsm_init_lock}]", :immediately
end
file tsm_init_lock do
mode '0644'
content 'tableau server initialized'
action :nothing
end
最后,我强烈建议您找出您认为成功登录Tableau和init的内容。如果您登录到服务器,请问自己如何检查这些内容。将这些验证用于防护而不是锁定文件。一般而言,您希望在需要时使用警卫来确保资源是幂等的。查看上面关于警卫的链接,了解警卫的工作方式。