From 496284280783fa48fd6093a40f412b488a1dda42 Mon Sep 17 00:00:00 2001 From: Cameron Johnston Date: Mon, 4 Feb 2013 12:41:21 -0700 Subject: [PATCH 1/3] COOK-2337: expose supervisor_service environment attribute on gunicorn and celery lwrps --- providers/celery.rb | 7 ++++++- providers/gunicorn.rb | 5 ++++- resources/celery.rb | 1 + resources/gunicorn.rb | 1 + 4 files changed, 12 insertions(+), 2 deletions(-) diff --git a/providers/celery.rb b/providers/celery.rb index f008454..f20092e 100644 --- a/providers/celery.rb +++ b/providers/celery.rb @@ -80,9 +80,14 @@ django_resource = new_resource.application.sub_resources.select{|res| res.type == :django}.first raise "No Django deployment resource found" unless django_resource command "#{::File.join(django_resource.virtualenv, "bin", "python")} manage.py #{cmd}" + environment new_resource.environment else command cmd - environment 'CELERY_CONFIG_MODULE' => new_resource.config + if new_resource.environment + environment new_resource.environment.merge!({'CELERY_CONFIG_MODULE' => new_resource.config}) + else + environment 'CELERY_CONFIG_MODULE' => new_resource.config + end end directory ::File.join(new_resource.path, "current") autostart false diff --git a/providers/gunicorn.rb b/providers/gunicorn.rb index f241cc0..71df9e4 100644 --- a/providers/gunicorn.rb +++ b/providers/gunicorn.rb @@ -32,7 +32,7 @@ gunicorn_install "gunicorn-#{new_resource.application.name}" do virtualenv django_resource ? django_resource.virtualenv : new_resource.virtualenv end - + if !new_resource.restart_command new_resource.restart_command do run_context.resource_collection.find(:supervisor_service => new_resource.application.name).run_action(:restart) @@ -72,6 +72,9 @@ supervisor_service new_resource.application.name do action :enable + if new_resource.environment + environment new_resource.environment + end if new_resource.app_module == :django django_resource = new_resource.application.sub_resources.select{|res| res.type == :django}.first raise "No Django deployment resource found" unless django_resource diff --git a/resources/celery.rb b/resources/celery.rb index 278ee29..e6cb49c 100644 --- a/resources/celery.rb +++ b/resources/celery.rb @@ -27,6 +27,7 @@ attribute :celerybeat, :kind_of => [TrueClass, FalseClass], :default => false attribute :celerycam, :kind_of => [TrueClass, FalseClass], :default => false attribute :camera_class, :kind_of => [String, NilClass], :default => nil +attribute :environment, :kind_of => [Hash,NilClass], :default => nil def config_base config.split(/[\\\/]/).last diff --git a/resources/gunicorn.rb b/resources/gunicorn.rb index cb337ec..19d8076 100644 --- a/resources/gunicorn.rb +++ b/resources/gunicorn.rb @@ -44,3 +44,4 @@ attribute :virtualenv, :kind_of => String, :default => nil attribute :packages, :kind_of => [Array, Hash], :default => [] attribute :requirements, :kind_of => [NilClass, String, FalseClass], :default => nil +attribute :environment, :kind_of => [Hash,NilClass], :default => nil From cdc96be8465160665004d68670015a3d5cb13cf3 Mon Sep 17 00:00:00 2001 From: Cameron Johnston Date: Fri, 8 Feb 2013 14:29:23 -0700 Subject: [PATCH 2/3] COOK-2337: using merge instead of merge! --- providers/celery.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/providers/celery.rb b/providers/celery.rb index f20092e..1b74b33 100644 --- a/providers/celery.rb +++ b/providers/celery.rb @@ -84,7 +84,7 @@ else command cmd if new_resource.environment - environment new_resource.environment.merge!({'CELERY_CONFIG_MODULE' => new_resource.config}) + environment new_resource.environment.merge({'CELERY_CONFIG_MODULE' => new_resource.config}) else environment 'CELERY_CONFIG_MODULE' => new_resource.config end From e28a1698dd9c6f0537909c1d93cbe8afda30b0fa Mon Sep 17 00:00:00 2001 From: Cameron Johnston Date: Fri, 8 Feb 2013 15:43:15 -0700 Subject: [PATCH 3/3] COOK-2337: default environment attrs to {} --- resources/celery.rb | 2 +- resources/gunicorn.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/celery.rb b/resources/celery.rb index e6cb49c..71d918c 100644 --- a/resources/celery.rb +++ b/resources/celery.rb @@ -27,7 +27,7 @@ attribute :celerybeat, :kind_of => [TrueClass, FalseClass], :default => false attribute :celerycam, :kind_of => [TrueClass, FalseClass], :default => false attribute :camera_class, :kind_of => [String, NilClass], :default => nil -attribute :environment, :kind_of => [Hash,NilClass], :default => nil +attribute :environment, :kind_of => [Hash], :default => {} def config_base config.split(/[\\\/]/).last diff --git a/resources/gunicorn.rb b/resources/gunicorn.rb index 19d8076..641463a 100644 --- a/resources/gunicorn.rb +++ b/resources/gunicorn.rb @@ -44,4 +44,4 @@ attribute :virtualenv, :kind_of => String, :default => nil attribute :packages, :kind_of => [Array, Hash], :default => [] attribute :requirements, :kind_of => [NilClass, String, FalseClass], :default => nil -attribute :environment, :kind_of => [Hash,NilClass], :default => nil +attribute :environment, :kind_of => [Hash], :default => {}