Chef: how to run actions if git deploy has pulled new code

chefdeploymentgit

Most of the time there's nothing new in the git repo that is deployed to a local directory, but if there are any changes, the node.js application should be restarted to start working with the latest changes. It should not be touched if no new code was pulled.

How to achieve that with chef?

Best Answer

The git sync action actually triggers notifications if the revision has changed. So add an execute block that runs only on notification, and you're done!

git "/home/code" do
    ...
    action :sync
    notifies :run, "execute[restart-node-app]", :immediately
end

execute "restart-node-app" do
    command "..."
    action :nothing
end