Class: Chef::Knife::ClusterKick

Inherits:
ClusterSsh show all
Defined in:
lib/chef/knife/cluster_kick.rb

Overview

Based on gist.github.com/1325982 by Ash Berlin

"Since chef v0.10 you can send USR1 to the chef-client process and it
will wake up and do a run. But the usual case when I want to do a run
is cos I'm either testing a cookbook change or I want to deploy now. I
could just run sudo chef-client but then that will only log to std
out.  Just run this script, it will send chef-client a USR1 signal and
then tail the log file (but nicely so that you'll get your terminal
back when the run completes)."

Constant Summary collapse

KICKSTART_SCRIPT =
<<EOF
#!/bin/bash
set -e
<%= ((config[:verbosity].to_i > 1) ? "set -v" : "") %>

if sudo service chef-client status ; then

# running
pid_file="<%= config[:pid_file] %>"
log_file=/var/log/chef/client.log

declare tail_pid

on_exit() {
  rm -f $pipe
  [ -n "$tail_pid" ] && kill $tail_pid
}

trap "on_exit" EXIT ERR

pipe=/tmp/pipe-$$
mkfifo $pipe

tail -fn0 "$log_file" > $pipe &

tail_pid=$!

sudo true
pid="$(sudo cat $pid_file)"
sudo kill -USR1 "$pid"
sed -r "/(ERROR: Sleeping for [0-9]+ seconds before trying again|INFO: Report handlers complete)\$/{q}" $pipe

else
  echo -e "****\n\nchef-client daemon not running, invoking chef-client directly\n\n****\n"
  sudo chef-client
fi
EOF

Instance Method Summary collapse

Methods inherited from ClusterSsh

#configure_session, #cssh, #print_data, #ssh_command

Methods included from ClusterChef::KnifeCommon

#bootstrapper, #configure_dry_run, #confirm_execution, #confirm_or_exit, #die, #display, #get_relevant_slice, #get_slice, included, #load_cluster_chef, load_deps, #predicate_str, #progressbar_for_threads, #relevant?, #run_bootstrap, #section, #sub_command

Instance Method Details

#runObject



85
86
87
88
89
90
# File 'lib/chef/knife/cluster_kick.rb', line 85

def run
  @name_args = [ @name_args.join(' ') ]
  script = Erubis::Eruby.new(KICKSTART_SCRIPT).result(:config => config)
  @name_args[1] = script
  super
end