Skip to content

Commit

Permalink
[COOK-635] Allow configuration of path to chef-client binary in init …
Browse files Browse the repository at this point in the history
…script
  • Loading branch information
schisamo committed Jul 20, 2011
1 parent 5baad5e commit 1a97c00
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 13 deletions.
10 changes: 6 additions & 4 deletions chef-client/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#
# Author:: Joshua Timberman <joshua@opscode.com>
# Author:: Joshua Timberman (<joshua@opscode.com>)
# Author:: Seth Chisamore (<schisamo@opscode.com>)
# Cookbook Name:: chef
# Attributes:: default
#
# Copyright 2008-2010, Opscode, Inc
# Copyright 2008-2011, Opscode, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -19,8 +20,9 @@

default["chef_client"]["interval"] = "1800"
default["chef_client"]["splay"] = "20"
default["chef_client"]["log_dir"] = "/var/log/chef"
default["chef_client"]["conf_dir"] = "/etc/chef"
default["chef_client"]["log_dir"] = "/var/log/chef"
default["chef_client"]["conf_dir"] = "/etc/chef"
default["chef_client"]["bin"] = "/usr/bin/chef-client"
default["chef_client"]["server_url"] = "http://localhost:4000"
default["chef_client"]["validation_client_name"] = "chef-validator"

Expand Down
25 changes: 24 additions & 1 deletion chef-client/recipes/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,22 @@
"default" => "root"
)

# COOK-635 account for alternate gem paths
# try to use the bin provided by the node attribute
if ::File.executable?(node["chef_client"]["bin"])
client_bin = node["chef_client"]["bin"]
# search for the bin in some sane paths
elsif (chef_in_sane_path=Chef::Client::SANE_PATHS.map{|p| p="#{p}/chef-client";p if ::File.executable?(p)}.compact.first) && chef_in_sane_path
client_bin = chef_in_sane_path
# last ditch search for a bin in PATH
elsif (chef_in_path=%x{which chef-client}.chomp) && ::File.executable?(chef_in_path)
client_bin = chef_in_path
else
raise "Could not locate the chef-client bin in any known path. Please set the proper path by overriding node['chef_client']['bin'] in a role."
end

%w{run_path cache_path backup_path log_dir}.each do |key|
directory node['chef_client'][key] do
directory node["chef_client"][key] do
recursive true
owner "root"
group root_group
Expand All @@ -44,6 +58,9 @@
template "/etc/init.d/chef-client" do
source "#{dist_dir}/init.d/chef-client.erb"
mode 0755
variables(
:client_bin => client_bin
)
notifies :restart, "service[chef-client]", :delayed
end

Expand Down Expand Up @@ -74,6 +91,9 @@
template "#{upstart_job_dir}/chef-client#{upstart_job_suffix}" do
source "debian/init/chef-client.conf.erb"
mode 0644
variables(
:client_bin => client_bin
)
notifies :restart, "service[chef-client]", :delayed
end

Expand All @@ -87,6 +107,9 @@
template "/etc/rc.d/chef-client" do
source "rc.d/chef-client.erb"
mode 0755
variables(
:client_bin => client_bin
)
notifies :restart, "service[chef-client]", :delayed
end

Expand Down
2 changes: 1 addition & 1 deletion chef-client/templates/arch/rc.d/chef-client.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# limitations under the License.
#

daemon_bin="/usr/bin/chef-client"
daemon_bin="<%= @client_bin %>"
daemon_name=$(basename $daemon_bin)
PIDF="<%= node["chef_client"]["run_path"] %>/$daemon_name.pid"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# description: starts up chef-client in daemon mode.

PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
DAEMON=/usr/bin/chef-client
DAEMON=<%= @client_bin %>
NAME=chef-client
DESC=chef-client
PIDFILE=<%= node["chef_client"]["run_path"] %>/client.pid
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ respawn
respawn limit 5 30

pre-start script
test -x /usr/bin/chef-client || { stop; exit 0; }
test -x <%= @client_bin %> || { stop; exit 0; }
end script

exec /usr/bin/chef-client -i <%= node["chef_client"]["interval"] %> -L <%= node["chef_client"]["log_dir"] %>/client.log
exec <%= @client_bin %> -i <%= node["chef_client"]["interval"] %> -L <%= node["chef_client"]["log_dir"] %>/client.log
6 changes: 3 additions & 3 deletions chef-client/templates/default/redhat/init.d/chef-client.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
# Source function library
. /etc/init.d/functions

exec="/usr/bin/chef-client"
exec="<%= @client_bin %>"
prog="chef-client"

[ -e /etc/sysconfig/$prog ] && . /etc/sysconfig/$prog
Expand All @@ -35,7 +35,7 @@ start() {
[ -x $exec ] || exit 5
[ -f $config ] || exit 6
echo -n $"Starting $prog: "
daemon chef-client -d -c "$config" -L "$logfile" -P "$pidfile" -i "$interval" -s "$splay" "$options"
daemon $exec -d -c "$config" -L "$logfile" -P "$pidfile" -i "$interval" -s "$splay" "$options"
retval=$?
echo
[ $retval -eq 0 ] && touch $lockfile
Expand All @@ -44,7 +44,7 @@ start() {

stop() {
echo -n $"Stopping $prog: "
killproc -p $pidfile chef-client
killproc -p $pidfile $exec
retval=$?
echo
[ $retval -eq 0 ] && rm -f $lockfile
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Configuration file for the chef-client service

CONFIG=<%= node["chef_client"]["log_dir"] %>/client.rb
CONFIG=<%= node["chef_client"]["conf_dir"] %>/client.rb
PIDFILE=<%= node["chef_client"]["run_path"] %>/client.pid
#LOCKFILE=/var/lock/subsys/chef-client
LOGFILE=<%= node["chef_client"]["log_dir"] %>/client.log
Expand Down

0 comments on commit 1a97c00

Please sign in to comment.