From d1e074afd06c8062328a3798a4933a6fa0a2289d Mon Sep 17 00:00:00 2001 From: Alexandre Marangone Date: Thu, 21 Mar 2013 11:02:32 -0700 Subject: [PATCH] Upstart and SYSV Init support - Handles different service names between upstart and sysvinit. - Create mon_dir/(upstart|sysvinit) depending on service to be used. Signed-off-by: Alexandre Marangone --- libraries/default.rb | 9 +++++++++ recipes/mon.rb | 22 ++++++++++++++++------ recipes/osd.rb | 17 ++++++++++++----- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/libraries/default.rb b/libraries/default.rb index 687e3d7..308d883 100644 --- a/libraries/default.rb +++ b/libraries/default.rb @@ -118,3 +118,12 @@ def have_quorum?() state = JSON.parse(mon_status)['state'] return QUORUM_STATES.include?(state) end + +def service_type() + case node['platform'] + when 'ubuntu' + return "upstart" + else + return "sysvinit" + end +end diff --git a/recipes/mon.rb b/recipes/mon.rb index 4b96429..f523d0e 100644 --- a/recipes/mon.rb +++ b/recipes/mon.rb @@ -19,11 +19,21 @@ require 'json' include_recipe "ceph::default" include_recipe "ceph::conf" -service "ceph-mon-all-starter" do - provider Chef::Provider::Service::Upstart - action [:enable] +service_type = service_type() +service "ceph_mon" do + case service_type + when "upstart" + service_name "ceph-mon-all-starter" + provider Chef::Provider::Service::Upstart + action :enable + when "sysvinit" + service_name "ceph" + provider Chef::Provider::Service::Init + end + supports :restart => true end + # TODO cluster name cluster = 'ceph' @@ -43,11 +53,11 @@ ceph-authtool "$KR" --create-keyring --name=mon. --add-key='#{node["ceph"]["moni 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']}/upstart +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"]}/upstart' - notifies :start, "service[ceph-mon-all-starter]", :immediately + creates "/var/lib/ceph/mon/ceph-#{node["hostname"]}/#{service_type}" + notifies :start, "service[ceph_mon]", :immediately end ruby_block "tell ceph-mon about its peers" do diff --git a/recipes/osd.rb b/recipes/osd.rb index c79a229..ce26224 100644 --- a/recipes/osd.rb +++ b/recipes/osd.rb @@ -44,11 +44,18 @@ if !search(:node,"hostname:#{node['hostname']} AND dmcrypt:true").empty? end end -service "ceph-osd-all" do - provider Chef::Provider::Service::Upstart - service_name "ceph-osd-all" +service_type = service_type() +service "ceph_osd" do + case service_type + when "sysvinit" + service_name "ceph" + provider Chef::Provider::Service::Init + when "upstart" + service_name "ceph-osd-all" + provider Chef::Provider::Service::Upstart + action :enable + end supports :restart => true - action :enable end mons = get_mon_nodes("ceph_bootstrap_osd_key:*") @@ -130,7 +137,7 @@ else execute "Creating Ceph OSD on #{osd_device['device']}" do command "ceph-disk-prepare #{dmcrypt} #{osd_device['device']}" action :run - notifies :start, "service[ceph-osd-all]", :immediately + notifies :start, "service[ceph_osd]", :immediately end # we add this status to the node env # so that we can implement recreate