diff --git a/providers/helper.rb b/providers/helper.rb index 9c9a46f..929dbf9 100644 --- a/providers/helper.rb +++ b/providers/helper.rb @@ -1,3 +1,5 @@ +include Chef::Mixin::ShellOut + def resource_exists?(name) cmd = Mixlib::ShellOut.new("crm configure show | grep #{name}") cmd.environment['HOME'] = ENV.fetch('HOME', '/root') @@ -9,3 +11,10 @@ def resource_exists?(name) false end end + +def resource_running?(name) + cmd = shell_out! "crm", "resource", "status", name + Chef::Log.info cmd.stdout + cmd.stdout.include? "resource #{name} is running" +end + diff --git a/providers/primitive.rb b/providers/primitive.rb index 61c3eac..091952e 100644 --- a/providers/primitive.rb +++ b/providers/primitive.rb @@ -84,3 +84,19 @@ action :delete do new_resource.updated_by_last_action(true) Chef::Log.info "Deleted primitive '#{name}'." end + +action :start do + name = new_resource.name + raise "no such resource #{name}" unless resource_exists?(name) + next if resource_running?(name) + shell_out! %w(crm resource start) + [name] + Chef::Log.info "Successfully started primitive '#{name}'." +end + +action :stop do + name = new_resource.name + raise "no such resource #{name}" unless resource_exists?(name) + next unless resource_running?(name) + shell_out! %w(crm resource stop) + [name] + Chef::Log.info "Successfully stopped primitive '#{name}'." +end diff --git a/resources/primitive.rb b/resources/primitive.rb index 925a051..acbc605 100644 --- a/resources/primitive.rb +++ b/resources/primitive.rb @@ -17,7 +17,7 @@ # limitations under the License. # -actions :create, :delete +actions :create, :delete, :start, :stop default_action :create