<commit_before># This recipe creates a monitor cluster
#
# You should never change the mon default path or
# the keyring path.
# Don't change the cluster name either
# Default path for mon data: /var/lib/ceph/mon/$cluster-$id/
#   which will be /var/lib/ceph/mon/ceph-`hostname`/
#   This path is used by upstart. If changed, upstart won't
#   start the monitor
# The keyring files are created using the following pattern:
#  /etc/ceph/$cluster.client.$name.keyring
#  e.g. /etc/ceph/ceph.client.admin.keyring
#  The bootstrap-osd and bootstrap-mds keyring are a bit
#  different and are created in
#  /var/lib/ceph/bootstrap-{osd,mds}/ceph.keyring

require 'json'

include_recipe "ceph::default"
include_recipe "ceph::conf"

service_type = node["ceph"]["mon"]["init_style"]
service "ceph_mon" do
  case service_type
  when "upstart"
    service_name "ceph-mon-all"
    provider Chef::Provider::Service::Upstart
    action :enable
  when "sysvinit"
    service_name "ceph"
    provider Chef::Provider::Service::Init
  end
  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'

unless File.exists?("/var/lib/ceph/mon/ceph-#{node["hostname"]}/done")
  keyring = "#{Chef::Config[:file_cache_path]}/#{cluster}-#{node['hostname']}.mon.keyring"

  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

  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
    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'] = run_out
    node.save
  end
  not_if { node['ceph']['bootstrap_osd_key'] }
end
<commit_msg>Place service at the end of script to ensure that service is always enable and running after chef is execute<commit_after># This recipe creates a monitor cluster
#
# You should never change the mon default path or
# the keyring path.
# Don't change the cluster name either
# Default path for mon data: /var/lib/ceph/mon/$cluster-$id/
#   which will be /var/lib/ceph/mon/ceph-`hostname`/
#   This path is used by upstart. If changed, upstart won't
#   start the monitor
# The keyring files are created using the following pattern:
#  /etc/ceph/$cluster.client.$name.keyring
#  e.g. /etc/ceph/ceph.client.admin.keyring
#  The bootstrap-osd and bootstrap-mds keyring are a bit
#  different and are created in
#  /var/lib/ceph/bootstrap-{osd,mds}/ceph.keyring

require 'json'

include_recipe "ceph::default"
include_recipe "ceph::conf"

service_type = node["ceph"]["mon"]["init_style"]

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'

unless File.exists?("/var/lib/ceph/mon/ceph-#{node["hostname"]}/done")
  keyring = "#{Chef::Config[:file_cache_path]}/#{cluster}-#{node['hostname']}.mon.keyring"

  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

  execute 'ceph-mon mkfs' do
    command "ceph-mon --mkfs -i #{node['hostname']} --keyring '#{keyring}'"
  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

service "ceph_mon" do
  case service_type
  when "upstart"
    service_name "ceph-mon-all"
    provider Chef::Provider::Service::Upstart
  when "sysvinit"
    service_name "ceph"
    provider Chef::Provider::Service::Init
  end
  supports :restart => true
  action [ :enable, :start ]
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
    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'] = run_out
    node.save
  end
  not_if { node['ceph']['bootstrap_osd_key'] }
end

{'fraction_non_alphanumeric': 0.14647987231778684, 'fraction_numerical': 0.0039014009576165986, 'mean_word_length': 3.83704974271012, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5652187', 'n_tokens_mistral': 1990, 'n_tokens_neox': 1994, 'n_words': 512}