diff options
Diffstat (limited to 'chef/examples/sample_definition.rb')
-rw-r--r-- | chef/examples/sample_definition.rb | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/chef/examples/sample_definition.rb b/chef/examples/sample_definition.rb new file mode 100644 index 0000000000..f536369290 --- /dev/null +++ b/chef/examples/sample_definition.rb @@ -0,0 +1,82 @@ +web_server "monchichi" do + one "something" + two "something else" +end + +runit_service "bobo" do + directory "monkey" + downif "/bin/false is true" + templatedir "something" +end + +define :runit_service, :directory => "/etc/sv", :downif => "/bin/false", :templatedir => nil do + require_recipe "runit" + + validate( + params, + { + :directory => { :required => true }, + :downif => { :required => true }, + :templatedir => { :required => false }, + } + ) + + file "#{param[:directory]}-#{param[:name]}" do + path "#{param[:directory]}/#{param[:name]}" + insure "directory" + owner "root" + group "root" + mode 0755 + end + + file "#{param[:directory]}/#{param[:name]}/log" do + insure "directory" + owner "root" + group "root" + mode 0755 + end + + file "#{param[:directory]}/#{param[:name]}/log/main" do + insure "directory" + owner "root" + group "root" + mode 0755 + end + + symlink "/etc/init.d/#{param[:name]}" do + sv_dir = case node[:lsbdistid] + when 'CentOS': "/usr/local/bin/sv" + else: "/usr/bin/sv" + end + source_file = sv_dir + end + + symlink "/var/service/#{param[:name]}" do + source_file "#{param[:directory]}/#{param[:name]}" + end + + service "#{param[:name]}" do + supports :status => true, :restart => true + end + + template_file "#{param[:directory]}/#{param[:name]}/log/run" do + content "#{param[:templatedir]}/log-run.erb" + owner "root" + group "root" + mode 755 + notifies resource("service[#{param[:name]}]") + end + + template_file "#{param[:directory]}/#{param[:name]}/run" do + content "#{param[:templatedir]}/run.erb" + owner root + group root + mode 755 + notifies resource("service[#{param[:name]}]") + end + + exec "#{param[:name]}-down" do + command "/etc/init.d/#{param[:name]} down" + only_if "#{downif}" + end +end |