]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph-cookbooks.git/commitdiff
creates prevent re-run
authorGuilhem Lettron <guilhem@lettron.fr>
Thu, 21 Mar 2013 09:51:27 +0000 (10:51 +0100)
committerGuilhem Lettron <guilhem@lettron.fr>
Thu, 2 May 2013 09:09:00 +0000 (11:09 +0200)
refactor to use chef commands
move ceph_bootstrap_osd_key to node['ceph']

we must wait for get osd-bootstrap keyring to finish

Last fixes
create /var/lib/ceph/mon/ceph-{hostname} directory if it doesn't exist.
remove ceph.mon.node attribute (more reflexion to this behaviour later)
fix typo for done file
service ceph-mon-all support restart and status
service must be restart immediately to launch ceph-mon

correct rebase

recipes/mon.rb
recipes/osd.rb

index f202c32d543156e9e0aa0019dbd6db5b48a45aad..0d15dc9f5d899327c0905ab1a6575eccf7027e4e 100644 (file)
@@ -33,56 +33,66 @@ service "ceph_mon" do
   supports :restart => true
 end
 
+directory "/var/run/ceph" do
+  owner "root"
+  group "root"
+  mode 00644
+  recursive true
+  action :create
+end
+
+directory "/var/lib/ceph/mon/ceph-#{node["hostname"]}" do
+  owner "root"
+  group "root"
+  mode 00644
+  recursive true
+  action :create
+end
+
 # TODO cluster name
 cluster = 'ceph'
 
-execute 'ceph-mon mkfs' do
-  command <<-EOH
-set -e
-mkdir -p /var/run/ceph
-mkdir -p /var/lib/ceph/mon/ceph-#{node['hostname']}
-# TODO chef creates doesn't seem to suppressing re-runs, do it manually
-if [ -e '/var/lib/ceph/mon/ceph-#{node["hostname"]}/done' ]; then
-  echo 'ceph-mon mkfs already done, skipping'
-  exit 0
-fi
-KR='/var/lib/ceph/tmp/#{cluster}-#{node['hostname']}.mon.keyring'
-# TODO don't put the key in "ps" output, stdout
-ceph-authtool "$KR" --create-keyring --name=mon. --add-key='#{node["ceph"]["monitor-secret"]}' --cap mon 'allow *'
+unless File.exists?("/var/lib/ceph/mon/ceph-#{node["hostname"]}/done")
+  keyring = "#{Chef::Config[:file_cache_path]}/#{cluster}-#{node['hostname']}.mon.keyring"
 
-ceph-mon --mkfs -i #{node['hostname']} --keyring "$KR"
-rm -f -- "$KR"
-touch /var/lib/ceph/mon/ceph-#{node['hostname']}/done
-touch /var/lib/ceph/mon/ceph-#{node['hostname']}/#{service_type}
-EOH
-  creates '/var/lib/ceph/mon/ceph-#{node["hostname"]}/done'
-  creates "/var/lib/ceph/mon/ceph-#{node["hostname"]}/#{service_type}"
-  notifies :start, "service[ceph_mon]", :immediately
-end
+  execute "format as keyring" do
+    command "ceph-authtool '#{keyring}' --create-keyring --name=mon. --add-key='#{node["ceph"]["monitor-secret"]}' --cap mon 'allow *'"
+    creates "#{Chef::Config[:file_cache_path]}/#{cluster}-#{node['hostname']}.mon.keyring"
+  end
 
-ruby_block "tell ceph-mon about its peers" do
-  block do
-    mon_addresses = get_mon_addresses()
-    mon_addresses.each do |addr|
-      system 'ceph', \
-        '--admin-daemon', "/var/run/ceph/ceph-mon.#{node['hostname']}.asok", \
-        'add_bootstrap_peer_hint', addr
-      # ignore errors
+  execute 'ceph-mon mkfs' do
+    command "ceph-mon --mkfs -i #{node['hostname']} --keyring '#{keyring}'"
+    notifies :restart, "service[ceph_mon]", :immediately
+  end
+
+  ruby_block "finalise" do
+    block do
+      ["done", service_type].each do |ack|
+        File.open("/var/lib/ceph/mon/ceph-#{node["hostname"]}/#{ack}", "w").close()
+      end
     end
   end
 end
 
+get_mon_addresses().each do |addr|
+  execute "peer #{addr}" do
+    command "ceph --admin-daemon '/var/run/ceph/ceph-mon.#{node['hostname']}.asok' add_bootstrap_peer_hint #{addr}"
+    ignore_failure true
+  end
+end
+
 # The key is going to be automatically
 # created,
 # We store it when it is created
 ruby_block "get osd-bootstrap keyring" do
   block do
-    osd_bootstrap_key = ""
-    while osd_bootstrap_key.empty? do
-       osd_bootstrap_key = %x[ ceph auth get-key client.bootstrap-osd ]
-       sleep(1)
+    run_out = ""
+    while run_out.empty?
+      run_out = Chef::ShellOut.new("ceph auth get-key client.bootstrap-osd").run_command.stdout.strip
+      sleep 2
     end
-    node.override['ceph_bootstrap_osd_key'] = osd_bootstrap_key
+    node.override['ceph']['bootstrap_osd_key'] = run_out
     node.save
   end
+  not_if { node['ceph']['bootstrap_osd_key'] }
 end
index 526d08312d29bfe4156b39937db97dca78ad503e..20bc04d85849c4cbc969b81765a39197cf05e0a5 100644 (file)
@@ -74,7 +74,7 @@ else
   cluster = 'ceph'
 
   execute "format as keyring" do
-    command "ceph-authtool '/var/lib/ceph/bootstrap-osd/#{cluster}.keyring' --create-keyring --name=client.bootstrap-osd --add-key='#{mons[0]["ceph_bootstrap_osd_key"]}'"
+    command "ceph-authtool '/var/lib/ceph/bootstrap-osd/#{cluster}.keyring' --create-keyring --name=client.bootstrap-osd --add-key='#{mons[0]["ceph"]["bootstrap_osd_key"]}'"
     creates "/var/lib/ceph/bootstrap-osd/#{cluster}.keyring"
   end