From 07693d6922ed515c7011b8b3d2b0e04acb972a74 Mon Sep 17 00:00:00 2001 From: Ami Rahav Date: Sun, 14 Dec 2014 12:09:54 -0500 Subject: [PATCH] add missing supervisord cookbook --- cookbooks/supervisord/.gitignore | 1 + cookbooks/supervisord/CHANGELOG.md | 14 ++ cookbooks/supervisord/Gemfile | 6 + cookbooks/supervisord/Gemfile.lock | 223 ------------------ cookbooks/supervisord/README.md | 35 +++ cookbooks/supervisord/Strainerfile | 3 + cookbooks/supervisord/metadata.json | 31 +++ cookbooks/supervisord/metadata.rb | 10 + cookbooks/supervisord/providers/program.rb | 29 +++ cookbooks/supervisord/recipes/default.rb | 6 + cookbooks/supervisord/recipes/example.rb | 54 +++++ cookbooks/supervisord/resources/program.rb | 71 ++++++ .../default/supervised-program.conf.erb | 5 + .../default/supervised-program.conf.erb~ | 13 + 14 files changed, 278 insertions(+), 223 deletions(-) create mode 100644 cookbooks/supervisord/.gitignore create mode 100644 cookbooks/supervisord/CHANGELOG.md create mode 100644 cookbooks/supervisord/Gemfile delete mode 100644 cookbooks/supervisord/Gemfile.lock create mode 100644 cookbooks/supervisord/README.md create mode 100644 cookbooks/supervisord/Strainerfile create mode 100644 cookbooks/supervisord/metadata.json create mode 100644 cookbooks/supervisord/metadata.rb create mode 100644 cookbooks/supervisord/providers/program.rb create mode 100644 cookbooks/supervisord/recipes/default.rb create mode 100644 cookbooks/supervisord/recipes/example.rb create mode 100644 cookbooks/supervisord/resources/program.rb create mode 100644 cookbooks/supervisord/templates/default/supervised-program.conf.erb create mode 100644 cookbooks/supervisord/templates/default/supervised-program.conf.erb~ diff --git a/cookbooks/supervisord/.gitignore b/cookbooks/supervisord/.gitignore new file mode 100644 index 0000000..24fe853 --- /dev/null +++ b/cookbooks/supervisord/.gitignore @@ -0,0 +1 @@ +/.bundle diff --git a/cookbooks/supervisord/CHANGELOG.md b/cookbooks/supervisord/CHANGELOG.md new file mode 100644 index 0000000..c869606 --- /dev/null +++ b/cookbooks/supervisord/CHANGELOG.md @@ -0,0 +1,14 @@ +Changes +======= + +1.0.1 +----- +- Add missing `stopwaitsecs` setting. + +1.0.0 +----- + +- foodcritic / chefspec tests +- simplify providers (don't use "linked service") +- docs +- support all supervisord.conf options diff --git a/cookbooks/supervisord/Gemfile b/cookbooks/supervisord/Gemfile new file mode 100644 index 0000000..3963a4f --- /dev/null +++ b/cookbooks/supervisord/Gemfile @@ -0,0 +1,6 @@ +source 'https://rubygems.org/' + +gem 'chef', '~> 11.8' +gem 'chefspec', '~> 3.0' +gem 'foodcritic', '~> 3.0' +gem 'strainer' diff --git a/cookbooks/supervisord/Gemfile.lock b/cookbooks/supervisord/Gemfile.lock deleted file mode 100644 index 8cbc25f..0000000 --- a/cookbooks/supervisord/Gemfile.lock +++ /dev/null @@ -1,223 +0,0 @@ -GEM - remote: https://rubygems.org/ - specs: - activesupport (3.2.16) - i18n (~> 0.6, >= 0.6.4) - multi_json (~> 1.0) - addressable (2.3.5) - akami (1.2.0) - gyoku (>= 0.4.0) - nokogiri (>= 1.4.0) - berkshelf (2.0.12) - activesupport (~> 3.2.0) - addressable (~> 2.3.4) - buff-shell_out (~> 0.1) - chozo (>= 0.6.1) - faraday (~> 0.8.5) - hashie (>= 2.0.2) - minitar (~> 0.5.4) - rbzip2 (~> 0.2.0) - retryable (~> 1.3.3) - ridley (~> 1.5.0) - solve (>= 0.5.0) - thor (~> 0.18.0) - buff-config (0.4.0) - buff-extensions (~> 0.3) - varia_model (~> 0.1) - buff-extensions (0.5.0) - buff-ignore (1.1.1) - buff-platform (0.1.0) - buff-ruby_engine (0.1.0) - buff-shell_out (0.1.1) - buff-ruby_engine (~> 0.1.0) - builder (3.2.2) - celluloid (0.14.1) - timers (>= 1.0.0) - celluloid-io (0.14.1) - celluloid (>= 0.14.1) - nio4r (>= 0.4.5) - chef (11.8.0) - chef-zero (~> 1.6, >= 1.6.2) - diff-lcs (~> 1.2, >= 1.2.4) - erubis (~> 2.7) - highline (~> 1.6, >= 1.6.9) - json (>= 1.4.4, <= 1.7.7) - mime-types (~> 1.16) - mixlib-authentication (~> 1.3) - mixlib-cli (~> 1.3) - mixlib-config (~> 2.0) - mixlib-log (~> 1.3) - mixlib-shellout (~> 1.2) - net-ssh (~> 2.6) - net-ssh-multi (~> 1.1.0) - ohai (~> 6.0) - pry (~> 0.9) - puma (~> 1.6) - rest-client (>= 1.0.4, < 1.7.0) - yajl-ruby (~> 1.1) - chef-zero (1.7.2) - hashie (~> 2.0) - json - mixlib-log (~> 1.3) - moneta (< 0.7.0) - rack - chefspec (3.1.4) - chef (~> 11.0) - fauxhai (~> 2.0) - i18n (>= 0.6.9, < 1.0.0) - rspec (~> 2.14) - chozo (0.6.1) - activesupport (>= 3.2.0) - hashie (>= 2.0.2) - multi_json (>= 1.3.0) - coderay (1.1.0) - diff-lcs (1.2.5) - erubis (2.7.0) - faraday (0.8.9) - multipart-post (~> 1.2.0) - fauxhai (2.0.1) - net-ssh - ohai - ffi (1.9.3) - foodcritic (3.0.3) - erubis - gherkin (~> 2.11.7) - nokogiri (~> 1.5.4) - rake - treetop (~> 1.4.10) - yajl-ruby (~> 1.1.0) - gherkin (2.11.8) - multi_json (~> 1.3) - gssapi (1.0.3) - ffi (>= 1.0.1) - gyoku (1.1.1) - builder (>= 2.1.2) - hashie (2.0.5) - highline (1.6.20) - hitimes (1.2.1) - httpclient (2.3.4.1) - httpi (0.9.7) - rack - i18n (0.6.9) - ipaddress (0.8.0) - json (1.7.7) - little-plugger (1.1.3) - logging (1.8.1) - little-plugger (>= 1.1.3) - multi_json (>= 1.3.6) - method_source (0.8.2) - mime-types (1.25.1) - minitar (0.5.4) - mixlib-authentication (1.3.0) - mixlib-log - mixlib-cli (1.4.0) - mixlib-config (2.1.0) - mixlib-log (1.6.0) - mixlib-shellout (1.3.0) - moneta (0.6.0) - multi_json (1.8.4) - multipart-post (1.2.0) - net-http-persistent (2.9) - net-ssh (2.7.0) - net-ssh-gateway (1.2.0) - net-ssh (>= 2.6.5) - net-ssh-multi (1.1) - net-ssh (>= 2.1.4) - net-ssh-gateway (>= 0.99.0) - nio4r (0.5.0) - nokogiri (1.5.11) - nori (1.1.5) - ohai (6.20.0) - ipaddress - mixlib-cli - mixlib-config - mixlib-log - mixlib-shellout - systemu (~> 2.5.2) - yajl-ruby - polyglot (0.3.3) - pry (0.9.12.4) - coderay (~> 1.0) - method_source (~> 0.8) - slop (~> 3.4) - puma (1.6.3) - rack (~> 1.2) - rack (1.5.2) - rake (10.1.1) - rbzip2 (0.2.0) - rest-client (1.6.7) - mime-types (>= 1.16) - retryable (1.3.4) - ridley (1.5.3) - addressable - buff-config (~> 0.2) - buff-extensions (~> 0.3) - buff-ignore (~> 1.1) - buff-shell_out (~> 0.1) - celluloid (~> 0.14.0) - celluloid-io (~> 0.14.0) - erubis - faraday (>= 0.8.4) - hashie (>= 2.0.2) - json (>= 1.7.7) - mixlib-authentication (>= 1.3.0) - net-http-persistent (>= 2.8) - net-ssh - nio4r (>= 0.5.0) - retryable - solve (>= 0.4.4) - varia_model (~> 0.1) - winrm (~> 1.1.0) - rspec (2.14.1) - rspec-core (~> 2.14.0) - rspec-expectations (~> 2.14.0) - rspec-mocks (~> 2.14.0) - rspec-core (2.14.7) - rspec-expectations (2.14.4) - diff-lcs (>= 1.1.3, < 2.0) - rspec-mocks (2.14.4) - rubyntlm (0.1.1) - savon (0.9.5) - akami (~> 1.0) - builder (>= 2.1.2) - gyoku (>= 0.4.0) - httpi (~> 0.9) - nokogiri (>= 1.4.0) - nori (~> 1.0) - wasabi (~> 1.0) - slop (3.4.7) - solve (0.8.2) - strainer (3.3.0) - berkshelf (~> 2.0) - buff-platform (~> 0.1) - systemu (2.5.2) - thor (0.18.1) - timers (2.0.0) - hitimes - treetop (1.4.15) - polyglot - polyglot (>= 0.3.1) - uuidtools (2.1.4) - varia_model (0.2.0) - buff-extensions (~> 0.2) - hashie (>= 2.0.2) - wasabi (1.0.0) - nokogiri (>= 1.4.0) - winrm (1.1.3) - gssapi (~> 1.0.0) - httpclient (~> 2.2, >= 2.2.0.2) - logging (~> 1.6, >= 1.6.1) - nokogiri (~> 1.5) - rubyntlm (~> 0.1.1) - savon (= 0.9.5) - uuidtools (~> 2.1.2) - yajl-ruby (1.1.0) - -PLATFORMS - ruby - -DEPENDENCIES - chef (~> 11.8) - chefspec (~> 3.0) - foodcritic (~> 3.0) - strainer diff --git a/cookbooks/supervisord/README.md b/cookbooks/supervisord/README.md new file mode 100644 index 0000000..206d6d5 --- /dev/null +++ b/cookbooks/supervisord/README.md @@ -0,0 +1,35 @@ +Supervisord cookbook +==================== + +This cookbook installs +[Supervisord](http://supervisord.org/configuration.html) and provides +a resource to supervise programs. + +Usage +----- + +Include `recipe[supervisord]` in your run list, and +`supervisord_program` resource to configure individual programs. See +`See recipes/example.rb` for sample usage + +Resources +--------- + +## `supervisord_program` + +### Actions + +- `:supervise` (default): add program to supervisord config +- `:start`, `:stop`, `:restart`: manage service + +### Attribute parameters + +- `:name` (name attribute) +- `:command` (required) +- all settings of a `[program:X]` section of supervisord config + +Authors +------- + +* Maciej Pasternacki +* Dan Crosta diff --git a/cookbooks/supervisord/Strainerfile b/cookbooks/supervisord/Strainerfile new file mode 100644 index 0000000..fdfa767 --- /dev/null +++ b/cookbooks/supervisord/Strainerfile @@ -0,0 +1,3 @@ +knife test: bundle exec knife cookbook test $COOKBOOK +foodcritic: bundle exec foodcritic -f any $SANDBOX/$COOKBOOK +chefspec: bundle exec rspec $SANDBOX/$COOKBOOK diff --git a/cookbooks/supervisord/metadata.json b/cookbooks/supervisord/metadata.json new file mode 100644 index 0000000..d55546c --- /dev/null +++ b/cookbooks/supervisord/metadata.json @@ -0,0 +1,31 @@ +{ + "name": "supervisord", + "description": "Installs/Configures supervisord", + "long_description": "Supervisord cookbook\n====================\n\nThis cookbook installs\n[Supervisord](http://supervisord.org/configuration.html) and provides\na resource to supervise programs.\n\nUsage\n-----\n\nInclude `recipe[supervisord]` in your run list, and\n`supervisord_program` resource to configure individual programs. See\n`See recipes/example.rb` for sample usage\n\nResources\n---------\n\n## `supervisord_program` \n\n### Actions\n\n- `:supervise` (default): add program to supervisord config\n- `:start`, `:stop`, `:restart`: manage service\n\n### Attribute parameters\n\n- `:name` (name attribute)\n- `:command` (required)\n- all settings of a `[program:X]` section of supervisord config\n\nAuthors\n-------\n\n* Maciej Pasternacki\n* Dan Crosta\n", + "maintainer": "Maciej Pasternacki", + "maintainer_email": "maciej@pasternacki.net", + "license": "WTFPL", + "platforms": { + "ubuntu": ">= 0.0.0", + "debian": ">= 6.0" + }, + "dependencies": { + }, + "recommendations": { + }, + "suggestions": { + }, + "conflicting": { + }, + "providing": { + }, + "replacing": { + }, + "attributes": { + }, + "groupings": { + }, + "recipes": { + }, + "version": "1.0.1" +} \ No newline at end of file diff --git a/cookbooks/supervisord/metadata.rb b/cookbooks/supervisord/metadata.rb new file mode 100644 index 0000000..66437b6 --- /dev/null +++ b/cookbooks/supervisord/metadata.rb @@ -0,0 +1,10 @@ +name "supervisord" +maintainer "Maciej Pasternacki" +maintainer_email "maciej@pasternacki.net" +license "WTFPL" +description "Installs/Configures supervisord" +long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) +version "1.0.1" + +supports "ubuntu" +supports "debian", ">= 6.0" diff --git a/cookbooks/supervisord/providers/program.rb b/cookbooks/supervisord/providers/program.rb new file mode 100644 index 0000000..2954da9 --- /dev/null +++ b/cookbooks/supervisord/providers/program.rb @@ -0,0 +1,29 @@ +require 'chef/mixin/shell_out' + +include Chef::Mixin::ShellOut + +def initialize(*args) + super + @run_context.include_recipe "supervisord" +end + + +action :supervise do + template "/etc/supervisor/conf.d/#{new_resource.name}.conf" do + source "supervised-program.conf.erb" + cookbook "supervisord" + owner "root" + group "root" + mode "0600" + variables :program => new_resource + notifies :reload, resources("service[supervisor]") + end + new_resource.updated_by_last_action(true) +end + +[:start, :stop, :restart].each do |act| + action act do + shell_out! "supervisorctl #{act} #{new_resource.name}" + new_resource.updated_by_last_action(true) + end +end diff --git a/cookbooks/supervisord/recipes/default.rb b/cookbooks/supervisord/recipes/default.rb new file mode 100644 index 0000000..50a4800 --- /dev/null +++ b/cookbooks/supervisord/recipes/default.rb @@ -0,0 +1,6 @@ +package "supervisor" # FIXME: work with custom debian package + +service "supervisor" do + reload_command "supervisorctl reload" + action [ :enable, :start ] +end diff --git a/cookbooks/supervisord/recipes/example.rb b/cookbooks/supervisord/recipes/example.rb new file mode 100644 index 0000000..3b7f950 --- /dev/null +++ b/cookbooks/supervisord/recipes/example.rb @@ -0,0 +1,54 @@ +supervisord_program "minimal" do + command "cat" +end + +supervisord_program "maximal" do + command "cat" + process_name 'procname' + numprocs 2 + numprocs_start 3 + priority 777 + autostart true + autorestart false + startsecs 4 + startretries 5 + exitcodes '0,6,7' + stopsignal 'QUIT' + user 'nobody' + stdout_logfile '/out' + stdout_logfile_maxbytes '10M' + stdout_logfile_backups 99 + stdout_capture_maxbytes '11M' + stdout_events_enabled true + stdout_syslog true + stderr_logfile '/serr' + stderr_logfile_maxbytes '12M' + stderr_logfile_backups 88 + stderr_capture_maxbytes '13M' + stderr_events_enabled true + stderr_syslog true + environment 'FOO="bar"' + directory '/' + umask '022' + serverurl '/some.sock' +end + +supervisord_program 'env_a' do + command 'cat' + environment [ 'FOO=1', 'BAR=2', 'BAZ=3' ] +end + +supervisord_program 'env_hash' do + command 'cat' + environment 'FOO' => 1, 'BAR' => 2, 'BAZ' => 3 +end + +supervisord_program 'umask_int' do + command 'cat' + umask 2 +end + +supervisord_program 'exitcodes_a' do + command 'cat' + exitcodes [ 0, 6, 7 ] +end diff --git a/cookbooks/supervisord/resources/program.rb b/cookbooks/supervisord/resources/program.rb new file mode 100644 index 0000000..d5b1d3d --- /dev/null +++ b/cookbooks/supervisord/resources/program.rb @@ -0,0 +1,71 @@ +actions :supervise, :start, :stop, :restart +default_action :supervise + +attribute :name, :kind_of => String, :name_attribute => true +attribute :command, :kind_of => String, :required => true + +attribute :service # internal + +class << self + attr_reader :all_settings + def setting(name, *args, &block) + (@all_settings ||= {})[name] = block + attribute(name, *args) + end +end + +def each_setting + self.class.all_settings.sort.each do |setting, block| + value = self.send(setting) + next if value.nil? + value = block.call(value) if block + yield setting, value + end +end + +setting :process_name, kind_of: String, default: nil +setting :numprocs, kind_of: Integer, default: nil +setting :numprocs_start, kind_of: Integer, default: nil +setting :priority, kind_of: Integer, default: nil +setting :autostart, kind_of: [FalseClass, TrueClass], default: nil +setting :autorestart, equal_to: [true, false, :unexpected], default: nil +setting :startsecs, kind_of: Integer, default: nil +setting :startretries, kind_of: Integer, default: nil +setting :exitcodes, default: nil do |val| + if val.respond_to? :map + val.map(&:to_s).join(',') + else + val + end +end +setting :stopsignal, equal_to: ["TERM", "HUP", "INT", "QUIT", "KILL", "USR1", "USR2"], default: nil +setting :stopwaitsecs, kind_of: Integer, default: nil +setting :user, kind_of: String, default: nil +setting :stdout_logfile, kind_of: String, default: nil +setting :stdout_logfile_maxbytes, kind_of: String, default: nil +setting :stdout_logfile_backups, kind_of: Integer, default: nil +setting :stdout_capture_maxbytes, kind_of: String, default: nil +setting :stdout_events_enabled, kind_of: [FalseClass, TrueClass], default: nil +setting :stdout_syslog, kind_of: [FalseClass, TrueClass], default: nil +setting :stderr_logfile, kind_of: String, default: nil +setting :stderr_logfile_maxbytes, kind_of: String, default: nil +setting :stderr_logfile_backups, kind_of: Integer, default: nil +setting :stderr_capture_maxbytes, kind_of: String, default: nil +setting :stderr_events_enabled, kind_of: [FalseClass, TrueClass], default: nil +setting :stderr_syslog, kind_of: [FalseClass, TrueClass], default: nil +setting :environment, kind_of: [Hash, Array, String], default: nil do |val| + case val + when String then val + when Array then val.map(&:to_s).join(',') + when Hash then val.map { |k, v| "#{k}=\"#{v}\"" }.join(',') + end +end +setting :directory, kind_of: String, default: nil +setting :umask, kind_of: [String, Integer], default: nil do |val| + case val + when Integer then '%03o' % val + else val + end +end +setting :serverurl, kind_of: String, default: nil + diff --git a/cookbooks/supervisord/templates/default/supervised-program.conf.erb b/cookbooks/supervisord/templates/default/supervised-program.conf.erb new file mode 100644 index 0000000..c1cf0e0 --- /dev/null +++ b/cookbooks/supervisord/templates/default/supervised-program.conf.erb @@ -0,0 +1,5 @@ +[program:<%= @program.name %>] +command = <%= @program.command %> +<% @program.each_setting do |name, setting| -%> +<%= name %> = <%= setting %> +<% end -%> diff --git a/cookbooks/supervisord/templates/default/supervised-program.conf.erb~ b/cookbooks/supervisord/templates/default/supervised-program.conf.erb~ new file mode 100644 index 0000000..257b11f --- /dev/null +++ b/cookbooks/supervisord/templates/default/supervised-program.conf.erb~ @@ -0,0 +1,13 @@ +[program:<%= @program.name %>] +command = <%= @program.command %> +<% if not @program.autostart.nil? %>autostart = <%= @program.autostart %><% end %> +<% if not @program.startsecs.nil? %>startsecs = <% @program.startsecs %><% end %> +<% if not @program.user.nil? %>user = <%= @program.user %><% end %> +<% if not @program.directory.nil? %>directory = <%= @program.directory %><% end %> + +<% if not @program.stdout_logfile.nil? %>stdout_logfile = <%= @program.stdout_logfile %><% end %> +<% if not @program.stdout_logfile_maxbytes.nil? %>stdout_logfile_maxbytes = <%= @program.stdout_logfile_maxbytes %><% end %> +<% if not @program.stderr_logfile.nil? %>stderr_logfile = <%= @program.stderr_logfile %><% end %> +<% if not @program.stderr_logfile_maxbytes.nil? %>stderr_logfile_maxbytes = <%= @program.stderr_logfile_maxbytes %><% end %> + +<% if not @program.stopsignal.nil? %>stopsignal = <%= @program.stopsignal %><% end %>