diff --git a/manifests/instance.pp b/manifests/instance.pp --- a/manifests/instance.pp +++ b/manifests/instance.pp @@ -7,6 +7,9 @@ # [*ensure*] # Whether the instance should be enabled, present (but disabled) or absent. # +# [*environment*] +# A hash of environment variables to start the service with. +# # [*executable*] # The wsgi callable to pass to gunicorn # @@ -17,6 +20,9 @@ # # gunicorn::instance {'foo': # ensure => enabled, +# environment => { +# FOOENV => 'foovar', +# } # executable => 'foo.wsgi:app' # user => 'foouser', # group => 'foogroup', @@ -53,7 +59,8 @@ $config_mode = '0644', $working_dir = undef, $log_only_errors = true, - $settings = {} + $settings = {}, + $environment = {} ) { $config_file = "/etc/gunicorn/instances/${name}.cfg" $service_name = "gunicorn-${name}" @@ -94,6 +101,7 @@ # Uses variables: # - $config_file + # - $environment # - $executable # - $group # - $name diff --git a/templates/gunicorn-instance.service.erb b/templates/gunicorn-instance.service.erb --- a/templates/gunicorn-instance.service.erb +++ b/templates/gunicorn-instance.service.erb @@ -13,6 +13,9 @@ PIDFile=<%= @runtime_dir %>/pidfile RuntimeDirectory=<%= @runtime_dir %> WorkingDirectory=<%= @working_dir_override %> +<% @environment.each do |key, value| %> +Environment=<%= key %>=<%= value %> +<% end %> ExecStart=/usr/bin/gunicorn3 -p <%= @runtime_dir %>/pidfile -c <%= @config_file %> <%= @executable %> ExecStop=/bin/kill -TERM $MAINPID ExecReload=/bin/kill -HUP $MAINPID