Trigger a chef client run after git push


#1

Hello,

We run our own chef server and clients on several machines.
We use the deploy resource and a bunch of cookbooks to deploy
our apps when chef client runs. Before chef we used capistrano
and triggered the deployment ourselves with cap deploy, now it
happens automatically but it’s not instant (we can’t tell exactly
when a deploy happens, it’s “during the next chef run”).

I’ve added a Jabber notification which sends a IM when any of our 80
apps is getting deployed/finished deploying so it helps a bit but I’ve been
thinking of a way to trigger a chef run on a node
immediately afer we git push a change to the application code so that we
don’t have to wait.

I’m wondering if there’s any tool in Chef that we could use to combine
git push hooks ( on our git server ) with restarting the chef client (to trigger
a deployment) on a node. The only thing that comes to mind is writing
a custom service that runs on every chef client node and listens for
"restart" events
and is able to restart chef client. Then writing a post git push hook
on the git server
that sends the “restart” even to the particular node.

I’m wondering if the above sounds like a good approach or if there’s anything
else that we could use in this case.

Any info much appreciated.

Thanks
Karol


#2

Hi,

On Mon, Sep 24, 2012 at 5:40 PM, Karol Hosiawa hosiawak@gmail.com wrote:

I’ve added a Jabber notification which sends a IM when any of our 80
apps is getting deployed/finished deploying so it helps a bit but I’ve been
thinking of a way to trigger a chef run on a node
immediately afer we git push a change to the application code so that we
don’t have to wait.

I’m wondering if there’s any tool in Chef that we could use to combine
git push hooks ( on our git server ) with restarting the chef client (to
trigger
a deployment) on a node. The only thing that comes to mind is writing
a custom service that runs on every chef client node and listens for
"restart" events
and is able to restart chef client. Then writing a post git push hook
on the git server
that sends the “restart” even to the particular node.

We do it through a couple of different mechanisms - however the simplest
is simply a ssh in and run chef client. However we don’t typically do it as
a result of a push but instead do it as part of our jenkins infrastructure.
Mostlywe use something that looks something like

def converge_linux_host(hostname)
Net::SSH.start(hostname, self.username, :keys =>
[self.private_key_filename]) do |ssh|
puts ssh.exec!(“sudo service chef-client stop”)
puts ssh.exec!(“sudo chef-client”)
puts ssh.exec!(“sudo service chef-client restart”)
end
end

HTH,

Peter Donald