From 82c17bd08880589438291eafbaf4518cad6c7deb Mon Sep 17 00:00:00 2001 From: Aaron Baer Date: Fri, 13 Mar 2015 09:04:13 -0700 Subject: [PATCH 01/14] Development 1.5.17 --- metadata.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.rb b/metadata.rb index 991f758..0432a1f 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache 2.0' description 'Installs runit and provides runit_service definition' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '1.5.18' +version '1.5.19' recipe 'runit', 'Installs and configures runit' From 51f705abe452e868b457605ff56a17a499819205 Mon Sep 17 00:00:00 2001 From: jtimberman Date: Fri, 13 Mar 2015 23:37:40 -0600 Subject: [PATCH 02/14] Fixes #88, use imeyer's packagecloud repo for RHEL - Change the "use_package_from_yum" attribute to "prefer_local_yum" to clarify intent. The default value will be set to the old attribute to attempt to preserve compatibility and default to false otherwise - Update the metadata and Cheffile to remove cookbooks that are not necessary; - Remove the runit tar.gz - Update the readme - Remove build-from-source portion of readme, and prefer packagecloud, as it's the same package anyway --- Cheffile | 2 -- Cheffile.lock | 18 +++---------- README.md | 10 +++---- attributes/default.rb | 2 +- files/default/runit-2.1.1.tar.gz | Bin 4538 -> 0 bytes metadata.rb | 4 +-- recipes/default.rb | 45 ++----------------------------- 7 files changed, 11 insertions(+), 70 deletions(-) delete mode 100644 files/default/runit-2.1.1.tar.gz diff --git a/Cheffile b/Cheffile index c893dbf..71af84f 100644 --- a/Cheffile +++ b/Cheffile @@ -2,8 +2,6 @@ site 'https://supermarket.chef.io/api/v1' -cookbook 'apt' -cookbook 'yum' cookbook 'runit', path: '.' cookbook 'runit_test', path: './test/cookbooks/runit_test' cookbook 'runit-other_test', path: './test/cookbooks/runit-other_test' diff --git a/Cheffile.lock b/Cheffile.lock index 6d23ba8..b3783b6 100644 --- a/Cheffile.lock +++ b/Cheffile.lock @@ -1,26 +1,16 @@ SITE remote: https://supermarket.chef.io/api/v1 specs: - apt (2.6.0) chef_handler (1.1.6) minitest-handler (1.3.2) chef_handler (>= 0.0.0) - yum (3.5.1) - -SITE - remote: https://supermarket.chef.io/api/v1 - specs: - build-essential (2.1.3) - yum-epel (0.5.3) - yum (~> 3.0) + packagecloud (0.0.17) PATH remote: . specs: - runit (1.5.11) - build-essential (>= 0.0.0) - yum (~> 3.0) - yum-epel (>= 0.0.0) + runit (1.5.18) + packagecloud (>= 0.0.0) PATH remote: ./test/cookbooks/runit-other_test @@ -33,10 +23,8 @@ PATH runit_test (1.0.0) DEPENDENCIES - apt (>= 0) minitest-handler (>= 0) runit (>= 0) runit-other_test (>= 0) runit_test (>= 0) - yum (>= 0) diff --git a/README.md b/README.md index 2fef30c..9f1fbb8 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ Requirements - Gentoo - RHEL +### Cookbooks +- packagecloud (for RHEL) Attributes ---------- @@ -32,23 +34,19 @@ See `attributes/default.rb` for defaults generated per platform. ### Optional Attributes for RHEL systems -- `node['runit']['use_package_from_yum']` - If `true`, attempts to install - runit without building an RPM first. This is for users who already have - the package in their own Yum repository. - +- `node['runit']['prefer_local_yum']` - If `true`, assumes that a `runit` package is available on an already configured local yum repository. By default, the recipe installs the `runit` package from a Package Cloud repository (see below). This is set to the value of `node['runit']['use_package_from_yum']` for backwards compatibility, but otherwise defaults to `false`. Recipes ------- ### default The default recipe installs runit and starts `runsvdir` to supervise the services in runit's service directory (e.g., `/etc/service`). -On RHEL family systems, it will build the runit RPM using [Ian Meyer's runit RPM SPEC](https://github.com/imeyer/runit-rpm) unless the attribute `node['runit']['use_package_from_yum']` is set to `true`. In which case it will try and install runit through the normal package installation mechanism. +On RHEL-family systems, it will install the runit RPM using [Ian Meyer's Package Cloud repository](https://packagecloud.io/imeyer/runit) for runit. This replaces the previous functionality where the RPM was build using his [runit RPM SPEC](https://github.com/imeyer/runit-rpm). However, if the attribute `node['runit']['prefer_local_yum']` is set to `true`, the packagecloud repository creation will be skipped and it is assumed that a `runit` package is available on an otherwise configured (outside this cookbook) local repository. On Debian family systems, the runit packages are maintained by the runit author, Gerrit Pape, and the recipe will use that for installation. On Gentoo, the runit ebuild package is installed. - Resource/Provider ----------------- This cookbook has a resource, `runit_service`, for managing services under runit. This service subclasses the Chef `service` resource. diff --git a/attributes/default.rb b/attributes/default.rb index 55e51d1..5a770a3 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -43,7 +43,7 @@ default['runit']['sv_dir'] = '/etc/sv' default['runit']['lsb_init_dir'] = '/etc/init.d' default['runit']['executable'] = '/sbin/runit' - default['runit']['use_package_from_yum'] = false + default['runit']['prefer_local_yum'] = node['runit']['use_package_from_yum'] || false default['runit']['start'] = '/etc/init.d/runit-start start' default['runit']['stop'] = '/etc/init.d/runit-start stop' default['runit']['reload'] = '/etc/init.d/runit-start reload' diff --git a/files/default/runit-2.1.1.tar.gz b/files/default/runit-2.1.1.tar.gz deleted file mode 100644 index 9c2364608e04af88ccf4ed70bf39f1eab9673098..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4538 zcmV;r5k>AFiwFQImXc8b1MNNAa@$CD+*}^EcQ#2SFUi|6C9N(bK!8`7vOJb;jm%lg zQbc=pwq!*HfhLIv1Yle!Yc)!$Qu%^ZW&b3VRDL2)dEC6^C3#Msb51uvffQxQv%YNx zrwkI^eJ(en;AXRaP5W0Cea03R;Q7!FC){J# zLdKEdS|LP3lI%F%sqGFRJhdZp$ip_#C<>;AVA(u!?4Aj#ssbQcWSfTLoPlGzCm|RE z!*;`Hg2vc0W5nBV38FD9Y0IQQw22*Xha2G~dUNUg%VQFIobqea%LQgzb{JhSwi9@< zpJCrU3nMoT zA4enKH=^N1W$B!Vk?4FZ)pMcr2%WJPfs@rC45P?zS1RGi2rTZZUNDd@qr$pg9GDq} zUyCW-&7~+62cJ6l727wk&oja@Zb{*hsf0WjqheK`@Fce0o{Np|;TYAYQ0o*EyVi~U zEM0XzUBrWtGK_u2^CPTTLc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zbho10wtYF{cvOwkvzJvS*(ut*gy$Vv&(ET-rs zbTG#zO=c_fMl~%bRwU(4mrJuLPYfu*5$1fQn^WZ`a?jI>OwyuR0eOIgIB6*%i8a_U z7NL#a*#v!pKcPUkK;D|-HBCJ3`c-e;YHN4fdTp+^o~E7k)~$BEHP>6$g-1(#f!cin z-CsW2+wXR|n0lBARde_feJ(5E*OMbGqC4J{D_$wA2k~k(%R2IIwaU8WN5NcT3ejc` ziQR$Z2P^BVjD{3N4}Ji zCIW28z-lx?jS!x^*e`>vauxX?GecrvpSy;`N?0jTq0)4PN{Og)vYsOw7r`oYT~`y; zbatL?Jw?rQ`qSD`0-R;+F%PF@iP#>(B}q;i*rO5d1F&Jv88+s7P?cGUqDY}ePy-aG zj~3lBED9=8u8PG-6b!LE61xRU-o;17P*e8jv;eJ7ME06zbXC1wn{RZ2M#B_OvGvw&dHlx_;2SEO0#2aAuPtoF@7J5jTswV^Adj zMf!x7Y!W&Wl>MpDG_Z`u+osr~IeZ?ljN>BHS!m^Xe|^rdoJV%}OyRoy|COM-zlDq& z_WxQ_tIq8IwR)|Q@BcprbZ~q9rY*Md;aD}<=5G%yJyRftVyTd6Bu4qj~Z$P!$ zZq(Yr-OpJ{noj*2<=~PlF;s#@0d1ksHoP^<8l658H4d&p4g=;sl2#eC_ zn<)O%_WyO`|1Dv(-&w{DHTj%ZoB))SF)ce%IFa z`U4X7wx66ZcGFK**e!nd!fyWg47<(GaM*2r(8CzJ)$fDmV9ox}h<(rBFtM9{9F@;s YIpmN-4msqI!~2K-1FHBjp#XRQ05i+jp#T5? diff --git a/metadata.rb b/metadata.rb index 991f758..d97e31e 100644 --- a/metadata.rb +++ b/metadata.rb @@ -12,6 +12,4 @@ supports os end -depends 'build-essential' -depends 'yum', '~> 3.0' -depends 'yum-epel' +depends 'packagecloud' diff --git a/recipes/default.rb b/recipes/default.rb index 5e49e19..cfc72cc 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -39,49 +39,8 @@ case node['platform_family'] when 'rhel' - if node['runit']['use_package_from_yum'] - package 'runit' - else - include_recipe 'build-essential' - # `rpmdevtools` is in EPEL repo in EL <= 5 - include_recipe 'yum-epel' if node['platform_version'].to_i == 5 - - packages = %w{rpm-build rpmdevtools tar gzip} - packages.each do |p| - package p - end - - if node['platform_version'].to_i >= 6 - package 'glibc-static' - else - package 'buildsys-macros' - end - - # This is the rpm spec and associated files to build a package of - # runit from source; the package will be installed. - cookbook_file "#{Chef::Config[:file_cache_path]}/runit-2.1.1.tar.gz" do - source 'runit-2.1.1.tar.gz' - not_if { runit_installed? } - notifies :run, 'bash[rhel_build_install]', :immediately - end - - # This bash resource does the rpm install because we need to - # dynamically detect where the rpm output directory is from the - # rpm config directive '%{_rpmdir}' - bash 'rhel_build_install' do - user 'root' - cwd Chef::Config[:file_cache_path] - code <<-EOH - tar xzf runit-2.1.1.tar.gz - cd runit-2.1.1 - ./build.sh - rpm_root_dir=`rpm --eval '%{_rpmdir}'` - rpm -ivh "${rpm_root_dir}/runit-2.1.1.rpm" - EOH - action :run - not_if { runit_installed? } - end - end + packagecloud_repo 'imeyer/runit' unless node['runit']['prefer_local_yum'] + package 'runit' when 'debian', 'gentoo' From 8b99a72d17e65629d9256a35de9d7d3951f4a57f Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Sat, 21 Mar 2015 13:30:32 -0700 Subject: [PATCH 03/14] fix converge_by usage in the first two cases the work done by converge_by is entirely done by idempotent sub resources. in the second case the converge_by sets the resources as being updated, setting updated_by_last_action is redundant. --- libraries/provider_runit_service.rb | 33 ++++++++++++----------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/libraries/provider_runit_service.rb b/libraries/provider_runit_service.rb index 3927495..2e4177a 100644 --- a/libraries/provider_runit_service.rb +++ b/libraries/provider_runit_service.rb @@ -82,24 +82,18 @@ def load_current_resource # def action_create - converge_by("configure service without enabling #{@new_resource}") do - configure_service # Do this every run, even if service is already enabled and running - Chef::Log.info("#{@new_resource} configured") - end + configure_service # Do this every run, even if service is already enabled and running + Chef::Log.info("#{@new_resource} configured") end def action_enable - converge_by("configure service #{@new_resource}") do - configure_service # Do this every run, even if service is already enabled and running - Chef::Log.info("#{@new_resource} configured") - end + configure_service # Do this every run, even if service is already enabled and running + Chef::Log.info("#{@new_resource} configured") if @current_resource.enabled Chef::Log.debug("#{@new_resource} already enabled - nothing to do") else - converge_by("enable service #{@new_resource}") do - enable_service - Chef::Log.info("#{@new_resource} enabled") - end + enable_service + Chef::Log.info("#{@new_resource} enabled") end load_new_resource_state @new_resource.enabled(true) @@ -129,7 +123,7 @@ def configure_service unless new_resource.env.empty? Chef::Log.debug("Setting up environment files for #{new_resource.service_name}") env_dir.run_action(:create) - env_files.each do |file| + env_files.each do |file| file.action.each { |action| file.run_action(action) } end else @@ -166,8 +160,8 @@ def configure_service def enable_service Chef::Log.debug("Creating symlink in service_dir for #{new_resource.service_name}") service_link.run_action(:create) - - unless inside_docker? + + unless inside_docker? Chef::Log.debug("waiting until named pipe #{service_dir_name}/supervise/ok exists.") until ::FileTest.pipe?("#{service_dir_name}/supervise/ok") sleep 1 @@ -182,7 +176,7 @@ def enable_service end end else - Chef::Log.debug("skipping */supervise/ok check inside docker") + Chef::Log.debug("skipping */supervise/ok check inside docker") end end @@ -258,7 +252,6 @@ def runit_send_signal(signal, friendly_name = nil) converge_by("send #{friendly_name} to #{new_resource}") do shell_out!("#{new_resource.sv_bin} #{sv_args}#{signal} #{service_dir_name}") Chef::Log.info("#{new_resource} sent #{friendly_name}") - new_resource.updated_by_last_action(true) end end @@ -369,7 +362,7 @@ def log_run_script @log_run_script = Chef::Resource::File.new( ::File.join(sv_dir_name, 'log', 'run'), run_context - ) + ) @log_run_script.content(default_logger_content) @log_run_script.owner(new_resource.owner) @log_run_script.group(new_resource.group) @@ -378,7 +371,7 @@ def log_run_script @log_run_script = Chef::Resource::Template.new( ::File.join(sv_dir_name, 'log', 'run'), run_context - ) + ) @log_run_script.owner(new_resource.owner) @log_run_script.group(new_resource.group) @log_run_script.mode(00755) @@ -489,7 +482,7 @@ def control_signal_files control_signal_file = Chef::Resource::Template.new( ::File.join(sv_dir_name, 'control', signal), run_context - ) + ) control_signal_file.owner(new_resource.owner) control_signal_file.group(new_resource.group) control_signal_file.mode(00755) From f89e79e196815e62ae6beb3382752db75cb88b02 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Sat, 21 Mar 2015 13:36:46 -0700 Subject: [PATCH 04/14] use do_action helper to set updated_by_last_action correctly slave the updated status to the subresources --- libraries/provider_runit_service.rb | 35 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/libraries/provider_runit_service.rb b/libraries/provider_runit_service.rb index 2e4177a..f805c53 100644 --- a/libraries/provider_runit_service.rb +++ b/libraries/provider_runit_service.rb @@ -105,26 +105,26 @@ def action_enable def configure_service if new_resource.sv_templates Chef::Log.debug("Creating sv_dir for #{new_resource.service_name}") - sv_dir.run_action(:create) + do_action(sv_dir, :create) Chef::Log.debug("Creating run_script for #{new_resource.service_name}") - run_script.run_action(:create) + do_action(run_script, :create) if new_resource.log Chef::Log.debug("Setting up svlog for #{new_resource.service_name}") - log_dir.run_action(:create) - log_main_dir.run_action(:create) - default_log_dir.run_action(:create) if new_resource.default_logger - log_run_script.run_action(:create) - log_config_file.run_action(:create) + do_action(log_dir, :create) + do_action(log_main_dir, :create) + do_action(default_log_dir, :create) if new_resource.default_logger + do_action(log_run_script, :create) + do_action(log_config_file, :create) else Chef::Log.debug("log not specified for #{new_resource.service_name}, continuing") end unless new_resource.env.empty? Chef::Log.debug("Setting up environment files for #{new_resource.service_name}") - env_dir.run_action(:create) + do_action(env_dir, :create) env_files.each do |file| - file.action.each { |action| file.run_action(action) } + file.action.each { |action| do_action(file, action) } end else Chef::Log.debug("Environment not specified for #{new_resource.service_name}, continuing") @@ -132,34 +132,34 @@ def configure_service if new_resource.check Chef::Log.debug("Creating check script for #{new_resource.service_name}") - check_script.run_action(:create) + do_action(check_script, :create) else Chef::Log.debug("Check script not specified for #{new_resource.service_name}, continuing") end if new_resource.finish Chef::Log.debug("Creating finish script for #{new_resource.service_name}") - finish_script.run_action(:create) + do_action(finish_script, :create) else Chef::Log.debug("Finish script not specified for #{new_resource.service_name}, continuing") end unless new_resource.control.empty? Chef::Log.debug("Creating control signal scripts for #{new_resource.service_name}") - control_dir.run_action(:create) - control_signal_files.each { |file| file.run_action(:create) } + do_action(control_dir, :create) + control_signal_files.each { |file| do_action(file, :create) } else Chef::Log.debug("Control signals not specified for #{new_resource.service_name}, continuing") end end Chef::Log.debug("Creating lsb_init compatible interface #{new_resource.service_name}") - lsb_init.run_action(:create) + do_action(lsb_init, :create) end def enable_service Chef::Log.debug("Creating symlink in service_dir for #{new_resource.service_name}") - service_link.run_action(:create) + do_action(service_link, :create) unless inside_docker? Chef::Log.debug("waiting until named pipe #{service_dir_name}/supervise/ok exists.") @@ -304,6 +304,11 @@ def default_logger_content # # Helper Resources # + def do_action(resource, action) + resource.run_action(action) + new_resource.updated_by_last_action(true) if resource.updated_by_last_action? + end + def sv_dir return @sv_dir unless @sv_dir.nil? @sv_dir = Chef::Resource::Directory.new(sv_dir_name, run_context) From 7eeb9576885c20677c3438aad040d21ced51e811 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Sat, 21 Mar 2015 15:00:28 -0700 Subject: [PATCH 05/14] style fixes to provider built on top of #94 removes useless @ivar usage and uses the accessors. uses ||= begin..end for lazy creation of resources. removes useless initialization of ivars to nil. --- libraries/provider_runit_service.rb | 399 +++++++++++++++------------- 1 file changed, 207 insertions(+), 192 deletions(-) diff --git a/libraries/provider_runit_service.rb b/libraries/provider_runit_service.rb index f805c53..3fefe0f 100644 --- a/libraries/provider_runit_service.rb +++ b/libraries/provider_runit_service.rb @@ -39,27 +39,12 @@ class Runit < Chef::Provider::Service def initialize(*args) super - @sv_dir = nil - @run_script = nil - @log_dir = nil - @log_main_dir = nil - @default_log_dir = nil - @log_run_script = nil - @log_config_file = nil - @env_dir = nil - @env_files = nil - @check_script = nil - @finish_script = nil - @control_dir = nil - @control_signal_files = nil - @lsb_init = nil - @service_link = nil - @new_resource.supports[:status] = true + new_resource.supports[:status] = true end def load_current_resource @current_resource = Chef::Resource::RunitService.new(new_resource.name) - @current_resource.service_name(new_resource.service_name) + current_resource.service_name(new_resource.service_name) Chef::Log.debug("Checking status of service #{new_resource.service_name}") @@ -71,10 +56,10 @@ def load_current_resource fail no_runit_message end - @current_resource.running(running?) - @current_resource.enabled(enabled?) - @current_resource.env(get_current_env) - @current_resource + current_resource.running(running?) + current_resource.enabled(enabled?) + current_resource.env(get_current_env) + current_resource end # @@ -83,23 +68,23 @@ def load_current_resource def action_create configure_service # Do this every run, even if service is already enabled and running - Chef::Log.info("#{@new_resource} configured") + Chef::Log.info("#{new_resource} configured") end def action_enable configure_service # Do this every run, even if service is already enabled and running - Chef::Log.info("#{@new_resource} configured") - if @current_resource.enabled - Chef::Log.debug("#{@new_resource} already enabled - nothing to do") + Chef::Log.info("#{new_resource} configured") + if current_resource.enabled + Chef::Log.debug("#{new_resource} already enabled - nothing to do") else enable_service - Chef::Log.info("#{@new_resource} enabled") + Chef::Log.info("#{new_resource} enabled") end load_new_resource_state - @new_resource.enabled(true) - restart_service if @new_resource.restart_on_update && run_script.updated_by_last_action? - restart_log_service if @new_resource.restart_on_update && log_run_script.updated_by_last_action? - restart_log_service if @new_resource.restart_on_update && log_config_file.updated_by_last_action? + new_resource.enabled(true) + restart_service if new_resource.restart_on_update && run_script.updated_by_last_action? + restart_log_service if new_resource.restart_on_update && log_run_script.updated_by_last_action? + restart_log_service if new_resource.restart_on_update && log_config_file.updated_by_last_action? end def configure_service @@ -218,7 +203,7 @@ def reload_log_service # only take action if the service is running [:down, :hup, :int, :term, :kill, :quit].each do |signal| define_method "action_#{signal}".to_sym do - if @current_resource.running + if current_resource.running runit_send_signal(signal) else Chef::Log.debug("#{new_resource} not running - nothing to do") @@ -229,7 +214,7 @@ def reload_log_service # only take action if service is *not* running [:up, :once, :cont].each do |signal| define_method "action_#{signal}".to_sym do - if @current_resource.running + if current_resource.running Chef::Log.debug("#{new_resource} already running - nothing to do") else runit_send_signal(signal) @@ -310,131 +295,149 @@ def do_action(resource, action) end def sv_dir - return @sv_dir unless @sv_dir.nil? - @sv_dir = Chef::Resource::Directory.new(sv_dir_name, run_context) - @sv_dir.recursive(true) - @sv_dir.owner(new_resource.owner) - @sv_dir.group(new_resource.group) - @sv_dir.mode(00755) - @sv_dir + @sv_dir ||= + begin + d = Chef::Resource::Directory.new(sv_dir_name, run_context) + d.recursive(true) + d.owner(new_resource.owner) + d.group(new_resource.group) + d.mode(00755) + d + end end def run_script - return @run_script unless @run_script.nil? - @run_script = Chef::Resource::Template.new(::File.join(sv_dir_name, 'run'), run_context) - @run_script.owner(new_resource.owner) - @run_script.group(new_resource.group) - @run_script.source("sv-#{new_resource.run_template_name}-run.erb") - @run_script.cookbook(template_cookbook) - @run_script.mode(00755) - @run_script.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) - @run_script + @run_script ||= + begin + t = Chef::Resource::Template.new(::File.join(sv_dir_name, 'run'), run_context) + t.owner(new_resource.owner) + t.group(new_resource.group) + t.source("sv-#{new_resource.run_template_name}-run.erb") + t.cookbook(template_cookbook) + t.mode(00755) + t.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) + t + end end def log_dir - return @log_dir unless @log_dir.nil? - @log_dir = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'log'), run_context) - @log_dir.recursive(true) - @log_dir.owner(new_resource.owner) - @log_dir.group(new_resource.group) - @log_dir.mode(00755) - @log_dir + @log_dir ||= + begin + d = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'log'), run_context) + d.recursive(true) + d.owner(new_resource.owner) + d.group(new_resource.group) + d.mode(00755) + d + end end def log_main_dir - return @log_main_dir unless @log_main_dir.nil? - @log_main_dir = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'log', 'main'), run_context) - @log_main_dir.recursive(true) - @log_main_dir.owner(new_resource.owner) - @log_main_dir.group(new_resource.group) - @log_main_dir.mode(00755) - @log_main_dir + @log_main_dir ||= + begin + d = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'log', 'main'), run_context) + d.recursive(true) + d.owner(new_resource.owner) + d.group(new_resource.group) + d.mode(00755) + d + end end def default_log_dir - return @default_log_dir unless @default_log_dir.nil? - @default_log_dir = Chef::Resource::Directory.new(::File.join("/var/log/#{new_resource.service_name}"), run_context) - @default_log_dir.recursive(true) - @default_log_dir.owner(new_resource.owner) - @default_log_dir.group(new_resource.group) - @default_log_dir.mode(00755) - @default_log_dir + @default_log_dir ||= + begin + d = Chef::Resource::Directory.new(::File.join("/var/log/#{new_resource.service_name}"), run_context) + d.recursive(true) + d.owner(new_resource.owner) + d.group(new_resource.group) + d.mode(00755) + d + end end def log_run_script - return @log_run_script unless @log_run_script.nil? - if new_resource.default_logger - @log_run_script = Chef::Resource::File.new( - ::File.join(sv_dir_name, 'log', 'run'), - run_context - ) - @log_run_script.content(default_logger_content) - @log_run_script.owner(new_resource.owner) - @log_run_script.group(new_resource.group) - @log_run_script.mode(00755) - else - @log_run_script = Chef::Resource::Template.new( - ::File.join(sv_dir_name, 'log', 'run'), - run_context - ) - @log_run_script.owner(new_resource.owner) - @log_run_script.group(new_resource.group) - @log_run_script.mode(00755) - @log_run_script.source("sv-#{new_resource.log_template_name}-log-run.erb") - @log_run_script.cookbook(template_cookbook) - @log_run_script.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) - end - @log_run_script + @log_run_script ||= + begin + if new_resource.default_logger + f = Chef::Resource::File.new( + ::File.join(sv_dir_name, 'log', 'run'), + run_context + ) + f.content(default_logger_content) + f.owner(new_resource.owner) + f.group(new_resource.group) + f.mode(00755) + f + else + t = Chef::Resource::Template.new( + ::File.join(sv_dir_name, 'log', 'run'), + run_context + ) + t.owner(new_resource.owner) + t.group(new_resource.group) + t.mode(00755) + t.source("sv-#{new_resource.log_template_name}-log-run.erb") + t.cookbook(template_cookbook) + t.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) + t + end + end end def log_config_file - return @log_config_file unless @log_config_file.nil? - @log_config_file = Chef::Resource::Template.new(::File.join(sv_dir_name, 'log', 'config'), run_context) - @log_config_file.owner(new_resource.owner) - @log_config_file.group(new_resource.group) - @log_config_file.mode(00644) - @log_config_file.cookbook('runit') - @log_config_file.source('log-config.erb') - @log_config_file.variables( - :size => new_resource.log_size, - :num => new_resource.log_num, - :min => new_resource.log_min, - :timeout => new_resource.log_timeout, - :processor => new_resource.log_processor, - :socket => new_resource.log_socket, - :prefix => new_resource.log_prefix, - :append => new_resource.log_config_append - ) - @log_config_file + @log_config_file ||= + begin + t = Chef::Resource::Template.new(::File.join(sv_dir_name, 'log', 'config'), run_context) + t.owner(new_resource.owner) + t.group(new_resource.group) + t.mode(00644) + t.cookbook('runit') + t.source('log-config.erb') + t.variables( + :size => new_resource.log_size, + :num => new_resource.log_num, + :min => new_resource.log_min, + :timeout => new_resource.log_timeout, + :processor => new_resource.log_processor, + :socket => new_resource.log_socket, + :prefix => new_resource.log_prefix, + :append => new_resource.log_config_append + ) + t + end end def env_dir - return @env_dir unless @env_dir.nil? - @env_dir = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'env'), run_context) - @env_dir.owner(new_resource.owner) - @env_dir.group(new_resource.group) - @env_dir.mode(00755) - @env_dir + @env_dir ||= + begin + d = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'env'), run_context) + d.owner(new_resource.owner) + d.group(new_resource.group) + d.mode(00755) + d + end end def env_files - return @env_files unless @env_files.nil? - create_files = new_resource.env.map do |var, value| - env_file = Chef::Resource::File.new(::File.join(sv_dir_name, 'env', var), run_context) - env_file.owner(new_resource.owner) - env_file.group(new_resource.group) - env_file.content(value) - env_file.action(:create) - env_file - end - extra_env = @current_resource.env.reject { |k,_| new_resource.env.key?(k) } - delete_files = extra_env.map do |k,_| - env_file = Chef::Resource::File.new(::File.join(sv_dir_name, 'env', k), run_context) - env_file.action(:delete) - env_file - end - @env_files = create_files + delete_files - @env_files + @env_files ||= + begin + create_files = new_resource.env.map do |var, value| + f = Chef::Resource::File.new(::File.join(sv_dir_name, 'env', var), run_context) + f.owner(new_resource.owner) + f.group(new_resource.group) + f.content(value) + f.action(:create) + f + end + extra_env = current_resource.env.reject { |k,_| new_resource.env.key?(k) } + delete_files = extra_env.map do |k,_| + f = Chef::Resource::File.new(::File.join(sv_dir_name, 'env', k), run_context) + f.action(:delete) + f + end + create_files + delete_files + end end def get_current_env @@ -449,80 +452,92 @@ def get_current_env end def check_script - return @check_script unless @check_script.nil? - @check_script = Chef::Resource::Template.new(::File.join(sv_dir_name, 'check'), run_context) - @check_script.owner(new_resource.owner) - @check_script.group(new_resource.group) - @check_script.source("sv-#{new_resource.check_script_template_name}-check.erb") - @check_script.cookbook(template_cookbook) - @check_script.mode(00755) - @check_script.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) - @check_script + @check_script ||= + begin + t = Chef::Resource::Template.new(::File.join(sv_dir_name, 'check'), run_context) + t.owner(new_resource.owner) + t.group(new_resource.group) + t.source("sv-#{new_resource.check_script_template_name}-check.erb") + t.cookbook(template_cookbook) + t.mode(00755) + t.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) + t + end end def finish_script - return @finish_script unless @finish_script.nil? - @finish_script = Chef::Resource::Template.new(::File.join(sv_dir_name, 'finish'), run_context) - @finish_script.owner(new_resource.owner) - @finish_script.group(new_resource.group) - @finish_script.mode(00755) - @finish_script.source("sv-#{new_resource.finish_script_template_name}-finish.erb") - @finish_script.cookbook(template_cookbook) - @finish_script.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) - @finish_script + @finish_script ||= + begin + t = Chef::Resource::Template.new(::File.join(sv_dir_name, 'finish'), run_context) + t.owner(new_resource.owner) + t.group(new_resource.group) + t.mode(00755) + t.source("sv-#{new_resource.finish_script_template_name}-finish.erb") + t.cookbook(template_cookbook) + t.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) + t + end end def control_dir - return @control_dir unless @control_dir.nil? - @control_dir = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'control'), run_context) - @control_dir.owner(new_resource.owner) - @control_dir.group(new_resource.group) - @control_dir.mode(00755) - @control_dir + @control_dir ||= + begin + d = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'control'), run_context) + d.owner(new_resource.owner) + d.group(new_resource.group) + d.mode(00755) + d + end end def control_signal_files - return @control_signal_files unless @control_signal_files.nil? - @control_signal_files = new_resource.control.map do |signal| - control_signal_file = Chef::Resource::Template.new( - ::File.join(sv_dir_name, 'control', signal), - run_context - ) - control_signal_file.owner(new_resource.owner) - control_signal_file.group(new_resource.group) - control_signal_file.mode(00755) - control_signal_file.source("sv-#{new_resource.control_template_names[signal]}-#{signal}.erb") - control_signal_file.cookbook(template_cookbook) - control_signal_file.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) - control_signal_file - end - @control_signal_files + @control_signal_files ||= + begin + new_resource.control.map do |signal| + t = Chef::Resource::Template.new( + ::File.join(sv_dir_name, 'control', signal), + run_context + ) + t.owner(new_resource.owner) + t.group(new_resource.group) + t.mode(00755) + t.source("sv-#{new_resource.control_template_names[signal]}-#{signal}.erb") + t.cookbook(template_cookbook) + t.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) + t + end + end end def lsb_init - return @lsb_init unless @lsb_init.nil? - initfile = ::File.join(new_resource.lsb_init_dir, new_resource.service_name) - if node['platform'] == 'debian' - ::File.unlink(initfile) if ::File.symlink?(initfile) - @lsb_init = Chef::Resource::Template.new(initfile, run_context) - @lsb_init.owner('root') - @lsb_init.group('root') - @lsb_init.mode(00755) - @lsb_init.cookbook('runit') - @lsb_init.source('init.d.erb') - @lsb_init.variables(:name => new_resource.service_name) - else - @lsb_init = Chef::Resource::Link.new(initfile, run_context) - @lsb_init.to(new_resource.sv_bin) - end - @lsb_init + @lsb_init ||= + begin + initfile = ::File.join(new_resource.lsb_init_dir, new_resource.service_name) + if node['platform'] == 'debian' + ::File.unlink(initfile) if ::File.symlink?(initfile) + t = Chef::Resource::Template.new(initfile, run_context) + t.owner('root') + t.group('root') + t.mode(00755) + t.cookbook('runit') + t.source('init.d.erb') + t.variables(:name => new_resource.service_name) + t + else + l = Chef::Resource::Link.new(initfile, run_context) + l.to(new_resource.sv_bin) + l + end + end end def service_link - return @service_link unless @service_link.nil? - @service_link = Chef::Resource::Link.new(::File.join(service_dir_name), run_context) - @service_link.to(sv_dir_name) - @service_link + @service_link ||= + begin + l = Chef::Resource::Link.new(::File.join(service_dir_name), run_context) + l.to(sv_dir_name) + l + end end def inside_docker? From 6c4d11edd7a48241ccfad81e90fe0a4b27b74593 Mon Sep 17 00:00:00 2001 From: Aaron Baer Date: Mon, 23 Mar 2015 23:14:46 -0700 Subject: [PATCH 06/14] Runit 1.5.20 --- CHANGELOG.md | 7 +++++++ metadata.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92c9de1..41b7417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ runit Cookbook CHANGELOG ======================== This file is used to list changes made in each version of the runit cookbook. +v1.5.20 (2015-03-23) +-------------------- +* use imeyer’s packagecloud repo for RHEL +* fix converge_by usage +* do_action helper to set updated_by_last_action +* style fixes to provider + v1.5.18 (2015-03-13) -------------------- * Add helper methods to detect installation presence diff --git a/metadata.rb b/metadata.rb index 0280842..4330358 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache 2.0' description 'Installs runit and provides runit_service definition' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '1.5.19' +version '1.5.20' recipe 'runit', 'Installs and configures runit' From 1d040332954b01af044577eda3fecd79984c78fd Mon Sep 17 00:00:00 2001 From: Aaron Baer Date: Fri, 13 Mar 2015 09:04:13 -0700 Subject: [PATCH 07/14] Development 1.5.17 --- metadata.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/metadata.rb b/metadata.rb index 991f758..0432a1f 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache 2.0' description 'Installs runit and provides runit_service definition' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '1.5.18' +version '1.5.19' recipe 'runit', 'Installs and configures runit' From 90b87466c072bca6e985cc2f8960e217b8892fdc Mon Sep 17 00:00:00 2001 From: jtimberman Date: Fri, 13 Mar 2015 23:37:40 -0600 Subject: [PATCH 08/14] Fixes #88, use imeyer's packagecloud repo for RHEL - Change the "use_package_from_yum" attribute to "prefer_local_yum" to clarify intent. The default value will be set to the old attribute to attempt to preserve compatibility and default to false otherwise - Update the metadata and Cheffile to remove cookbooks that are not necessary; - Remove the runit tar.gz - Update the readme - Remove build-from-source portion of readme, and prefer packagecloud, as it's the same package anyway --- Cheffile | 2 -- Cheffile.lock | 18 +++---------- README.md | 10 +++---- attributes/default.rb | 2 +- files/default/runit-2.1.1.tar.gz | Bin 4538 -> 0 bytes metadata.rb | 4 +-- recipes/default.rb | 45 ++----------------------------- 7 files changed, 11 insertions(+), 70 deletions(-) delete mode 100644 files/default/runit-2.1.1.tar.gz diff --git a/Cheffile b/Cheffile index c893dbf..71af84f 100644 --- a/Cheffile +++ b/Cheffile @@ -2,8 +2,6 @@ site 'https://supermarket.chef.io/api/v1' -cookbook 'apt' -cookbook 'yum' cookbook 'runit', path: '.' cookbook 'runit_test', path: './test/cookbooks/runit_test' cookbook 'runit-other_test', path: './test/cookbooks/runit-other_test' diff --git a/Cheffile.lock b/Cheffile.lock index 6d23ba8..b3783b6 100644 --- a/Cheffile.lock +++ b/Cheffile.lock @@ -1,26 +1,16 @@ SITE remote: https://supermarket.chef.io/api/v1 specs: - apt (2.6.0) chef_handler (1.1.6) minitest-handler (1.3.2) chef_handler (>= 0.0.0) - yum (3.5.1) - -SITE - remote: https://supermarket.chef.io/api/v1 - specs: - build-essential (2.1.3) - yum-epel (0.5.3) - yum (~> 3.0) + packagecloud (0.0.17) PATH remote: . specs: - runit (1.5.11) - build-essential (>= 0.0.0) - yum (~> 3.0) - yum-epel (>= 0.0.0) + runit (1.5.18) + packagecloud (>= 0.0.0) PATH remote: ./test/cookbooks/runit-other_test @@ -33,10 +23,8 @@ PATH runit_test (1.0.0) DEPENDENCIES - apt (>= 0) minitest-handler (>= 0) runit (>= 0) runit-other_test (>= 0) runit_test (>= 0) - yum (>= 0) diff --git a/README.md b/README.md index 2fef30c..9f1fbb8 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,8 @@ Requirements - Gentoo - RHEL +### Cookbooks +- packagecloud (for RHEL) Attributes ---------- @@ -32,23 +34,19 @@ See `attributes/default.rb` for defaults generated per platform. ### Optional Attributes for RHEL systems -- `node['runit']['use_package_from_yum']` - If `true`, attempts to install - runit without building an RPM first. This is for users who already have - the package in their own Yum repository. - +- `node['runit']['prefer_local_yum']` - If `true`, assumes that a `runit` package is available on an already configured local yum repository. By default, the recipe installs the `runit` package from a Package Cloud repository (see below). This is set to the value of `node['runit']['use_package_from_yum']` for backwards compatibility, but otherwise defaults to `false`. Recipes ------- ### default The default recipe installs runit and starts `runsvdir` to supervise the services in runit's service directory (e.g., `/etc/service`). -On RHEL family systems, it will build the runit RPM using [Ian Meyer's runit RPM SPEC](https://github.com/imeyer/runit-rpm) unless the attribute `node['runit']['use_package_from_yum']` is set to `true`. In which case it will try and install runit through the normal package installation mechanism. +On RHEL-family systems, it will install the runit RPM using [Ian Meyer's Package Cloud repository](https://packagecloud.io/imeyer/runit) for runit. This replaces the previous functionality where the RPM was build using his [runit RPM SPEC](https://github.com/imeyer/runit-rpm). However, if the attribute `node['runit']['prefer_local_yum']` is set to `true`, the packagecloud repository creation will be skipped and it is assumed that a `runit` package is available on an otherwise configured (outside this cookbook) local repository. On Debian family systems, the runit packages are maintained by the runit author, Gerrit Pape, and the recipe will use that for installation. On Gentoo, the runit ebuild package is installed. - Resource/Provider ----------------- This cookbook has a resource, `runit_service`, for managing services under runit. This service subclasses the Chef `service` resource. diff --git a/attributes/default.rb b/attributes/default.rb index 55e51d1..5a770a3 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -43,7 +43,7 @@ default['runit']['sv_dir'] = '/etc/sv' default['runit']['lsb_init_dir'] = '/etc/init.d' default['runit']['executable'] = '/sbin/runit' - default['runit']['use_package_from_yum'] = false + default['runit']['prefer_local_yum'] = node['runit']['use_package_from_yum'] || false default['runit']['start'] = '/etc/init.d/runit-start start' default['runit']['stop'] = '/etc/init.d/runit-start stop' default['runit']['reload'] = '/etc/init.d/runit-start reload' diff --git a/files/default/runit-2.1.1.tar.gz b/files/default/runit-2.1.1.tar.gz deleted file mode 100644 index 9c2364608e04af88ccf4ed70bf39f1eab9673098..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4538 zcmV;r5k>AFiwFQImXc8b1MNNAa@$CD+*}^EcQ#2SFUi|6C9N(bK!8`7vOJb;jm%lg zQbc=pwq!*HfhLIv1Yle!Yc)!$Qu%^ZW&b3VRDL2)dEC6^C3#Msb51uvffQxQv%YNx zrwkI^eJ(en;AXRaP5W0Cea03R;Q7!FC){J# zLdKEdS|LP3lI%F%sqGFRJhdZp$ip_#C<>;AVA(u!?4Aj#ssbQcWSfTLoPlGzCm|RE z!*;`Hg2vc0W5nBV38FD9Y0IQQw22*Xha2G~dUNUg%VQFIobqea%LQgzb{JhSwi9@< zpJCrU3nMoT zA4enKH=^N1W$B!Vk?4FZ)pMcr2%WJPfs@rC45P?zS1RGi2rTZZUNDd@qr$pg9GDq} zUyCW-&7~+62cJ6l727wk&oja@Zb{*hsf0WjqheK`@Fce0o{Np|;TYAYQ0o*EyVi~U zEM0XzUBrWtGK_u2^CPTTLc#WWq37@j%`q7e_ckG;sipHkTF(XB54(~wmdt{t&7?>tQ`{GWsJyV>(fb39_mVd#nTIhVLv>2s!;}Q18*`#O-UOel33pQ0X z#PNpqBZgX{X$WJ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7NL#a*#v!pKcPUkK;D|-HBCJ3`c-e;YHN4fdTp+^o~E7k)~$BEHP>6$g-1(#f!cin z-CsW2+wXR|n0lBARde_feJ(5E*OMbGqC4J{D_$wA2k~k(%R2IIwaU8WN5NcT3ejc` ziQR$Z2P^BVjD{3N4}Ji zCIW28z-lx?jS!x^*e`>vauxX?GecrvpSy;`N?0jTq0)4PN{Og)vYsOw7r`oYT~`y; zbatL?Jw?rQ`qSD`0-R;+F%PF@iP#>(B}q;i*rO5d1F&Jv88+s7P?cGUqDY}ePy-aG zj~3lBED9=8u8PG-6b!LE61xRU-o;17P*e8jv;eJ7ME06zbXC1wn{RZ2M#B_OvGvw&dHlx_;2SEO0#2aAuPtoF@7J5jTswV^Adj zMf!x7Y!W&Wl>MpDG_Z`u+osr~IeZ?ljN>BHS!m^Xe|^rdoJV%}OyRoy|COM-zlDq& z_WxQ_tIq8IwR)|Q@BcprbZ~q9rY*Md;aD}<=5G%yJyRftVyTd6Bu4qj~Z$P!$ zZq(Yr-OpJ{noj*2<=~PlF;s#@0d1ksHoP^<8l658H4d&p4g=;sl2#eC_ zn<)O%_WyO`|1Dv(-&w{DHTj%ZoB))SF)ce%IFa z`U4X7wx66ZcGFK**e!nd!fyWg47<(GaM*2r(8CzJ)$fDmV9ox}h<(rBFtM9{9F@;s YIpmN-4msqI!~2K-1FHBjp#XRQ05i+jp#T5? diff --git a/metadata.rb b/metadata.rb index 0432a1f..0280842 100644 --- a/metadata.rb +++ b/metadata.rb @@ -12,6 +12,4 @@ supports os end -depends 'build-essential' -depends 'yum', '~> 3.0' -depends 'yum-epel' +depends 'packagecloud' diff --git a/recipes/default.rb b/recipes/default.rb index 5e49e19..cfc72cc 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -39,49 +39,8 @@ case node['platform_family'] when 'rhel' - if node['runit']['use_package_from_yum'] - package 'runit' - else - include_recipe 'build-essential' - # `rpmdevtools` is in EPEL repo in EL <= 5 - include_recipe 'yum-epel' if node['platform_version'].to_i == 5 - - packages = %w{rpm-build rpmdevtools tar gzip} - packages.each do |p| - package p - end - - if node['platform_version'].to_i >= 6 - package 'glibc-static' - else - package 'buildsys-macros' - end - - # This is the rpm spec and associated files to build a package of - # runit from source; the package will be installed. - cookbook_file "#{Chef::Config[:file_cache_path]}/runit-2.1.1.tar.gz" do - source 'runit-2.1.1.tar.gz' - not_if { runit_installed? } - notifies :run, 'bash[rhel_build_install]', :immediately - end - - # This bash resource does the rpm install because we need to - # dynamically detect where the rpm output directory is from the - # rpm config directive '%{_rpmdir}' - bash 'rhel_build_install' do - user 'root' - cwd Chef::Config[:file_cache_path] - code <<-EOH - tar xzf runit-2.1.1.tar.gz - cd runit-2.1.1 - ./build.sh - rpm_root_dir=`rpm --eval '%{_rpmdir}'` - rpm -ivh "${rpm_root_dir}/runit-2.1.1.rpm" - EOH - action :run - not_if { runit_installed? } - end - end + packagecloud_repo 'imeyer/runit' unless node['runit']['prefer_local_yum'] + package 'runit' when 'debian', 'gentoo' From 2169e0a1beb7fb144e647c88cf5200693d613ee3 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Sat, 21 Mar 2015 13:30:32 -0700 Subject: [PATCH 09/14] fix converge_by usage in the first two cases the work done by converge_by is entirely done by idempotent sub resources. in the second case the converge_by sets the resources as being updated, setting updated_by_last_action is redundant. --- libraries/provider_runit_service.rb | 33 ++++++++++++----------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/libraries/provider_runit_service.rb b/libraries/provider_runit_service.rb index 3927495..2e4177a 100644 --- a/libraries/provider_runit_service.rb +++ b/libraries/provider_runit_service.rb @@ -82,24 +82,18 @@ def load_current_resource # def action_create - converge_by("configure service without enabling #{@new_resource}") do - configure_service # Do this every run, even if service is already enabled and running - Chef::Log.info("#{@new_resource} configured") - end + configure_service # Do this every run, even if service is already enabled and running + Chef::Log.info("#{@new_resource} configured") end def action_enable - converge_by("configure service #{@new_resource}") do - configure_service # Do this every run, even if service is already enabled and running - Chef::Log.info("#{@new_resource} configured") - end + configure_service # Do this every run, even if service is already enabled and running + Chef::Log.info("#{@new_resource} configured") if @current_resource.enabled Chef::Log.debug("#{@new_resource} already enabled - nothing to do") else - converge_by("enable service #{@new_resource}") do - enable_service - Chef::Log.info("#{@new_resource} enabled") - end + enable_service + Chef::Log.info("#{@new_resource} enabled") end load_new_resource_state @new_resource.enabled(true) @@ -129,7 +123,7 @@ def configure_service unless new_resource.env.empty? Chef::Log.debug("Setting up environment files for #{new_resource.service_name}") env_dir.run_action(:create) - env_files.each do |file| + env_files.each do |file| file.action.each { |action| file.run_action(action) } end else @@ -166,8 +160,8 @@ def configure_service def enable_service Chef::Log.debug("Creating symlink in service_dir for #{new_resource.service_name}") service_link.run_action(:create) - - unless inside_docker? + + unless inside_docker? Chef::Log.debug("waiting until named pipe #{service_dir_name}/supervise/ok exists.") until ::FileTest.pipe?("#{service_dir_name}/supervise/ok") sleep 1 @@ -182,7 +176,7 @@ def enable_service end end else - Chef::Log.debug("skipping */supervise/ok check inside docker") + Chef::Log.debug("skipping */supervise/ok check inside docker") end end @@ -258,7 +252,6 @@ def runit_send_signal(signal, friendly_name = nil) converge_by("send #{friendly_name} to #{new_resource}") do shell_out!("#{new_resource.sv_bin} #{sv_args}#{signal} #{service_dir_name}") Chef::Log.info("#{new_resource} sent #{friendly_name}") - new_resource.updated_by_last_action(true) end end @@ -369,7 +362,7 @@ def log_run_script @log_run_script = Chef::Resource::File.new( ::File.join(sv_dir_name, 'log', 'run'), run_context - ) + ) @log_run_script.content(default_logger_content) @log_run_script.owner(new_resource.owner) @log_run_script.group(new_resource.group) @@ -378,7 +371,7 @@ def log_run_script @log_run_script = Chef::Resource::Template.new( ::File.join(sv_dir_name, 'log', 'run'), run_context - ) + ) @log_run_script.owner(new_resource.owner) @log_run_script.group(new_resource.group) @log_run_script.mode(00755) @@ -489,7 +482,7 @@ def control_signal_files control_signal_file = Chef::Resource::Template.new( ::File.join(sv_dir_name, 'control', signal), run_context - ) + ) control_signal_file.owner(new_resource.owner) control_signal_file.group(new_resource.group) control_signal_file.mode(00755) From 020e61d54a932ece9740de1a5f8fc188088d7f10 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Sat, 21 Mar 2015 13:36:46 -0700 Subject: [PATCH 10/14] use do_action helper to set updated_by_last_action correctly slave the updated status to the subresources --- libraries/provider_runit_service.rb | 35 ++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/libraries/provider_runit_service.rb b/libraries/provider_runit_service.rb index 2e4177a..f805c53 100644 --- a/libraries/provider_runit_service.rb +++ b/libraries/provider_runit_service.rb @@ -105,26 +105,26 @@ def action_enable def configure_service if new_resource.sv_templates Chef::Log.debug("Creating sv_dir for #{new_resource.service_name}") - sv_dir.run_action(:create) + do_action(sv_dir, :create) Chef::Log.debug("Creating run_script for #{new_resource.service_name}") - run_script.run_action(:create) + do_action(run_script, :create) if new_resource.log Chef::Log.debug("Setting up svlog for #{new_resource.service_name}") - log_dir.run_action(:create) - log_main_dir.run_action(:create) - default_log_dir.run_action(:create) if new_resource.default_logger - log_run_script.run_action(:create) - log_config_file.run_action(:create) + do_action(log_dir, :create) + do_action(log_main_dir, :create) + do_action(default_log_dir, :create) if new_resource.default_logger + do_action(log_run_script, :create) + do_action(log_config_file, :create) else Chef::Log.debug("log not specified for #{new_resource.service_name}, continuing") end unless new_resource.env.empty? Chef::Log.debug("Setting up environment files for #{new_resource.service_name}") - env_dir.run_action(:create) + do_action(env_dir, :create) env_files.each do |file| - file.action.each { |action| file.run_action(action) } + file.action.each { |action| do_action(file, action) } end else Chef::Log.debug("Environment not specified for #{new_resource.service_name}, continuing") @@ -132,34 +132,34 @@ def configure_service if new_resource.check Chef::Log.debug("Creating check script for #{new_resource.service_name}") - check_script.run_action(:create) + do_action(check_script, :create) else Chef::Log.debug("Check script not specified for #{new_resource.service_name}, continuing") end if new_resource.finish Chef::Log.debug("Creating finish script for #{new_resource.service_name}") - finish_script.run_action(:create) + do_action(finish_script, :create) else Chef::Log.debug("Finish script not specified for #{new_resource.service_name}, continuing") end unless new_resource.control.empty? Chef::Log.debug("Creating control signal scripts for #{new_resource.service_name}") - control_dir.run_action(:create) - control_signal_files.each { |file| file.run_action(:create) } + do_action(control_dir, :create) + control_signal_files.each { |file| do_action(file, :create) } else Chef::Log.debug("Control signals not specified for #{new_resource.service_name}, continuing") end end Chef::Log.debug("Creating lsb_init compatible interface #{new_resource.service_name}") - lsb_init.run_action(:create) + do_action(lsb_init, :create) end def enable_service Chef::Log.debug("Creating symlink in service_dir for #{new_resource.service_name}") - service_link.run_action(:create) + do_action(service_link, :create) unless inside_docker? Chef::Log.debug("waiting until named pipe #{service_dir_name}/supervise/ok exists.") @@ -304,6 +304,11 @@ def default_logger_content # # Helper Resources # + def do_action(resource, action) + resource.run_action(action) + new_resource.updated_by_last_action(true) if resource.updated_by_last_action? + end + def sv_dir return @sv_dir unless @sv_dir.nil? @sv_dir = Chef::Resource::Directory.new(sv_dir_name, run_context) From dfbd25290711f3a8ef7019f8056346fe0443e057 Mon Sep 17 00:00:00 2001 From: Lamont Granquist Date: Sat, 21 Mar 2015 15:00:28 -0700 Subject: [PATCH 11/14] style fixes to provider built on top of #94 removes useless @ivar usage and uses the accessors. uses ||= begin..end for lazy creation of resources. removes useless initialization of ivars to nil. --- libraries/provider_runit_service.rb | 399 +++++++++++++++------------- 1 file changed, 207 insertions(+), 192 deletions(-) diff --git a/libraries/provider_runit_service.rb b/libraries/provider_runit_service.rb index f805c53..3fefe0f 100644 --- a/libraries/provider_runit_service.rb +++ b/libraries/provider_runit_service.rb @@ -39,27 +39,12 @@ class Runit < Chef::Provider::Service def initialize(*args) super - @sv_dir = nil - @run_script = nil - @log_dir = nil - @log_main_dir = nil - @default_log_dir = nil - @log_run_script = nil - @log_config_file = nil - @env_dir = nil - @env_files = nil - @check_script = nil - @finish_script = nil - @control_dir = nil - @control_signal_files = nil - @lsb_init = nil - @service_link = nil - @new_resource.supports[:status] = true + new_resource.supports[:status] = true end def load_current_resource @current_resource = Chef::Resource::RunitService.new(new_resource.name) - @current_resource.service_name(new_resource.service_name) + current_resource.service_name(new_resource.service_name) Chef::Log.debug("Checking status of service #{new_resource.service_name}") @@ -71,10 +56,10 @@ def load_current_resource fail no_runit_message end - @current_resource.running(running?) - @current_resource.enabled(enabled?) - @current_resource.env(get_current_env) - @current_resource + current_resource.running(running?) + current_resource.enabled(enabled?) + current_resource.env(get_current_env) + current_resource end # @@ -83,23 +68,23 @@ def load_current_resource def action_create configure_service # Do this every run, even if service is already enabled and running - Chef::Log.info("#{@new_resource} configured") + Chef::Log.info("#{new_resource} configured") end def action_enable configure_service # Do this every run, even if service is already enabled and running - Chef::Log.info("#{@new_resource} configured") - if @current_resource.enabled - Chef::Log.debug("#{@new_resource} already enabled - nothing to do") + Chef::Log.info("#{new_resource} configured") + if current_resource.enabled + Chef::Log.debug("#{new_resource} already enabled - nothing to do") else enable_service - Chef::Log.info("#{@new_resource} enabled") + Chef::Log.info("#{new_resource} enabled") end load_new_resource_state - @new_resource.enabled(true) - restart_service if @new_resource.restart_on_update && run_script.updated_by_last_action? - restart_log_service if @new_resource.restart_on_update && log_run_script.updated_by_last_action? - restart_log_service if @new_resource.restart_on_update && log_config_file.updated_by_last_action? + new_resource.enabled(true) + restart_service if new_resource.restart_on_update && run_script.updated_by_last_action? + restart_log_service if new_resource.restart_on_update && log_run_script.updated_by_last_action? + restart_log_service if new_resource.restart_on_update && log_config_file.updated_by_last_action? end def configure_service @@ -218,7 +203,7 @@ def reload_log_service # only take action if the service is running [:down, :hup, :int, :term, :kill, :quit].each do |signal| define_method "action_#{signal}".to_sym do - if @current_resource.running + if current_resource.running runit_send_signal(signal) else Chef::Log.debug("#{new_resource} not running - nothing to do") @@ -229,7 +214,7 @@ def reload_log_service # only take action if service is *not* running [:up, :once, :cont].each do |signal| define_method "action_#{signal}".to_sym do - if @current_resource.running + if current_resource.running Chef::Log.debug("#{new_resource} already running - nothing to do") else runit_send_signal(signal) @@ -310,131 +295,149 @@ def do_action(resource, action) end def sv_dir - return @sv_dir unless @sv_dir.nil? - @sv_dir = Chef::Resource::Directory.new(sv_dir_name, run_context) - @sv_dir.recursive(true) - @sv_dir.owner(new_resource.owner) - @sv_dir.group(new_resource.group) - @sv_dir.mode(00755) - @sv_dir + @sv_dir ||= + begin + d = Chef::Resource::Directory.new(sv_dir_name, run_context) + d.recursive(true) + d.owner(new_resource.owner) + d.group(new_resource.group) + d.mode(00755) + d + end end def run_script - return @run_script unless @run_script.nil? - @run_script = Chef::Resource::Template.new(::File.join(sv_dir_name, 'run'), run_context) - @run_script.owner(new_resource.owner) - @run_script.group(new_resource.group) - @run_script.source("sv-#{new_resource.run_template_name}-run.erb") - @run_script.cookbook(template_cookbook) - @run_script.mode(00755) - @run_script.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) - @run_script + @run_script ||= + begin + t = Chef::Resource::Template.new(::File.join(sv_dir_name, 'run'), run_context) + t.owner(new_resource.owner) + t.group(new_resource.group) + t.source("sv-#{new_resource.run_template_name}-run.erb") + t.cookbook(template_cookbook) + t.mode(00755) + t.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) + t + end end def log_dir - return @log_dir unless @log_dir.nil? - @log_dir = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'log'), run_context) - @log_dir.recursive(true) - @log_dir.owner(new_resource.owner) - @log_dir.group(new_resource.group) - @log_dir.mode(00755) - @log_dir + @log_dir ||= + begin + d = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'log'), run_context) + d.recursive(true) + d.owner(new_resource.owner) + d.group(new_resource.group) + d.mode(00755) + d + end end def log_main_dir - return @log_main_dir unless @log_main_dir.nil? - @log_main_dir = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'log', 'main'), run_context) - @log_main_dir.recursive(true) - @log_main_dir.owner(new_resource.owner) - @log_main_dir.group(new_resource.group) - @log_main_dir.mode(00755) - @log_main_dir + @log_main_dir ||= + begin + d = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'log', 'main'), run_context) + d.recursive(true) + d.owner(new_resource.owner) + d.group(new_resource.group) + d.mode(00755) + d + end end def default_log_dir - return @default_log_dir unless @default_log_dir.nil? - @default_log_dir = Chef::Resource::Directory.new(::File.join("/var/log/#{new_resource.service_name}"), run_context) - @default_log_dir.recursive(true) - @default_log_dir.owner(new_resource.owner) - @default_log_dir.group(new_resource.group) - @default_log_dir.mode(00755) - @default_log_dir + @default_log_dir ||= + begin + d = Chef::Resource::Directory.new(::File.join("/var/log/#{new_resource.service_name}"), run_context) + d.recursive(true) + d.owner(new_resource.owner) + d.group(new_resource.group) + d.mode(00755) + d + end end def log_run_script - return @log_run_script unless @log_run_script.nil? - if new_resource.default_logger - @log_run_script = Chef::Resource::File.new( - ::File.join(sv_dir_name, 'log', 'run'), - run_context - ) - @log_run_script.content(default_logger_content) - @log_run_script.owner(new_resource.owner) - @log_run_script.group(new_resource.group) - @log_run_script.mode(00755) - else - @log_run_script = Chef::Resource::Template.new( - ::File.join(sv_dir_name, 'log', 'run'), - run_context - ) - @log_run_script.owner(new_resource.owner) - @log_run_script.group(new_resource.group) - @log_run_script.mode(00755) - @log_run_script.source("sv-#{new_resource.log_template_name}-log-run.erb") - @log_run_script.cookbook(template_cookbook) - @log_run_script.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) - end - @log_run_script + @log_run_script ||= + begin + if new_resource.default_logger + f = Chef::Resource::File.new( + ::File.join(sv_dir_name, 'log', 'run'), + run_context + ) + f.content(default_logger_content) + f.owner(new_resource.owner) + f.group(new_resource.group) + f.mode(00755) + f + else + t = Chef::Resource::Template.new( + ::File.join(sv_dir_name, 'log', 'run'), + run_context + ) + t.owner(new_resource.owner) + t.group(new_resource.group) + t.mode(00755) + t.source("sv-#{new_resource.log_template_name}-log-run.erb") + t.cookbook(template_cookbook) + t.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) + t + end + end end def log_config_file - return @log_config_file unless @log_config_file.nil? - @log_config_file = Chef::Resource::Template.new(::File.join(sv_dir_name, 'log', 'config'), run_context) - @log_config_file.owner(new_resource.owner) - @log_config_file.group(new_resource.group) - @log_config_file.mode(00644) - @log_config_file.cookbook('runit') - @log_config_file.source('log-config.erb') - @log_config_file.variables( - :size => new_resource.log_size, - :num => new_resource.log_num, - :min => new_resource.log_min, - :timeout => new_resource.log_timeout, - :processor => new_resource.log_processor, - :socket => new_resource.log_socket, - :prefix => new_resource.log_prefix, - :append => new_resource.log_config_append - ) - @log_config_file + @log_config_file ||= + begin + t = Chef::Resource::Template.new(::File.join(sv_dir_name, 'log', 'config'), run_context) + t.owner(new_resource.owner) + t.group(new_resource.group) + t.mode(00644) + t.cookbook('runit') + t.source('log-config.erb') + t.variables( + :size => new_resource.log_size, + :num => new_resource.log_num, + :min => new_resource.log_min, + :timeout => new_resource.log_timeout, + :processor => new_resource.log_processor, + :socket => new_resource.log_socket, + :prefix => new_resource.log_prefix, + :append => new_resource.log_config_append + ) + t + end end def env_dir - return @env_dir unless @env_dir.nil? - @env_dir = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'env'), run_context) - @env_dir.owner(new_resource.owner) - @env_dir.group(new_resource.group) - @env_dir.mode(00755) - @env_dir + @env_dir ||= + begin + d = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'env'), run_context) + d.owner(new_resource.owner) + d.group(new_resource.group) + d.mode(00755) + d + end end def env_files - return @env_files unless @env_files.nil? - create_files = new_resource.env.map do |var, value| - env_file = Chef::Resource::File.new(::File.join(sv_dir_name, 'env', var), run_context) - env_file.owner(new_resource.owner) - env_file.group(new_resource.group) - env_file.content(value) - env_file.action(:create) - env_file - end - extra_env = @current_resource.env.reject { |k,_| new_resource.env.key?(k) } - delete_files = extra_env.map do |k,_| - env_file = Chef::Resource::File.new(::File.join(sv_dir_name, 'env', k), run_context) - env_file.action(:delete) - env_file - end - @env_files = create_files + delete_files - @env_files + @env_files ||= + begin + create_files = new_resource.env.map do |var, value| + f = Chef::Resource::File.new(::File.join(sv_dir_name, 'env', var), run_context) + f.owner(new_resource.owner) + f.group(new_resource.group) + f.content(value) + f.action(:create) + f + end + extra_env = current_resource.env.reject { |k,_| new_resource.env.key?(k) } + delete_files = extra_env.map do |k,_| + f = Chef::Resource::File.new(::File.join(sv_dir_name, 'env', k), run_context) + f.action(:delete) + f + end + create_files + delete_files + end end def get_current_env @@ -449,80 +452,92 @@ def get_current_env end def check_script - return @check_script unless @check_script.nil? - @check_script = Chef::Resource::Template.new(::File.join(sv_dir_name, 'check'), run_context) - @check_script.owner(new_resource.owner) - @check_script.group(new_resource.group) - @check_script.source("sv-#{new_resource.check_script_template_name}-check.erb") - @check_script.cookbook(template_cookbook) - @check_script.mode(00755) - @check_script.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) - @check_script + @check_script ||= + begin + t = Chef::Resource::Template.new(::File.join(sv_dir_name, 'check'), run_context) + t.owner(new_resource.owner) + t.group(new_resource.group) + t.source("sv-#{new_resource.check_script_template_name}-check.erb") + t.cookbook(template_cookbook) + t.mode(00755) + t.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) + t + end end def finish_script - return @finish_script unless @finish_script.nil? - @finish_script = Chef::Resource::Template.new(::File.join(sv_dir_name, 'finish'), run_context) - @finish_script.owner(new_resource.owner) - @finish_script.group(new_resource.group) - @finish_script.mode(00755) - @finish_script.source("sv-#{new_resource.finish_script_template_name}-finish.erb") - @finish_script.cookbook(template_cookbook) - @finish_script.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) - @finish_script + @finish_script ||= + begin + t = Chef::Resource::Template.new(::File.join(sv_dir_name, 'finish'), run_context) + t.owner(new_resource.owner) + t.group(new_resource.group) + t.mode(00755) + t.source("sv-#{new_resource.finish_script_template_name}-finish.erb") + t.cookbook(template_cookbook) + t.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) + t + end end def control_dir - return @control_dir unless @control_dir.nil? - @control_dir = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'control'), run_context) - @control_dir.owner(new_resource.owner) - @control_dir.group(new_resource.group) - @control_dir.mode(00755) - @control_dir + @control_dir ||= + begin + d = Chef::Resource::Directory.new(::File.join(sv_dir_name, 'control'), run_context) + d.owner(new_resource.owner) + d.group(new_resource.group) + d.mode(00755) + d + end end def control_signal_files - return @control_signal_files unless @control_signal_files.nil? - @control_signal_files = new_resource.control.map do |signal| - control_signal_file = Chef::Resource::Template.new( - ::File.join(sv_dir_name, 'control', signal), - run_context - ) - control_signal_file.owner(new_resource.owner) - control_signal_file.group(new_resource.group) - control_signal_file.mode(00755) - control_signal_file.source("sv-#{new_resource.control_template_names[signal]}-#{signal}.erb") - control_signal_file.cookbook(template_cookbook) - control_signal_file.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) - control_signal_file - end - @control_signal_files + @control_signal_files ||= + begin + new_resource.control.map do |signal| + t = Chef::Resource::Template.new( + ::File.join(sv_dir_name, 'control', signal), + run_context + ) + t.owner(new_resource.owner) + t.group(new_resource.group) + t.mode(00755) + t.source("sv-#{new_resource.control_template_names[signal]}-#{signal}.erb") + t.cookbook(template_cookbook) + t.variables(:options => new_resource.options) if new_resource.options.respond_to?(:has_key?) + t + end + end end def lsb_init - return @lsb_init unless @lsb_init.nil? - initfile = ::File.join(new_resource.lsb_init_dir, new_resource.service_name) - if node['platform'] == 'debian' - ::File.unlink(initfile) if ::File.symlink?(initfile) - @lsb_init = Chef::Resource::Template.new(initfile, run_context) - @lsb_init.owner('root') - @lsb_init.group('root') - @lsb_init.mode(00755) - @lsb_init.cookbook('runit') - @lsb_init.source('init.d.erb') - @lsb_init.variables(:name => new_resource.service_name) - else - @lsb_init = Chef::Resource::Link.new(initfile, run_context) - @lsb_init.to(new_resource.sv_bin) - end - @lsb_init + @lsb_init ||= + begin + initfile = ::File.join(new_resource.lsb_init_dir, new_resource.service_name) + if node['platform'] == 'debian' + ::File.unlink(initfile) if ::File.symlink?(initfile) + t = Chef::Resource::Template.new(initfile, run_context) + t.owner('root') + t.group('root') + t.mode(00755) + t.cookbook('runit') + t.source('init.d.erb') + t.variables(:name => new_resource.service_name) + t + else + l = Chef::Resource::Link.new(initfile, run_context) + l.to(new_resource.sv_bin) + l + end + end end def service_link - return @service_link unless @service_link.nil? - @service_link = Chef::Resource::Link.new(::File.join(service_dir_name), run_context) - @service_link.to(sv_dir_name) - @service_link + @service_link ||= + begin + l = Chef::Resource::Link.new(::File.join(service_dir_name), run_context) + l.to(sv_dir_name) + l + end end def inside_docker? From 9fe89176f357aaf48cb1855e084256ff060dee64 Mon Sep 17 00:00:00 2001 From: Aaron Baer Date: Mon, 23 Mar 2015 23:14:46 -0700 Subject: [PATCH 12/14] Runit 1.5.20 --- CHANGELOG.md | 7 +++++++ metadata.rb | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 92c9de1..41b7417 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,13 @@ runit Cookbook CHANGELOG ======================== This file is used to list changes made in each version of the runit cookbook. +v1.5.20 (2015-03-23) +-------------------- +* use imeyer’s packagecloud repo for RHEL +* fix converge_by usage +* do_action helper to set updated_by_last_action +* style fixes to provider + v1.5.18 (2015-03-13) -------------------- * Add helper methods to detect installation presence diff --git a/metadata.rb b/metadata.rb index 0280842..4330358 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache 2.0' description 'Installs runit and provides runit_service definition' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '1.5.19' +version '1.5.20' recipe 'runit', 'Installs and configures runit' From c3d46bcf2c330e90aff8f1bb1e1701d57078cca8 Mon Sep 17 00:00:00 2001 From: jtimberman Date: Wed, 25 Mar 2015 12:19:46 -0600 Subject: [PATCH 13/14] Add support for Fedora 21, kitchen updates This commit mainly adds support for Fedora 21, which now has packages in imeyer's Package Cloud repository. - Update centos base boxes to latest releases - Add ubuntu 14.04 - Add fedora to 'rhel' conditionals where applicable - Register the 'runit_service' resource with MiniTest::Chef so it can be asserted using the runit state instead of underlying system service state checking because that generally will attempt to use the "lsb init interface," which doesn't work with systemd --- .kitchen.yml | 7 +++-- attributes/default.rb | 2 +- recipes/default.rb | 2 +- .../default/tests/minitest/service_test.rb | 31 ++++++++++--------- test/cookbooks/runit_test/recipes/service.rb | 2 +- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/.kitchen.yml b/.kitchen.yml index fd2c548..b57623d 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -5,11 +5,12 @@ provisioner: name: chef_zero platforms: - - name: centos-5.10 - - name: centos-6.5 - - name: fedora-19 + - name: centos-5.11 + - name: centos-6.6 + - name: fedora-21 - name: ubuntu-10.04 - name: ubuntu-12.04 + - name: ubuntu-14.04 suites: - name: default diff --git a/attributes/default.rb b/attributes/default.rb index 5a770a3..f201c8b 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -36,7 +36,7 @@ default['runit']['reload'] = 'reload runsvdir' end -when 'rhel' +when 'rhel', 'fedora' default['runit']['sv_bin'] = '/sbin/sv' default['runit']['chpst_bin'] = '/sbin/chpst' default['runit']['service_dir'] = '/etc/service' diff --git a/recipes/default.rb b/recipes/default.rb index cfc72cc..c3439f8 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -37,7 +37,7 @@ end case node['platform_family'] -when 'rhel' +when 'rhel', 'fedora' packagecloud_repo 'imeyer/runit' unless node['runit']['prefer_local_yum'] package 'runit' diff --git a/test/cookbooks/runit_test/files/default/tests/minitest/service_test.rb b/test/cookbooks/runit_test/files/default/tests/minitest/service_test.rb index c527246..94574c1 100644 --- a/test/cookbooks/runit_test/files/default/tests/minitest/service_test.rb +++ b/test/cookbooks/runit_test/files/default/tests/minitest/service_test.rb @@ -21,9 +21,10 @@ describe 'runit_test::service' do include Helpers::RunitTest + MiniTest::Chef::Resources.register_resource(:runit_service) it 'creates a service with the defaults' do - service('plain-defaults').must_be_running + runit_service('plain-defaults').must_be_running file('/etc/service/plain-defaults/run').must_exist file('/etc/service/plain-defaults/log/run').must_exist file('/etc/init.d/plain-defaults').must_exist @@ -34,53 +35,53 @@ end it 'creates a service that doesnt use the svlog' do - service('no-svlog').must_be_running + runit_service('no-svlog').must_be_running directory('/etc/sv/no-svlog/log').wont_exist end it 'creates a service that uses the default svlog' do regexp = %r{#!/bin/sh\nexec svlogd -tt /var/log/default-svlog} - service('default-svlog').must_be_running + runit_service('default-svlog').must_be_running file('/etc/service/default-svlog/log/run').must_match(regexp) end it 'creates a service that has a check script' do - service('checker').must_be_running + runit_service('checker').must_be_running file('/etc/service/checker/check').must_exist end it 'creates a service that has a finish script' do - service('finisher').must_be_running + runit_service('finisher').must_be_running file('/etc/service/finisher/finish').must_exist end it 'creates a service using sv_timeout' do - service('timer').must_be_running + runit_service('timer').must_be_running end it 'creates a service using sv_verbose' do - service('chatterbox').must_be_running + runit_service('chatterbox').must_be_running end it 'creates a service that uses env files' do regexp = %r{\$PATH:/opt/chef/embedded/bin} - service('env-files').must_be_running + runit_service('env-files').must_be_running file('/etc/service/env-files/env/PATH').must_match(regexp) end it 'creates a service that sets options for the templates' do - service('template-options').must_be_running + runit_service('template-options').must_be_running file('/etc/service/template-options/run').must_match('# Options are delicious') end it 'creates a service that uses control signal files' do - service('control-signals').must_be_running + runit_service('control-signals').must_be_running file('/etc/service/control-signals/control/u').must_match(/control signal up/) end it 'creates a runsvdir service for a normal user' do regexp = %r{exec chpst -ufloyd runsvdir /home/floyd/service} - service('runsvdir-floyd').must_be_running + runit_service('runsvdir-floyd').must_be_running file('/etc/service/runsvdir-floyd/run').must_match(regexp) end @@ -101,11 +102,11 @@ end it 'creates a service with differently named template files' do - service('yerba').must_be_running + runit_service('yerba').must_be_running end it 'creates a service with differently named run script template' do - service('yerba-alt').must_be_running + runit_service('yerba-alt').must_be_running end it 'creates a service that should exist but be disabled' do @@ -114,11 +115,11 @@ end it 'can use templates from another cookbook' do - service('other-cookbook-templates').must_be_running + runit_service('other-cookbook-templates').must_be_running end it 'creates a service that has its own run scripts' do - skip 'RHEL platforms dont ship runit scripts' if node['platform_family'] == 'rhel' + skip 'RHEL platforms dont ship runit scripts' if node['platform_family'] == 'rhel' || node['platform_family'] == 'fedora' git_daemon = shell_out("#{node['runit']['sv_bin']} status /etc/service/git-daemon") assert git_daemon.stdout.include?('run:') diff --git a/test/cookbooks/runit_test/recipes/service.rb b/test/cookbooks/runit_test/recipes/service.rb index 5906448..0428c16 100644 --- a/test/cookbooks/runit_test/recipes/service.rb +++ b/test/cookbooks/runit_test/recipes/service.rb @@ -141,7 +141,7 @@ cookbook 'runit-other_test' end -unless platform_family?('rhel') +unless platform_family?('rhel', 'fedora') # Create a service that has a package with its own service directory package 'git-daemon-run' From 4ec9e67f0091b0de3193edff99c81d49c33a296e Mon Sep 17 00:00:00 2001 From: Aaron Baer Date: Mon, 6 Apr 2015 15:26:53 -0700 Subject: [PATCH 14/14] Runit 1.6.0 --- CHANGELOG.md | 4 +++- metadata.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 41b7417..c10a8b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,8 +2,10 @@ runit Cookbook CHANGELOG ======================== This file is used to list changes made in each version of the runit cookbook. -v1.5.20 (2015-03-23) +v1.6.0 (2015-04-06) -------------------- +* Fedora 21 support +* Kitchen platform updates * use imeyer’s packagecloud repo for RHEL * fix converge_by usage * do_action helper to set updated_by_last_action diff --git a/metadata.rb b/metadata.rb index 4330358..0f46f3d 100644 --- a/metadata.rb +++ b/metadata.rb @@ -4,7 +4,7 @@ license 'Apache 2.0' description 'Installs runit and provides runit_service definition' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) -version '1.5.20' +version '1.6.0' recipe 'runit', 'Installs and configures runit'