Valter Silva
Valter Silva

Reputation: 16656

How to build artifacts and reload services with Chef?

I'm using the git resource to clone and keep my application repository up-to-date with chef. If something has changed, I'm building my artifacts locally, however, I would like to also reload my services so the changes can be applied. I'm thinking about using subscribe for that, but I'm not sure. How can I achieve this ?

.. # create application user/group/directories

git node['mvp']['home'] do
  repository node['mvp']['repository']
  revision 'master'
  user 'mvp'
  group 'mvp'
  action :sync
  notifies :run, 'execute[build]', :immediately
end

# builds only if necessary/changes
execute 'build' do
  user "mvp"
  command 'make libs && make clean all'
  cwd node['mvp']['home']
  action :nothing
end

template '/etc/mvp_frontend' do
  owner 'root'
  group 'root'
  mode '0600'
  source 'mvp_frontend_env.erb'
end

directory '/etc/systemd/system/mvp.service.d' do
  owner 'root'
  group 'root'
  mode '0755'
end

%w(mvp_frontend mvp_quote mvp_newsfeed).each do |srvc|
  template "/etc/systemd/system/#{srvc}.service" do
    owner 'root'
    group 'root'
    mode '0755'
    source "#{srvc}.service.erb"
  end

  service "#{srvc}" do
    supports :status => true, :stop => true, :restart => true, :reload => true
    action [:enable, :start]
    subscribes :reload, "template[/etc/systemd/system/#{srvc}.service]", :immediately
  end
end

Upvotes: 0

Views: 47

Answers (1)

coderanger
coderanger

Reputation: 54211

Your example is subscribing to updates on the template, you probably want to subscribe to the git resource instead (or maybe the execute, but I wouldn't go that far).

Upvotes: 0

Related Questions