chef-vpc-toolkit 2.7.2 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
* Tue Nov 8 2011 Dan Prince <dan.prince@rackspace.com> - 2.8.0
|
2
|
+
- Add chef_interval option to chef_installer.conf.
|
3
|
+
- Add RESTART_ON_FAILURE and RESTART_TIMEOUT options to poll_clients task.
|
4
|
+
|
1
5
|
* Sun Nov 6 2011 Dan Prince <dan.prince@rackspace.com> - 2.7.2
|
2
6
|
- Support for configuring and starting Chef 0.10 when preinstalled.
|
3
7
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.8.0
|
data/config/chef_installer.yml
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# Installation functions for Chef 0.8 RPMs obtained from the ELFF repo.
|
2
2
|
export CHEF_STATUS_PORT="1234"
|
3
3
|
export STATUS_MONITOR_DIR="/root/status_monitor"
|
4
|
+
export SERVICE_BIN="/usr/sbin/service"
|
5
|
+
[ -f /bin/rpm ] && SERVICE_BIN="/sbin/service"
|
4
6
|
|
5
7
|
function configure_chef_server {
|
6
8
|
|
@@ -14,14 +16,15 @@ function print_client_validation_key {
|
|
14
16
|
|
15
17
|
function configure_chef_client {
|
16
18
|
|
17
|
-
if (( $# !=
|
19
|
+
if (( $# != 3 )); then
|
18
20
|
echo "Unable to configure chef client."
|
19
|
-
echo "usage: configure_chef_client <server_name> <client_validation_key>"
|
21
|
+
echo "usage: configure_chef_client <server_name> <client_validation_key> <interval>"
|
20
22
|
exit 1
|
21
23
|
fi
|
22
24
|
|
23
25
|
local SERVER_NAME=$1
|
24
26
|
local CLIENT_VALIDATION_KEY=$2
|
27
|
+
local INTERVAL=${3:-"600"} # default is 10 minutes
|
25
28
|
|
26
29
|
if [ ! -f "/etc/chef/validation.pem" ]; then
|
27
30
|
cat > /etc/chef/validation.pem <<-EOF_VALIDATION_PEM
|
@@ -46,8 +49,8 @@ EOF_CAT_CHEF_CLIENT_CONF
|
|
46
49
|
|
47
50
|
local CHEF_SYSCONFIG=/etc/default/chef-client
|
48
51
|
[ -d /etc/sysconfig/ ] && CHEF_SYSCONFIG=/etc/sysconfig/chef-client
|
49
|
-
cat > $CHEF_SYSCONFIG <<-
|
50
|
-
INTERVAL
|
52
|
+
cat > $CHEF_SYSCONFIG <<-EOF_CAT_CHEF_SYSCONFIG
|
53
|
+
INTERVAL=$INTERVAL
|
51
54
|
SPLAY=20
|
52
55
|
CONFIG=/etc/chef/client.rb
|
53
56
|
LOGFILE=/var/log/chef/client.log
|
@@ -243,9 +246,6 @@ done
|
|
243
246
|
|
244
247
|
function start_chef_server {
|
245
248
|
|
246
|
-
local SERVICE_BIN="/usr/sbin/service"
|
247
|
-
[ -f /bin/rpm ] && SERVICE_BIN="/sbin/service"
|
248
|
-
|
249
249
|
[ -d /var/run/chef ] && chown chef:chef /var/run/chef
|
250
250
|
|
251
251
|
if [ ! -f /var/run/chef/server.main.pid ]; then
|
@@ -268,9 +268,6 @@ function start_chef_server {
|
|
268
268
|
|
269
269
|
function start_chef_client {
|
270
270
|
|
271
|
-
local SERVICE_BIN="/usr/sbin/service"
|
272
|
-
[ -f /bin/rpm ] && SERVICE_BIN="/sbin/service"
|
273
|
-
|
274
271
|
$SERVICE_BIN chef-client start
|
275
272
|
if [ -f /sbin/chkconfig ]; then
|
276
273
|
chkconfig chef-client on &> /dev/null
|
@@ -312,28 +309,49 @@ function poll_chef_client_online {
|
|
312
309
|
|
313
310
|
local CLIENT_NAMES=${1:?"Please specify a chef client name."}
|
314
311
|
local SECS=${2:-"600"} #10 minutes
|
312
|
+
local RESTART_TIMEOUT=${3:-"$SECS"} #Restart clients if they haven't finished by timeout
|
313
|
+
local RESTART_ON_FAILURE=${4} #Restart clients on failure (once)
|
314
|
+
local TMP_RESTART=$(mktemp)
|
315
315
|
|
316
316
|
local SLEEP_COUNT=5
|
317
317
|
local COUNT=1
|
318
318
|
local MAX_COUNT=$(( $SECS / $SLEEP_COUNT ))
|
319
|
+
local MAX_RETRY_COUNT=$(( $RESTART_TIMEOUT / $SLEEP_COUNT ))
|
319
320
|
local FAILED_CLIENTS=""
|
320
321
|
local ALL_ONLINE="true"
|
321
322
|
until (( $COUNT == $MAX_COUNT )); do
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
323
|
+
ALL_ONLINE="true"
|
324
|
+
FAILED_CLIENTS=""
|
325
|
+
for NAME in $CLIENT_NAMES; do
|
326
|
+
if ! grep "$NAME:" $STATUS_MONITOR_DIR/status.out | tail -n 1 | grep -c ":ONLINE" &> /dev/null; then
|
327
|
+
ALL_ONLINE="false"
|
328
|
+
FAILED_CLIENTS="$NAME $FAILED_CLIENTS"
|
329
|
+
|
330
|
+
#Restart any chef clients that might have failed (do this once)
|
331
|
+
if [ -n "$RESTART_ON_FAILURE" ] && grep "$NAME:" $STATUS_MONITOR_DIR/status.out &> /dev/null && ! grep ":$NAME:" $TMP_RESTART &> /dev/null; then
|
332
|
+
echo ":$NAME:" >> $TMP_RESTART
|
333
|
+
ssh "$NAME" bash <<-EOF_SSH_CHEF_RESTART
|
334
|
+
$SERVICE_BIN chef-client restart
|
335
|
+
EOF_SSH_CHEF_RESTART
|
336
|
+
fi
|
337
|
+
|
338
|
+
#Restart any chef clients that haven't completed by timeout
|
339
|
+
if (( $COUNT >= $MAX_RETRY_COUNT )) && ! grep "$NAME:" $STATUS_MONITOR_DIR/status.out &> /dev/null && ! grep ":$NAME:" $TMP_RESTART &> /dev/null; then
|
340
|
+
echo ":$NAME:" >> $TMP_RESTART
|
341
|
+
ssh "$NAME" bash <<-EOF_SSH_CHEF_RESTART
|
342
|
+
$SERVICE_BIN chef-client restart
|
343
|
+
EOF_SSH_CHEF_RESTART
|
344
|
+
fi
|
345
|
+
fi
|
346
|
+
done
|
347
|
+
if [[ $ALL_ONLINE == "true" ]]; then
|
348
|
+
echo "All Chef client(s) ran successfully."
|
349
|
+
return 0
|
350
|
+
fi
|
351
|
+
COUNT=$(( $COUNT + 1 ))
|
352
|
+
sleep $SLEEP_COUNT
|
336
353
|
done
|
354
|
+
[ -f "$TMP_RESTART" ] && rm $TMP_RESTART
|
337
355
|
|
338
356
|
echo "Chef client(s) failed to run: $FAILED_CLIENTS"
|
339
357
|
return 1
|
@@ -5,7 +5,7 @@ require 'yaml'
|
|
5
5
|
module ChefVPCToolkit
|
6
6
|
|
7
7
|
module ChefInstaller
|
8
|
-
CHEF_INSTALL_FUNCTIONS=File.dirname(__FILE__) + "/
|
8
|
+
CHEF_INSTALL_FUNCTIONS=File.dirname(__FILE__) + "/chef_functions.bash"
|
9
9
|
|
10
10
|
def self.load_configs
|
11
11
|
|
@@ -74,7 +74,7 @@ json=JSON.parse(IO.read(options["chef_json_file"]))
|
|
74
74
|
configure_client_script=""
|
75
75
|
start_client_script=""
|
76
76
|
if json.has_key?(options["chef_server_name"]) then
|
77
|
-
configure_client_script="configure_chef_client '#{options['chef_server_name']}' ''"
|
77
|
+
configure_client_script="configure_chef_client '#{options['chef_server_name']}' '' '#{options['chef_interval']}'"
|
78
78
|
start_client_script="start_chef_client"
|
79
79
|
end
|
80
80
|
knife_add_nodes_script=""
|
@@ -172,7 +172,7 @@ def self.install_chef_client(options, client_name, client_validation_key, os_typ
|
|
172
172
|
#{IO.read(File.dirname(__FILE__) + "/cloud_files.bash")}
|
173
173
|
#{IO.read(CHEF_INSTALL_FUNCTIONS)}
|
174
174
|
#{install_chef_script('CLIENT', os_type)}
|
175
|
-
configure_chef_client '#{options['chef_server_name']}' '#{client_validation_key}'
|
175
|
+
configure_chef_client '#{options['chef_server_name']}' '#{client_validation_key}' '#{options['chef_interval']}'
|
176
176
|
start_chef_client
|
177
177
|
EOF_BASH
|
178
178
|
EOF_GATEWAY
|
@@ -296,13 +296,13 @@ def self.rsync_cookbook_repos(options, local_dir="#{CHEF_VPC_PROJECT}/cookbook-r
|
|
296
296
|
|
297
297
|
end
|
298
298
|
|
299
|
-
def self.poll_clients(options, client_names, timeout=600)
|
299
|
+
def self.poll_clients(options, client_names, timeout=600, restart_timeout=600, restart_once_on_failure="")
|
300
300
|
|
301
301
|
output=%x{
|
302
302
|
ssh -o "StrictHostKeyChecking no" root@#{options['ssh_gateway_ip']} bash <<-"EOF_GATEWAY"
|
303
303
|
ssh #{options['chef_server_name']} bash <<-"EOF_BASH"
|
304
304
|
#{IO.read(CHEF_INSTALL_FUNCTIONS)}
|
305
|
-
poll_chef_client_online "#{client_names}" "#{timeout}"
|
305
|
+
poll_chef_client_online "#{client_names}" "#{timeout}" "#{restart_timeout}" "#{restart_once_on_failure}"
|
306
306
|
EOF_BASH
|
307
307
|
EOF_GATEWAY
|
308
308
|
}
|
data/rake/chef_vpc_toolkit.rake
CHANGED
@@ -219,6 +219,8 @@ namespace :chef do
|
|
219
219
|
|
220
220
|
server_list=ENV['SERVER_NAME']
|
221
221
|
timeout=ENV['CHEF_TIMEOUT']
|
222
|
+
restart_timeout=ENV['CHEF_RESTART_TIMEOUT'] # restart if it takes this long
|
223
|
+
restart_on_failure=ENV['CHEF_RESTART_ON_FAILURE'] # restart once on failure
|
222
224
|
group=ServerGroup.fetch(:source => "cache")
|
223
225
|
if server_list.nil? or server_list.empty?
|
224
226
|
server_list=group.server_names.collect{|x| x+" "}.join.to_s
|
@@ -229,7 +231,7 @@ namespace :chef do
|
|
229
231
|
configs=ChefInstaller.load_configs
|
230
232
|
configs["ssh_gateway_ip"]=group.vpn_gateway_ip
|
231
233
|
puts "Polling for Chef clients to finish running..."
|
232
|
-
if not ChefInstaller.poll_clients(configs, server_list, timeout) then
|
234
|
+
if not ChefInstaller.poll_clients(configs, server_list, timeout, restart_timeout, restart_on_failure) then
|
233
235
|
raise "Chef client timeout."
|
234
236
|
end
|
235
237
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: chef-vpc-toolkit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 47
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 2.
|
8
|
+
- 8
|
9
|
+
- 0
|
10
|
+
version: 2.8.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dan Prince
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-11-
|
18
|
+
date: 2011-11-08 00:00:00 -05:00
|
19
19
|
default_executable: chef-vpc-toolkit
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -115,7 +115,6 @@ files:
|
|
115
115
|
- cookbook-repos/local/cookbooks/motd/templates/default/motd.erb
|
116
116
|
- cookbook-repos/local/roles/README
|
117
117
|
- lib/chef-vpc-toolkit.rb
|
118
|
-
- lib/chef-vpc-toolkit/chef-0.9.bash
|
119
118
|
- lib/chef-vpc-toolkit/chef_bootstrap/centos.bash
|
120
119
|
- lib/chef-vpc-toolkit/chef_bootstrap/debian.bash
|
121
120
|
- lib/chef-vpc-toolkit/chef_bootstrap/fedora.bash
|
@@ -123,6 +122,7 @@ files:
|
|
123
122
|
- lib/chef-vpc-toolkit/chef_bootstrap/ubuntu-opscode.bash
|
124
123
|
- lib/chef-vpc-toolkit/chef_bootstrap/ubuntu.bash
|
125
124
|
- lib/chef-vpc-toolkit/chef_bootstrap/unknown.bash
|
125
|
+
- lib/chef-vpc-toolkit/chef_functions.bash
|
126
126
|
- lib/chef-vpc-toolkit/chef_installer.rb
|
127
127
|
- lib/chef-vpc-toolkit/cloud-servers-vpc/client.rb
|
128
128
|
- lib/chef-vpc-toolkit/cloud-servers-vpc/connection.rb
|