abiquo-chef-agent 1.0.10 → 1.0.11

Sign up to get free protection for your applications and to get access to all the features.
data/bin/abiquo-chef-run CHANGED
@@ -145,11 +145,36 @@ else
145
145
  end
146
146
  end
147
147
 
148
+
149
+ #
150
+ # Set the hostname
151
+ #
152
+ node_name = bootstrap_config.node_name
153
+
154
+ log "Setting hostname"
155
+ output = `hostname #{node_name} 2>&1`
156
+ log output, :debug
157
+
158
+ net_config_file = '/etc/sysconfig/network'
159
+ if File.exists? net_config_file
160
+ log "Configuring /etc/sysconfig/network with the new hostname"
161
+ data = File.read net_config_file
162
+ File.open net_config_file, 'w' do |f|
163
+ data.each_line {|l| l.include?('HOSTNAME') ? f.puts("HOSTNAME=#{node_name}\n") : f.puts(l)}
164
+ end
165
+ end
166
+ File.open('/etc/hostname', 'w') do |f|
167
+ f.puts node_name
168
+ end
169
+ File.open('/etc/hosts', 'a') do |f|
170
+ f.puts "127.0.0.1 #{node_name}"
171
+ end
172
+ log "done"
173
+
148
174
  #
149
175
  # Everything in place, no run the client
150
176
  #
151
177
  # first, we run it once to register and apply recipes
152
- node_name = bootstrap_config.node_name
153
178
  cmd = "chef-client -N #{node_name} --once -j /etc/chef/first-boot.json -L /var/log/chef-client.log"
154
179
  log "Running chef-client first time"
155
180
  log cmd
@@ -169,25 +194,21 @@ else
169
194
  log "chef-client run failed", :error
170
195
  log output, :debug
171
196
  else
172
- log "Setting hostname"
173
- output = `hostname #{node_name} 2>&1`
174
- log output, :debug
175
- File.open('/etc/hostname', 'w') do |f|
176
- f.puts node_name
177
- end
178
- File.open('/etc/hosts', 'a') do |f|
179
- f.puts "127.0.0.1 #{node_name}"
180
- end
181
- log "chef-client run OK"
182
197
  log "Running chef-client in daemon mode"
183
- # Now we run it in daemon mode
184
- cmd = "chef-client -N #{node_name} -i 1800 -d -L /var/log/chef-client.log"
185
- output = `#{cmd}`
186
- if $? != 0
187
- log "Running chef-client in daemon mode failed.", :error
188
- log output, :debug
198
+ # Run the chef-client if not already running
199
+ if not (`ps aux|grep "chef-client "| grep -v grep|wc -l`.to_i > 0)
200
+ # Now we run it in daemon mode
201
+ cmd = "chef-client -N #{node_name} -i 1800 -d -L /var/log/chef-client.log"
202
+ output = `#{cmd}`
203
+ if $? != 0
204
+ log "Running chef-client in daemon mode failed.", :error
205
+ log output, :debug
206
+ else
207
+ log "Success."
208
+ end
189
209
  else
190
- log "Success."
210
+ log "chef-client already running."
211
+ log `ps aux|grep "chef-client "| grep -v grep`
191
212
  end
192
213
  end
193
214
  end
@@ -3,7 +3,7 @@ require 'xmlsimple'
3
3
  module Abiquo
4
4
  module Chef
5
5
 
6
- VERSION="1.0.10"
6
+ VERSION="1.0.11"
7
7
 
8
8
  class Config
9
9
  def self.chef_config_dir
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: abiquo-chef-agent
3
3
  version: !ruby/object:Gem::Version
4
- hash: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 10
10
- version: 1.0.10
9
+ - 11
10
+ version: 1.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Salvador Girones
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2012-10-16 00:00:00 Z
19
+ date: 2012-10-26 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  requirement: &id001 !ruby/object:Gem::Requirement