Class: Chef::Knife::ClusterKick
- Inherits:
-
ClusterSsh
- Object
- Ssh
- ClusterSsh
- Chef::Knife::ClusterKick
- 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 =
"#!/bin/bash\nset -e\nsudo -p 'knife sudo password: ' true\n\n<%= ((config[:verbosity].to_i > 1) ? \"set -v\" : \"\") %>\n\n# New style server, using chef-client-nonce\nif [ -f /etc/init.d/chef-client-nonce ]; then\n echo -e \"****\\n\\nstarting chef-client-nonce service\\n\\n****\\n\"\n sudo -p 'knife sudo password: ' service chef-client-nonce start\n# Old style server, using long-running chef-client\nelif [ -f /etc/init.d/chef-client ]; then\n if sudo -p 'knife sudo password: ' service chef-client status ; then\n\n # running\n pid_file=\"<%= config[:pid_file] %>\"\n log_file=<%= config[:log_file] %>\n\n declare tail_pid\n\n on_exit() {\n rm -f $pipe\n }\n\n trap \"on_exit\" EXIT ERR\n\n pipe=/tmp/pipe-$$\n mkfifo $pipe\n\n tail -Fn0 \"$log_file\" > $pipe &\n\n tail_pid=$!\n\n pid=\"$(sudo -p 'knife sudo password: ' cat $pid_file)\"\n sudo -p 'knife sudo password: ' kill -USR1 \"$pid\"\n GOOD_RESULT='INFO: Report handlers complete\\$'\n BAD_RESULT='ERROR: Sleeping for [0-9]+ seconds before trying again\\$'\n sed -r -e \"/$GOOD_RESULT/{q 0}\" -e\"/$BAD_RESULT/{q 1}\" $pipe\n else\n echo -e \"****\\n\\nchef-client daemon not running, invoking chef-client directly\\n\\n****\\n\"\n sudo -p 'knife sudo password: ' chef-client\n fi\nelse\n echo -e \"****\\n\\nNo chef-client found!\\n\\n****\\n\"\n exit 1\nfi\n"
Instance Attribute Summary
Attributes included from Ironfan::KnifeCommon
Instance Method Summary collapse
Methods inherited from ClusterSsh
#_run, #configure_session, #cssh, #print_data, #ssh_command
Methods included from Ironfan::KnifeCommon
#all_computers, #bootstrapper, #configure_dry_run, #confirm_execution, #confirm_or_exit, #die, #discover_computers, #display, #exit_if_unhealthy!, #gemfile, #get_relevant_slice, #get_slice, #has_problem, #healthy?, included, load_deps, #load_ironfan, #pick_apart, #predicate_str, #progressbar_for_threads, #relevant?, #run_bootstrap, #section, #sub_command, #wait_for_ssh
Instance Method Details
#run ⇒ Object
48 49 50 51 52 53 54 |
# File 'lib/chef/knife/cluster_kick.rb', line 48 def run @name_args = [ @name_args.join('-') ] config[:display_target] = true script = Erubis::Eruby.new(KICKSTART_SCRIPT).result(:config => config) @name_args[1] = script super end |