chef-vpc-toolkit 2.3.2 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +3 -0
- data/VERSION +1 -1
- data/lib/chef-vpc-toolkit/chef-0.9.bash +104 -7
- data/lib/chef-vpc-toolkit/chef_installer.rb +17 -0
- data/rake/chef_vpc_toolkit.rake +21 -2
- metadata +5 -5
data/CHANGELOG
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.4.0
|
@@ -1,4 +1,6 @@
|
|
1
1
|
# Installation functions for Chef 0.8 RPMs obtained from the ELFF repo.
|
2
|
+
export CHEF_STATUS_PORT="1234"
|
3
|
+
export STATUS_MONITOR_DIR="/root/status_monitor"
|
2
4
|
|
3
5
|
function configure_chef_server {
|
4
6
|
|
@@ -28,18 +30,49 @@ $CLIENT_VALIDATION_KEY
|
|
28
30
|
sed -e "/^$/d" -i /etc/chef/validation.pem
|
29
31
|
fi
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
sed -e "s
|
33
|
+
local CLIENT_CONFIG="/etc/chef/client.rb"
|
34
|
+
local CHEF_NOTIFICATION_HANDLER=/var/lib/chef/handlers/netcat.rb
|
35
|
+
sed -e "s|localhost|$SERVER_NAME|g" -i $CLIENT_CONFIG
|
36
|
+
sed -e "s|^chef_server_url.*|chef_server_url \"http://$SERVER_NAME:4000\"|g" -i $CLIENT_CONFIG
|
37
|
+
sed -e "s|^log_location.*|log_location \"\/var/log/chef/client.log\"|g" -i $CLIENT_CONFIG
|
38
|
+
cat >> $CLIENT_CONFIG <<-EOF_CAT_CHEF_CLIENT_CONF
|
39
|
+
# custom Chef notification handler
|
40
|
+
require "$CHEF_NOTIFICATION_HANDLER"
|
41
|
+
netcat_handler = NetcatHandler.new
|
42
|
+
report_handlers << netcat_handler
|
43
|
+
exception_handlers << netcat_handler
|
44
|
+
EOF_CAT_CHEF_CLIENT_CONF
|
45
|
+
|
34
46
|
|
35
|
-
local
|
36
|
-
[ -d /etc/sysconfig/ ] &&
|
37
|
-
cat > $
|
47
|
+
local CHEF_SYSCONFIG=/etc/default/chef-client
|
48
|
+
[ -d /etc/sysconfig/ ] && CHEF_SYSCONFIG=/etc/sysconfig/chef-client
|
49
|
+
cat > $CHEF_SYSCONFIG <<-"EOF_CAT_CHEF_SYSCONFIG"
|
38
50
|
INTERVAL=600
|
39
51
|
SPLAY=20
|
40
52
|
CONFIG=/etc/chef/client.rb
|
41
53
|
LOGFILE=/var/log/chef/client.log
|
42
|
-
|
54
|
+
EOF_CAT_CHEF_SYSCONFIG
|
55
|
+
|
56
|
+
mkdir -p /var/lib/chef/handlers
|
57
|
+
cat > $CHEF_NOTIFICATION_HANDLER <<-EOF_CHEF_NOTIFY
|
58
|
+
require 'socket'
|
59
|
+
class NetcatHandler < Chef::Handler
|
60
|
+
def report
|
61
|
+
begin
|
62
|
+
socket = TCPSocket.open('$SERVER_NAME', $CHEF_STATUS_PORT)
|
63
|
+
hostname=%x{hostname}.chomp
|
64
|
+
if success?
|
65
|
+
socket.write("#{hostname}:ONLINE\n")
|
66
|
+
else
|
67
|
+
socket.write("#{hostname}:FAILURE\n")
|
68
|
+
end
|
69
|
+
socket.close()
|
70
|
+
rescue Exception => e
|
71
|
+
Chef::Log.error("Netcat handler failed: " + e.message)
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
EOF_CHEF_NOTIFY
|
43
76
|
|
44
77
|
}
|
45
78
|
|
@@ -131,6 +164,8 @@ knife node delete "$NODE_NAME.$DOMAIN_NAME" -y &> /dev/null || \
|
|
131
164
|
knife client delete "$NODE_NAME.$DOMAIN_NAME" -y &> /dev/null || \
|
132
165
|
{ echo "Failed to delete client with knife. Ignoring..."; }
|
133
166
|
|
167
|
+
#send a reset notification for the Chef client status monitor
|
168
|
+
echo "$NODE_NAME:RESET" | nc localhost $CHEF_STATUS_PORT
|
134
169
|
}
|
135
170
|
|
136
171
|
function knife_create_databag {
|
@@ -231,3 +266,65 @@ function start_chef_client {
|
|
231
266
|
fi
|
232
267
|
|
233
268
|
}
|
269
|
+
|
270
|
+
|
271
|
+
function start_notification_server {
|
272
|
+
|
273
|
+
|
274
|
+
[ -d "$STATUS_MONITOR_DIR" ] && return 0;
|
275
|
+
|
276
|
+
if [ -f /usr/bin/yum ]; then
|
277
|
+
rpm -q nc &> /dev/null || yum install -y -q nc
|
278
|
+
elif [ -f /usr/bin/dpkg ]; then
|
279
|
+
dpkg -L netcat-openbsd > /dev/null 2>&1 || apt-get install -y --quiet netcat-openbsd > /dev/null 2>&1
|
280
|
+
else
|
281
|
+
echo "Failed to install netcat. (for Chef client status monitoring)"
|
282
|
+
exit 1
|
283
|
+
fi
|
284
|
+
|
285
|
+
mkdir -p $STATUS_MONITOR_DIR
|
286
|
+
cat >> $STATUS_MONITOR_DIR/server.sh <<-EOF_NC_NOTIFY_SERVER
|
287
|
+
#!/bin/bash
|
288
|
+
while true; do
|
289
|
+
nc -d -k -l $CHEF_STATUS_PORT > $STATUS_MONITOR_DIR/status.out
|
290
|
+
done
|
291
|
+
EOF_NC_NOTIFY_SERVER
|
292
|
+
bash $STATUS_MONITOR_DIR/server.sh &> /dev/null < /dev/null &
|
293
|
+
|
294
|
+
if [ -f /etc/rc.local ]; then
|
295
|
+
echo "bash $STATUS_MONITOR_DIR/server.sh &> /dev/null < /dev/null &" >> /etc/rc.local
|
296
|
+
fi
|
297
|
+
|
298
|
+
}
|
299
|
+
|
300
|
+
function poll_chef_client_online {
|
301
|
+
|
302
|
+
local CLIENT_NAMES=${1:?"Please specify a chef client name."}
|
303
|
+
local SECS=${2:-"600"} #10 minutes
|
304
|
+
|
305
|
+
local SLEEP_COUNT=5
|
306
|
+
local COUNT=1
|
307
|
+
local MAX_COUNT=$(( $SECS / $SLEEP_COUNT ))
|
308
|
+
local FAILED_CLIENTS=""
|
309
|
+
local ALL_ONLINE="true"
|
310
|
+
until (( $COUNT == $MAX_COUNT )); do
|
311
|
+
ALL_ONLINE="true"
|
312
|
+
FAILED_CLIENTS=""
|
313
|
+
for NAME in $CLIENT_NAMES; do
|
314
|
+
if ! grep "$NAME:" $STATUS_MONITOR_DIR/status.out | tail -n 1 | grep -c ":ONLINE" &> /dev/null; then
|
315
|
+
ALL_ONLINE="false"
|
316
|
+
FAILED_CLIENTS="$NAME $FAILED_CLIENTS"
|
317
|
+
fi
|
318
|
+
done
|
319
|
+
if [[ $ALL_ONLINE == "true" ]]; then
|
320
|
+
echo "All Chef client(s) ran successfully."
|
321
|
+
return 0
|
322
|
+
fi
|
323
|
+
COUNT=$(( $COUNT + 1 ))
|
324
|
+
sleep $SLEEP_COUNT
|
325
|
+
done
|
326
|
+
|
327
|
+
echo "Chef client(s) failed to run: $FAILED_CLIENTS"
|
328
|
+
return 1
|
329
|
+
|
330
|
+
}
|
@@ -92,6 +92,7 @@ mkdir -p /root/cookbook-repos
|
|
92
92
|
|
93
93
|
configure_chef_server
|
94
94
|
start_chef_server
|
95
|
+
start_notification_server
|
95
96
|
|
96
97
|
#{configure_client_script}
|
97
98
|
|
@@ -279,6 +280,22 @@ def self.rsync_cookbook_repos(options, local_dir="#{CHEF_VPC_PROJECT}/cookbook-r
|
|
279
280
|
|
280
281
|
end
|
281
282
|
|
283
|
+
def self.poll_clients(options, client_names, timeout=600)
|
284
|
+
|
285
|
+
output=%x{
|
286
|
+
ssh -o "StrictHostKeyChecking no" root@#{options['ssh_gateway_ip']} bash <<-"EOF_GATEWAY"
|
287
|
+
ssh #{options['chef_server_name']} bash <<-"EOF_BASH"
|
288
|
+
#{IO.read(CHEF_INSTALL_FUNCTIONS)}
|
289
|
+
poll_chef_client_online "#{client_names}" "#{timeout}"
|
290
|
+
EOF_BASH
|
291
|
+
EOF_GATEWAY
|
292
|
+
}
|
293
|
+
retval=$?
|
294
|
+
puts output
|
295
|
+
return retval.success?
|
296
|
+
|
297
|
+
end
|
298
|
+
|
282
299
|
end
|
283
300
|
|
284
301
|
end
|
data/rake/chef_vpc_toolkit.rake
CHANGED
@@ -189,7 +189,7 @@ namespace :chef do
|
|
189
189
|
|
190
190
|
lines=ENV['LINES']
|
191
191
|
server=ENV['SERVER_NAME']
|
192
|
-
if server
|
192
|
+
if server and server.empty?
|
193
193
|
server=nil
|
194
194
|
end
|
195
195
|
if lines.nil? or lines.empty? then
|
@@ -198,7 +198,7 @@ namespace :chef do
|
|
198
198
|
configs=ChefInstaller.load_configs
|
199
199
|
group=ServerGroup.fetch(:source => "cache")
|
200
200
|
group.server_names do |name|
|
201
|
-
if server
|
201
|
+
if server and server != name
|
202
202
|
next
|
203
203
|
end
|
204
204
|
|
@@ -209,6 +209,25 @@ namespace :chef do
|
|
209
209
|
|
210
210
|
end
|
211
211
|
|
212
|
+
desc "Poll for Chef clients to finish running."
|
213
|
+
task :poll_clients do
|
214
|
+
|
215
|
+
server_list=ENV['SERVER_NAME']
|
216
|
+
timeout=ENV['CHEF_TIMEOUT']
|
217
|
+
group=ServerGroup.fetch(:source => "cache")
|
218
|
+
if server_list.nil? or server_list.empty?
|
219
|
+
server_list=group.server_names.collect{|x| x+" "}.to_s
|
220
|
+
end
|
221
|
+
if timeout.nil? or timeout.empty?
|
222
|
+
timeout=600
|
223
|
+
end
|
224
|
+
configs=ChefInstaller.load_configs
|
225
|
+
configs["ssh_gateway_ip"]=group.vpn_gateway_ip
|
226
|
+
puts "Polling for Chef clients to finish running..."
|
227
|
+
ChefInstaller.poll_clients(configs, server_list, timeout)
|
228
|
+
|
229
|
+
end
|
230
|
+
|
212
231
|
#Deprecated
|
213
232
|
task :sync_repos => "chef:push_repos"
|
214
233
|
|
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: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 2.
|
8
|
+
- 4
|
9
|
+
- 0
|
10
|
+
version: 2.4.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-03-
|
18
|
+
date: 2011-03-28 00:00:00 -04:00
|
19
19
|
default_executable: chef-vpc-toolkit
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|