From 34febeafff0ced241de1821c5b92091301230a17 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 18 Oct 2012 16:52:10 +0000 Subject: [PATCH 01/62] Start work on redoing the gunicorn support of this module to be more useful for our environment. This now allows you to pass in the required parameters from mitx::gunicorn to python::gunicorn. --- manifests/config.pp | 10 ------- manifests/gunicorn.pp | 41 +++++++++++++++++++++++----- templates/gunicorn/gunicorn.conf.erb | 41 ++++++++++++++++++++++++++++ 3 files changed, 75 insertions(+), 17 deletions(-) create mode 100644 templates/gunicorn/gunicorn.conf.erb diff --git a/manifests/config.pp b/manifests/config.pp index 43da22e4..617cb39c 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -9,16 +9,6 @@ if $python::gunicorn { Class['python::install'] -> Python::Gunicorn <| |> - - Python::Gunicorn <| |> ~> Service['gunicorn'] - - service { 'gunicorn': - ensure => running, - enable => true, - hasrestart => true, - hasstatus => false, - pattern => '/usr/bin/gunicorn', - } } } diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index d328d750..d84df117 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -41,12 +41,22 @@ # Sergey Stankevich # define python::gunicorn ( - $ensure = present, - $virtualenv = false, - $mode = 'wsgi', - $dir = false, - $bind = false, - $environment = false + $reporting, + $ensure = present, + $virtualenv = false, + $mode = 'wsgi', + $dir = false, + $bind = false, + $environment = false, + $settings_module = undef, + $port = '8000', + $pre_start_commands = [], + $package_root = '/opt/wwc/mitx', + $app_interface = 'django', + $wsgi_app = undef, + $timeout = '30', + $workers = undef, + $upstart_template = template('python/gunicorn/gunicorn.erb'), ) { # Parameter validation @@ -59,7 +69,24 @@ mode => '0644', owner => 'root', group => 'root', - content => template('python/gunicorn.erb'), + content => $upstart_template, + } + + file { "/etc/init/${name}.conf": + ensure => file, + owner => 'root', + group => 'root', + mode => '0644', + require => Class['python::install'], + notify => Service[$name], + content => $upstart_template, + } + + service { $name: + ensure => running, + provider => 'upstart', + require => File["/etc/init/${name}.conf"], + tag => release } } diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb new file mode 100644 index 00000000..a3cc2f04 --- /dev/null +++ b/templates/gunicorn/gunicorn.conf.erb @@ -0,0 +1,41 @@ +# gunicorn + +description "gunicorn server" +author "Calen Pennington " + +start on runlevel [2345] +stop on runlevel [!2345] + +respawn +respawn limit 3 30 + +env PID=/var/run/gunicorn/<%= name %>.pid +env NEW_RELIC_CONFIG_FILE=/opt/wwc/newrelic.ini +env NEWRELIC=/usr/local/bin/newrelic-admin +<% if @workers -%> +env WORKERS=<%= @workers %> +<% else -%> +env WORKERS=<%= 4 * @processorcount.to_i %> +<% end -%> +env PORT=<%= @port %> +env LANG=en_US.UTF-8 +env DJANGO_SETTINGS_MODULE=<%= @settings_module %> + +pre-start script +<% pre_start_commands.each do |cmd| -%> + <%= cmd %> +<% end -%> +end script + +chdir <%= @package_root %> +setuid makeitso + +<% case app_interface + when 'django' %> + +exec $NEWRELIC run-program /usr/local/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= @timeout %> --pythonpath=<%= @package_root %> --settings=<%= @settings_module %> +<% when 'wsgi' %> + +exec $NEWRELIC run-program /usr/local/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= @timeout %> --pythonpath=<%= @package_root %> <%= @wsgi_app %> + +<% end %> From 8949de3a36fa593eb396d1277a4bbcc0b8c4d89a Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 18 Oct 2012 17:37:57 +0000 Subject: [PATCH 02/62] Various changes to rework and redesign the gunicorn support within this module. Make it more appropriate for our environment, so it uses upstart and installs gunicorn into the virtualenv. --- manifests/config.pp | 4 ---- manifests/gunicorn.pp | 14 +++++--------- manifests/gunicorn/install.pp | 10 ++++++++++ manifests/install.pp | 7 ------- templates/gunicorn/gunicorn.conf.erb | 20 +++++++++----------- 5 files changed, 24 insertions(+), 31 deletions(-) create mode 100644 manifests/gunicorn/install.pp diff --git a/manifests/config.pp b/manifests/config.pp index 617cb39c..8e7cc3ef 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -7,8 +7,4 @@ Python::Virtualenv <| |> -> Python::Pip <| |> Python::Virtualenv <| |> -> Python::Requirements <| |> - if $python::gunicorn { - Class['python::install'] -> Python::Gunicorn <| |> - } - } diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index d84df117..a5078458 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -59,25 +59,21 @@ $upstart_template = template('python/gunicorn/gunicorn.erb'), ) { + class { 'python::gunicorn::install': + virtualenv => $virtualenv, + } + # Parameter validation if ! $dir { fail('python::gunicorn: dir parameter must not be empty') } - file { "/etc/gunicorn.d/${name}": - ensure => $ensure, - mode => '0644', - owner => 'root', - group => 'root', - content => $upstart_template, - } - file { "/etc/init/${name}.conf": ensure => file, owner => 'root', group => 'root', mode => '0644', - require => Class['python::install'], + require => Class['python::gunicorn::install'], notify => Service[$name], content => $upstart_template, } diff --git a/manifests/gunicorn/install.pp b/manifests/gunicorn/install.pp new file mode 100644 index 00000000..48814759 --- /dev/null +++ b/manifests/gunicorn/install.pp @@ -0,0 +1,10 @@ +class python::gunicorn::install( + $virtualenv, +) { + + python::pip { 'gunicorn': + ensure => present, + virtualenv => $virtualenv, + } + +} diff --git a/manifests/install.pp b/manifests/install.pp index dec99b8a..7092dac8 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -21,11 +21,4 @@ package { 'python-virtualenv': ensure => $venv_ensure } - $gunicorn_ensure = $python::gunicorn ? { - true => present, - default => absent, - } - - package { 'gunicorn': ensure => $gunicorn_ensure } - } diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index a3cc2f04..9800bee5 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -12,14 +12,14 @@ respawn limit 3 30 env PID=/var/run/gunicorn/<%= name %>.pid env NEW_RELIC_CONFIG_FILE=/opt/wwc/newrelic.ini env NEWRELIC=/usr/local/bin/newrelic-admin -<% if @workers -%> -env WORKERS=<%= @workers %> +<% if scope.lookupvar('workers') -%> +env WORKERS=<%= scope.lookupvar('workers') %> <% else -%> -env WORKERS=<%= 4 * @processorcount.to_i %> +env WORKERS=<%= 4 * scope.lookupvar('::processorcount').to_i %> <% end -%> -env PORT=<%= @port %> +env PORT=<%= scope.lookupvar('port') %> env LANG=en_US.UTF-8 -env DJANGO_SETTINGS_MODULE=<%= @settings_module %> +env DJANGO_SETTINGS_MODULE=<%= scope.lookupvar('settings_module') %> pre-start script <% pre_start_commands.each do |cmd| -%> @@ -27,15 +27,13 @@ pre-start script <% end -%> end script -chdir <%= @package_root %> +chdir <%= scope.lookupvar('package_root') %> setuid makeitso -<% case app_interface - when 'django' %> - -exec $NEWRELIC run-program /usr/local/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= @timeout %> --pythonpath=<%= @package_root %> --settings=<%= @settings_module %> +<% case scope.lookupvar('app_interface') when 'django' %> +exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> <% when 'wsgi' %> -exec $NEWRELIC run-program /usr/local/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= @timeout %> --pythonpath=<%= @package_root %> <%= @wsgi_app %> + exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> <% end %> From 2d96da0466fbe6752e813c46d309bf9738c7d69b Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 18 Oct 2012 18:24:20 +0000 Subject: [PATCH 03/62] Fix template location. --- manifests/gunicorn.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index a5078458..a6aab021 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -56,7 +56,7 @@ $wsgi_app = undef, $timeout = '30', $workers = undef, - $upstart_template = template('python/gunicorn/gunicorn.erb'), + $upstart_template = template('python/gunicorn/gunicorn.conf.erb'), ) { class { 'python::gunicorn::install': From 1589f7fe6124f84730094eb0fbfdaba9fe0b9185 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 18 Oct 2012 18:27:10 +0000 Subject: [PATCH 04/62] Tweak this to account for package_root rather than dir. --- manifests/gunicorn.pp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index a6aab021..55c578da 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -14,7 +14,7 @@ # Gunicorn mode. # wsgi|django. Default: wsgi # -# [*dir*] +# [*package_root*] # Application directory. # # [*bind*] @@ -28,12 +28,12 @@ # === Examples # # python::gunicorn { 'vhost': -# ensure => present, -# virtualenv => '/var/www/project1', -# mode => 'wsgi', -# dir => '/var/www/project1/current', -# bind => 'unix:/tmp/gunicorn.socket', -# environment => 'prod', +# ensure => present, +# virtualenv => '/var/www/project1', +# mode => 'wsgi', +# package_root => '/var/www/project1/current', +# bind => 'unix:/tmp/gunicorn.socket', +# environment => 'prod', # } # # === Authors @@ -45,7 +45,6 @@ $ensure = present, $virtualenv = false, $mode = 'wsgi', - $dir = false, $bind = false, $environment = false, $settings_module = undef, @@ -63,11 +62,6 @@ virtualenv => $virtualenv, } - # Parameter validation - if ! $dir { - fail('python::gunicorn: dir parameter must not be empty') - } - file { "/etc/init/${name}.conf": ensure => file, owner => 'root', From df6eee4cfa57c840d75ad43257abbf787d97868d Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 18 Oct 2012 18:27:41 +0000 Subject: [PATCH 05/62] Fix this up to rename dir to package_root. --- manifests/gunicorn.pp | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index a6aab021..55c578da 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -14,7 +14,7 @@ # Gunicorn mode. # wsgi|django. Default: wsgi # -# [*dir*] +# [*package_root*] # Application directory. # # [*bind*] @@ -28,12 +28,12 @@ # === Examples # # python::gunicorn { 'vhost': -# ensure => present, -# virtualenv => '/var/www/project1', -# mode => 'wsgi', -# dir => '/var/www/project1/current', -# bind => 'unix:/tmp/gunicorn.socket', -# environment => 'prod', +# ensure => present, +# virtualenv => '/var/www/project1', +# mode => 'wsgi', +# package_root => '/var/www/project1/current', +# bind => 'unix:/tmp/gunicorn.socket', +# environment => 'prod', # } # # === Authors @@ -45,7 +45,6 @@ $ensure = present, $virtualenv = false, $mode = 'wsgi', - $dir = false, $bind = false, $environment = false, $settings_module = undef, @@ -63,11 +62,6 @@ virtualenv => $virtualenv, } - # Parameter validation - if ! $dir { - fail('python::gunicorn: dir parameter must not be empty') - } - file { "/etc/init/${name}.conf": ensure => file, owner => 'root', From d352d0c8f41d79d10a1b53465a272bdb97730161 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 18 Oct 2012 18:52:06 +0000 Subject: [PATCH 06/62] Fix template. --- templates/gunicorn/gunicorn.conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 9800bee5..38c0b40a 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -34,6 +34,6 @@ setuid makeitso exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> <% when 'wsgi' %> - exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> + exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> <% end %> From 7cd9b4363fe830472f1d8f851dca058d3b236935 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 18 Oct 2012 19:06:45 +0000 Subject: [PATCH 07/62] Further changes to better enable newrelic in a virtualenv. --- templates/gunicorn.erb | 35 ---------------------------- templates/gunicorn/gunicorn.conf.erb | 2 +- 2 files changed, 1 insertion(+), 36 deletions(-) delete mode 100644 templates/gunicorn.erb diff --git a/templates/gunicorn.erb b/templates/gunicorn.erb deleted file mode 100644 index 2cf3eedd..00000000 --- a/templates/gunicorn.erb +++ /dev/null @@ -1,35 +0,0 @@ -CONFIG = { -<% if mode == 'django' -%> - 'mode': 'django', -<% else -%> - 'mode': 'wsgi', -<% end -%> -<% if virtualenv -%> - 'environment': { -<% if environment -%> - 'ENVIRONMENT': '<%= environment %>', -<% end -%> - 'PYTHONPATH': '<%= virtualenv %>' - }, -<% end -%> - 'working_dir': '<%= dir %>', - 'user': 'www-data', - 'group': 'www-data', -<% if virtualenv -%> - 'python': '<%= virtualenv %>/bin/python', -<% else -%> - 'python': '/usr/bin/python', -<% end -%> - 'args': ( -<% if !virtualenv and !bind -%> - '--bind=unix:/tmp/gunicorn-<%= name %>.socket', -<% elsif virtualenv and !bind -%> - '--bind=unix:<%= virtualenv %>/<%= name %>.socket', -<% else -%> - '--bind=<%= bind %>', -<% end -%> - '--workers=<%= @processorcount.to_i*2 %>', - '--timeout=30', - 'app:app', - ), -} diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 38c0b40a..1a5533e5 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -11,7 +11,7 @@ respawn limit 3 30 env PID=/var/run/gunicorn/<%= name %>.pid env NEW_RELIC_CONFIG_FILE=/opt/wwc/newrelic.ini -env NEWRELIC=/usr/local/bin/newrelic-admin +env NEWRELIC=<%= scope.lookupvar('virtualenv') %>/bin/newrelic-admin <% if scope.lookupvar('workers') -%> env WORKERS=<%= scope.lookupvar('workers') %> <% else -%> From 44a100c9064cce0c50464f4346be409c08df7467 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 18 Oct 2012 20:19:29 +0000 Subject: [PATCH 08/62] Maybe this'll let requirements.txt finish. There's a lot of stuff in there. --- manifests/requirements.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/requirements.pp b/manifests/requirements.pp index b6c9b346..334236a0 100644 --- a/manifests/requirements.pp +++ b/manifests/requirements.pp @@ -61,7 +61,7 @@ command => "${pip_env} install ${proxy_flag} -Ur ${requirements}", cwd => $virtualenv, refreshonly => true, - timeout => 1800, + timeout => 3600, subscribe => Exec["python_requirements_check_${name}"], } From 2dc81d110ee2b9f2c339c98d2b2eb1425fbc2e39 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 23 Oct 2012 00:48:23 +0000 Subject: [PATCH 09/62] Use the $reqdir because we have several lines in our requirements.txt that use -e and relative paths. --- manifests/requirements.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/requirements.pp b/manifests/requirements.pp index 334236a0..b40a9bb8 100644 --- a/manifests/requirements.pp +++ b/manifests/requirements.pp @@ -59,7 +59,7 @@ exec { "python_requirements_update_${name}": command => "${pip_env} install ${proxy_flag} -Ur ${requirements}", - cwd => $virtualenv, + cwd => $req_dir, refreshonly => true, timeout => 3600, subscribe => Exec["python_requirements_check_${name}"], From 2b7e3fda04f5f3b6f97d50203b1dcd5e94b25645 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 24 Oct 2012 14:07:02 +0000 Subject: [PATCH 10/62] Make sure the init script isn't full of extra blank lines. --- templates/gunicorn/gunicorn.conf.erb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 1a5533e5..2a2b59aa 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -12,28 +12,27 @@ respawn limit 3 30 env PID=/var/run/gunicorn/<%= name %>.pid env NEW_RELIC_CONFIG_FILE=/opt/wwc/newrelic.ini env NEWRELIC=<%= scope.lookupvar('virtualenv') %>/bin/newrelic-admin -<% if scope.lookupvar('workers') -%> +<%= if scope.lookupvar('workers') -%> env WORKERS=<%= scope.lookupvar('workers') %> -<% else -%> +<%= else -%> env WORKERS=<%= 4 * scope.lookupvar('::processorcount').to_i %> -<% end -%> +<%= end -%> env PORT=<%= scope.lookupvar('port') %> env LANG=en_US.UTF-8 env DJANGO_SETTINGS_MODULE=<%= scope.lookupvar('settings_module') %> pre-start script -<% pre_start_commands.each do |cmd| -%> +<%= pre_start_commands.each do |cmd| -%> <%= cmd %> -<% end -%> +<%= end -%> end script chdir <%= scope.lookupvar('package_root') %> setuid makeitso -<% case scope.lookupvar('app_interface') when 'django' %> +<%= case scope.lookupvar('app_interface') when 'django' %> exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> -<% when 'wsgi' %> +<%= when 'wsgi' %> +exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> - exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> - -<% end %> +<%= end %> From e012abfb98f6337503b86ca12ff955900f20a802 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 24 Oct 2012 14:08:59 +0000 Subject: [PATCH 11/62] Further updates to allow us to pass in a user to run as. --- templates/gunicorn/gunicorn.conf.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 2a2b59aa..52eb5ee6 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -10,7 +10,7 @@ respawn respawn limit 3 30 env PID=/var/run/gunicorn/<%= name %>.pid -env NEW_RELIC_CONFIG_FILE=/opt/wwc/newrelic.ini +env NEW_RELIC_CONFIG_FILE=<%= scope.lookupvar('package_root') %>/newrelic.ini env NEWRELIC=<%= scope.lookupvar('virtualenv') %>/bin/newrelic-admin <%= if scope.lookupvar('workers') -%> env WORKERS=<%= scope.lookupvar('workers') %> @@ -28,7 +28,7 @@ pre-start script end script chdir <%= scope.lookupvar('package_root') %> -setuid makeitso +setuid <%= scope.lookupvar('user') %> <%= case scope.lookupvar('app_interface') when 'django' %> exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> From c8d81d30a5bd6d7a4a1694f2cec0619922310fa9 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 24 Oct 2012 14:11:04 +0000 Subject: [PATCH 12/62] Push $user into gunicorn. --- manifests/gunicorn.pp | 1 + 1 file changed, 1 insertion(+) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index 55c578da..867e04c3 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -55,6 +55,7 @@ $wsgi_app = undef, $timeout = '30', $workers = undef, + $user = 'www-data', $upstart_template = template('python/gunicorn/gunicorn.conf.erb'), ) { From 958d5dd10ca182ead186ce39c450132a026211db Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 24 Oct 2012 14:16:37 +0000 Subject: [PATCH 13/62] Fix this by using -%> to not output blank lines, total brain lapse moment. --- templates/gunicorn/gunicorn.conf.erb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 52eb5ee6..f0ba28fc 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -12,27 +12,27 @@ respawn limit 3 30 env PID=/var/run/gunicorn/<%= name %>.pid env NEW_RELIC_CONFIG_FILE=<%= scope.lookupvar('package_root') %>/newrelic.ini env NEWRELIC=<%= scope.lookupvar('virtualenv') %>/bin/newrelic-admin -<%= if scope.lookupvar('workers') -%> +<% if scope.lookupvar('workers') -%> env WORKERS=<%= scope.lookupvar('workers') %> -<%= else -%> +<% else -%> env WORKERS=<%= 4 * scope.lookupvar('::processorcount').to_i %> -<%= end -%> +<% end -%> env PORT=<%= scope.lookupvar('port') %> env LANG=en_US.UTF-8 env DJANGO_SETTINGS_MODULE=<%= scope.lookupvar('settings_module') %> pre-start script -<%= pre_start_commands.each do |cmd| -%> +<% pre_start_commands.each do |cmd| -%> <%= cmd %> -<%= end -%> +<% end -%> end script chdir <%= scope.lookupvar('package_root') %> setuid <%= scope.lookupvar('user') %> -<%= case scope.lookupvar('app_interface') when 'django' %> +<% case scope.lookupvar('app_interface') when 'django' -%> exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> -<%= when 'wsgi' %> +<% when 'wsgi' -%> exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> -<%= end %> +<% end -%> From a7383f67d676827de10e2749a6cd21e98109504f Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 24 Oct 2012 17:21:32 +0000 Subject: [PATCH 14/62] Add base to python::gunicorn --- manifests/gunicorn.pp | 19 ++++++++++--------- templates/gunicorn/gunicorn.conf.erb | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index 867e04c3..c66b9074 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -42,21 +42,22 @@ # define python::gunicorn ( $reporting, - $ensure = present, - $virtualenv = false, - $mode = 'wsgi', + $app_interface = 'django', + $base = '/opt/wwc', $bind = false, + $ensure = present, $environment = false, - $settings_module = undef, + $mode = 'wsgi', + $package_root = '/opt/wwc/mitx', $port = '8000', $pre_start_commands = [], - $package_root = '/opt/wwc/mitx', - $app_interface = 'django', - $wsgi_app = undef, + $settings_module = undef, $timeout = '30', - $workers = undef, - $user = 'www-data', $upstart_template = template('python/gunicorn/gunicorn.conf.erb'), + $user = 'www-data', + $virtualenv = false, + $workers = undef, + $wsgi_app = undef, ) { class { 'python::gunicorn::install': diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index f0ba28fc..9d8bb9ed 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -10,7 +10,7 @@ respawn respawn limit 3 30 env PID=/var/run/gunicorn/<%= name %>.pid -env NEW_RELIC_CONFIG_FILE=<%= scope.lookupvar('package_root') %>/newrelic.ini +env NEW_RELIC_CONFIG_FILE=<%= scope.lookupvar('base') %>/newrelic.ini env NEWRELIC=<%= scope.lookupvar('virtualenv') %>/bin/newrelic-admin <% if scope.lookupvar('workers') -%> env WORKERS=<%= scope.lookupvar('workers') %> From 28a3da150a10aa13f4180f54fa7c2a3072cc9002 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 9 Nov 2012 15:46:42 +0000 Subject: [PATCH 15/62] Tweak template to add new params. --- templates/gunicorn/gunicorn.conf.erb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 9d8bb9ed..16937dd3 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -7,7 +7,9 @@ start on runlevel [2345] stop on runlevel [!2345] respawn +<% if scope.lookupvar('respawn_limit') %> -%> respawn limit 3 30 +<% end -%> env PID=/var/run/gunicorn/<%= name %>.pid env NEW_RELIC_CONFIG_FILE=<%= scope.lookupvar('base') %>/newrelic.ini @@ -34,5 +36,6 @@ setuid <%= scope.lookupvar('user') %> exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> <% when 'wsgi' -%> exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> - +<% when 'python' -%> +exec python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> <% end -%> From 3cc66b509c631d43df4d4b8ab1a805d4468de345 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 9 Nov 2012 15:47:51 +0000 Subject: [PATCH 16/62] Add params to gunicorn and test for respawn_limit false. --- manifests/gunicorn.pp | 1 + templates/gunicorn/gunicorn.conf.erb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index c66b9074..321cac6c 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -51,6 +51,7 @@ $package_root = '/opt/wwc/mitx', $port = '8000', $pre_start_commands = [], + $respawn_limit = false, $settings_module = undef, $timeout = '30', $upstart_template = template('python/gunicorn/gunicorn.conf.erb'), diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 16937dd3..12f83d0f 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -7,7 +7,7 @@ start on runlevel [2345] stop on runlevel [!2345] respawn -<% if scope.lookupvar('respawn_limit') %> -%> +<% if scope.lookupvar('respawn_limit') != false %> -%> respawn limit 3 30 <% end -%> From 4ba3648ac74db77482d8beba9ab82347c1cd7106 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 9 Nov 2012 17:37:52 +0000 Subject: [PATCH 17/62] Make sure we can set a script_name for 'straight python' startup scripts and fix a typo in the template. --- manifests/gunicorn.pp | 1 + templates/gunicorn/gunicorn.conf.erb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index 321cac6c..ffc3a721 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -52,6 +52,7 @@ $port = '8000', $pre_start_commands = [], $respawn_limit = false, + $script_name = '', $settings_module = undef, $timeout = '30', $upstart_template = template('python/gunicorn/gunicorn.conf.erb'), diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 12f83d0f..e4b8dce6 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -7,7 +7,7 @@ start on runlevel [2345] stop on runlevel [!2345] respawn -<% if scope.lookupvar('respawn_limit') != false %> -%> +<% if scope.lookupvar('respawn_limit') != false -%> respawn limit 3 30 <% end -%> From 5307395deb127868644881556e520e8299ea295e Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 9 Nov 2012 18:10:04 +0000 Subject: [PATCH 18/62] Full paths. --- manifests/requirements.pp | 2 +- manifests/virtualenv.pp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/requirements.pp b/manifests/requirements.pp index b40a9bb8..ce3a41a1 100644 --- a/manifests/requirements.pp +++ b/manifests/requirements.pp @@ -29,7 +29,7 @@ $requirements = $name $pip_env = $virtualenv ? { - 'system' => '`which pip`', + 'system' => '`/bin/which pip`', default => "${virtualenv}/bin/pip", } diff --git a/manifests/virtualenv.pp b/manifests/virtualenv.pp index f22f4e14..ebb9834d 100644 --- a/manifests/virtualenv.pp +++ b/manifests/virtualenv.pp @@ -58,7 +58,7 @@ exec { "python_virtualenv_${venv_dir}": command => "mkdir -p ${venv_dir} \ ${proxy_command} \ - && virtualenv -p `which ${python}` ${venv_dir} \ + && virtualenv -p `/bin/which ${python}` ${venv_dir} \ && ${venv_dir}/bin/pip install ${proxy_flag} --upgrade distribute pip", creates => $venv_dir, } From 5bc7333a3b8266a53cb1ae69e7a94b6c1b103dd3 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Fri, 9 Nov 2012 18:37:15 +0000 Subject: [PATCH 19/62] Tweak this. --- templates/gunicorn/gunicorn.conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index e4b8dce6..a6d8470c 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -37,5 +37,5 @@ exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn_dja <% when 'wsgi' -%> exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> <% when 'python' -%> -exec python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> +exec python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 2>&1 <% end -%> From f6f9b1282ebd61356104543c04b4fd8a1188aec1 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Mon, 26 Nov 2012 20:50:29 +0000 Subject: [PATCH 20/62] Hopefully modify this to check reporting and disable newrelic if required. --- templates/gunicorn/gunicorn.conf.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index a6d8470c..a2365322 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -33,9 +33,9 @@ chdir <%= scope.lookupvar('package_root') %> setuid <%= scope.lookupvar('user') %> <% case scope.lookupvar('app_interface') when 'django' -%> -exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> +<% if scope.lookupvar('reporting') == true -%>exec $NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> <% when 'wsgi' -%> -exec $NEWRELIC run-program <%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> + <% if scope.lookupvar('reporting') == true -%>exec $NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> <% when 'python' -%> exec python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 2>&1 <% end -%> From 4c91ca682f8d02aae536121d1d8fde81f0246f7f Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Mon, 26 Nov 2012 21:01:15 +0000 Subject: [PATCH 21/62] Keep the exec out the if. --- templates/gunicorn/gunicorn.conf.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index a2365322..d0bdf0d1 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -33,9 +33,9 @@ chdir <%= scope.lookupvar('package_root') %> setuid <%= scope.lookupvar('user') %> <% case scope.lookupvar('app_interface') when 'django' -%> -<% if scope.lookupvar('reporting') == true -%>exec $NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> +exec <% if scope.lookupvar('reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> <% when 'wsgi' -%> - <% if scope.lookupvar('reporting') == true -%>exec $NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> +exec <% if scope.lookupvar('reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> <% when 'python' -%> exec python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 2>&1 <% end -%> From 6a60280a2bf1cdb1ace79257bd6f05da5339d177 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 29 Nov 2012 18:02:15 +0000 Subject: [PATCH 22/62] Fix this. --- manifests/requirements.pp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/manifests/requirements.pp b/manifests/requirements.pp index ce3a41a1..f19fbe8e 100644 --- a/manifests/requirements.pp +++ b/manifests/requirements.pp @@ -24,6 +24,8 @@ define python::requirements ( $virtualenv = 'system', $proxy = false + $owner = 'www-data', + $group = 'www-data', ) { $requirements = $name @@ -44,8 +46,8 @@ file { $requirements: ensure => present, mode => '0644', - owner => 'root', - group => 'root', + owner => $owner, + group => $group, replace => false, content => '# Puppet will install and/or update pip packages listed here', } From d67b403eb651e3877e1cce27ca0638d215f87de5 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 29 Nov 2012 18:04:41 +0000 Subject: [PATCH 23/62] Fix. --- manifests/requirements.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/requirements.pp b/manifests/requirements.pp index f19fbe8e..d5995e7f 100644 --- a/manifests/requirements.pp +++ b/manifests/requirements.pp @@ -23,7 +23,7 @@ # define python::requirements ( $virtualenv = 'system', - $proxy = false + $proxy = false, $owner = 'www-data', $group = 'www-data', ) { From 5568e03a55a1e8690f1a9dff18c1b8930d08a070 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Tue, 4 Dec 2012 21:26:05 +0000 Subject: [PATCH 24/62] Add a service_enabled param. --- manifests/gunicorn.pp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index ffc3a721..00cd131f 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -53,6 +53,7 @@ $pre_start_commands = [], $respawn_limit = false, $script_name = '', + $service_enabled = 'present', $settings_module = undef, $timeout = '30', $upstart_template = template('python/gunicorn/gunicorn.conf.erb'), @@ -77,7 +78,7 @@ } service { $name: - ensure => running, + ensure => $service_enabled, provider => 'upstart', require => File["/etc/init/${name}.conf"], tag => release From 157edbcfcde15a71b2c6d1867ac12df40b4a24ae Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Tue, 4 Dec 2012 20:50:41 -0500 Subject: [PATCH 25/62] default service state from 'present' to 'running' --- manifests/gunicorn.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index 00cd131f..40eb1302 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -53,7 +53,7 @@ $pre_start_commands = [], $respawn_limit = false, $script_name = '', - $service_enabled = 'present', + $service_enabled = 'running', $settings_module = undef, $timeout = '30', $upstart_template = template('python/gunicorn/gunicorn.conf.erb'), From e0ba7974dfef172bd6596a4cbf1cebeabe0a1439 Mon Sep 17 00:00:00 2001 From: ashley Penney Date: Tue, 11 Dec 2012 09:03:09 -0500 Subject: [PATCH 26/62] Add testing to the python module. --- Rakefile | 10 ++-------- spec/classes/python_spec.rb | 4 ++++ spec/spec_helper.rb | 2 ++ 3 files changed, 8 insertions(+), 8 deletions(-) create mode 100644 spec/classes/python_spec.rb create mode 100644 spec/spec_helper.rb diff --git a/Rakefile b/Rakefile index 58df3ec3..14f1c246 100644 --- a/Rakefile +++ b/Rakefile @@ -1,8 +1,2 @@ -# Rakefile for puppet-lint (https://github.com/rodjek/puppet-lint) -# Run: rake lint - -require 'puppet-lint/tasks/puppet-lint' -PuppetLint.configuration.with_filename = true -PuppetLint.configuration.send('disable_documentation') -PuppetLint.configuration.send('disable_class_parameter_defaults') -PuppetLint.configuration.send('disable_80chars') +require 'rubygems' +require 'puppetlabs_spec_helper/rake_tasks' diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb new file mode 100644 index 00000000..7fa1bb48 --- /dev/null +++ b/spec/classes/python_spec.rb @@ -0,0 +1,4 @@ +require 'spec_helper' + +describe "python" do +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 00000000..dc7e9f4a --- /dev/null +++ b/spec/spec_helper.rb @@ -0,0 +1,2 @@ +require 'rubygems' +require 'puppetlabs_spec_helper/module_spec_helper' From 82d1382f12243a76461ff7e8299705f975107d4e Mon Sep 17 00:00:00 2001 From: ashley Penney Date: Mon, 17 Dec 2012 09:10:04 -0500 Subject: [PATCH 27/62] Ensure we use the virtualenv copy of python. --- templates/gunicorn/gunicorn.conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index d0bdf0d1..64475321 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -37,5 +37,5 @@ exec <% if scope.lookupvar('reporting') == true -%>$NEWRELIC run-program <% end <% when 'wsgi' -%> exec <% if scope.lookupvar('reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> <% when 'python' -%> -exec python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 2>&1 + exec <%= scope.lookupvar('virtualenv') %>/python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 2>&1 <% end -%> From d7814da0df4cc852317afcd3ca9065d4cba6d2fe Mon Sep 17 00:00:00 2001 From: ashley Penney Date: Mon, 17 Dec 2012 09:14:04 -0500 Subject: [PATCH 28/62] $virtualenv doesn't include /bin/, whoops. --- templates/gunicorn/gunicorn.conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 64475321..bd66f080 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -37,5 +37,5 @@ exec <% if scope.lookupvar('reporting') == true -%>$NEWRELIC run-program <% end <% when 'wsgi' -%> exec <% if scope.lookupvar('reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> <% when 'python' -%> - exec <%= scope.lookupvar('virtualenv') %>/python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 2>&1 + exec <%= scope.lookupvar('virtualenv') %>/bin/python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 2>&1 <% end -%> From 46697feb6cd72d8ab1a97583b935eb74227a7e6e Mon Sep 17 00:00:00 2001 From: ashley Penney Date: Mon, 17 Dec 2012 10:17:32 -0500 Subject: [PATCH 29/62] su instead of use setuid due to some weirdness. --- templates/gunicorn/gunicorn.conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index bd66f080..f1f2ba03 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -37,5 +37,5 @@ exec <% if scope.lookupvar('reporting') == true -%>$NEWRELIC run-program <% end <% when 'wsgi' -%> exec <% if scope.lookupvar('reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> <% when 'python' -%> - exec <%= scope.lookupvar('virtualenv') %>/bin/python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 2>&1 +exec su - www-data -c '<%= scope.lookupvar('virtualenv') %>/bin/python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 2>&1' <% end -%> From f9767cf3142adf9efe857773b3445207d1a71860 Mon Sep 17 00:00:00 2001 From: ashley Penney Date: Mon, 17 Dec 2012 12:03:09 -0500 Subject: [PATCH 30/62] Not happy with this. --- templates/gunicorn/gunicorn.conf.erb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index f1f2ba03..d8e02060 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -30,7 +30,9 @@ pre-start script end script chdir <%= scope.lookupvar('package_root') %> +<% if scope.lookupvar('app_interface') == 'python' -%> setuid <%= scope.lookupvar('user') %> +<% end -%> <% case scope.lookupvar('app_interface') when 'django' -%> exec <% if scope.lookupvar('reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> From 3b40200fccc3d743371df276a70ea6b7dfd5f83f Mon Sep 17 00:00:00 2001 From: ashley Penney Date: Mon, 17 Dec 2012 12:18:58 -0500 Subject: [PATCH 31/62] I regret this too. --- templates/gunicorn/gunicorn.conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index d8e02060..bb876fd4 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -30,7 +30,7 @@ pre-start script end script chdir <%= scope.lookupvar('package_root') %> -<% if scope.lookupvar('app_interface') == 'python' -%> +<% if scope.lookupvar('app_interface') != 'python' -%> setuid <%= scope.lookupvar('user') %> <% end -%> From dbca908ffb3a0ec3e1f3de1b08ef8279cf107c10 Mon Sep 17 00:00:00 2001 From: ashley Penney Date: Tue, 18 Dec 2012 09:07:41 -0500 Subject: [PATCH 32/62] WHY, WHY WOULD UPGRADING BE THE DEFAULT. --- manifests/requirements.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/requirements.pp b/manifests/requirements.pp index d5995e7f..ee84cf35 100644 --- a/manifests/requirements.pp +++ b/manifests/requirements.pp @@ -60,7 +60,7 @@ } exec { "python_requirements_update_${name}": - command => "${pip_env} install ${proxy_flag} -Ur ${requirements}", + command => "${pip_env} install ${proxy_flag} -r ${requirements}", cwd => $req_dir, refreshonly => true, timeout => 3600, From cdfb6b2a8b5f7ebe36c6f806af6bc5a3891f1e8e Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 30 Jan 2013 12:31:46 -0500 Subject: [PATCH 33/62] Add newrelic handling into the service directly, and make sure we can actually use this define multiple times. --- manifests/gunicorn.pp | 14 +++++++------- manifests/gunicorn/install.pp | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index 40eb1302..7af74fc2 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -63,9 +63,8 @@ $wsgi_app = undef, ) { - class { 'python::gunicorn::install': - virtualenv => $virtualenv, - } + include 'python::gunicorn::install' + include 'edx::newrelic' file { "/etc/init/${name}.conf": ensure => file, @@ -78,10 +77,11 @@ } service { $name: - ensure => $service_enabled, - provider => 'upstart', - require => File["/etc/init/${name}.conf"], - tag => release + ensure => $service_enabled, + provider => 'upstart', + require => File["/etc/init/${name}.conf"], + tag => release, + subscribe => Class['edx::newrelic'], } } diff --git a/manifests/gunicorn/install.pp b/manifests/gunicorn/install.pp index 48814759..2686d091 100644 --- a/manifests/gunicorn/install.pp +++ b/manifests/gunicorn/install.pp @@ -1,5 +1,5 @@ class python::gunicorn::install( - $virtualenv, + $virtualenv = $python::gunicorn::virtualenv, ) { python::pip { 'gunicorn': From e90b5d0307a49ae64e33d90cea62f5b11f79dbda Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 30 Jan 2013 13:22:24 -0500 Subject: [PATCH 34/62] Move this up a level so we don't have to include yet another class and cause problems. --- manifests/gunicorn.pp | 6 +++++- manifests/gunicorn/install.pp | 10 ---------- 2 files changed, 5 insertions(+), 11 deletions(-) delete mode 100644 manifests/gunicorn/install.pp diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index 7af74fc2..9fd21f28 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -63,7 +63,6 @@ $wsgi_app = undef, ) { - include 'python::gunicorn::install' include 'edx::newrelic' file { "/etc/init/${name}.conf": @@ -84,4 +83,9 @@ subscribe => Class['edx::newrelic'], } + python::pip { 'gunicorn': + ensure => present, + virtualenv => $virtualenv, + } + } diff --git a/manifests/gunicorn/install.pp b/manifests/gunicorn/install.pp deleted file mode 100644 index 2686d091..00000000 --- a/manifests/gunicorn/install.pp +++ /dev/null @@ -1,10 +0,0 @@ -class python::gunicorn::install( - $virtualenv = $python::gunicorn::virtualenv, -) { - - python::pip { 'gunicorn': - ensure => present, - virtualenv => $virtualenv, - } - -} From 54eea726d5530831754823be7acab03bbbdd1d33 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 30 Jan 2013 13:29:26 -0500 Subject: [PATCH 35/62] Fix this require. --- manifests/gunicorn.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index 9fd21f28..654d4559 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -70,9 +70,9 @@ owner => 'root', group => 'root', mode => '0644', - require => Class['python::gunicorn::install'], notify => Service[$name], content => $upstart_template, + require => Python::Pip['gunicorn'], } service { $name: From e5eb9eb683893437ec0ce046e9623699322e2c78 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 30 Jan 2013 13:59:56 -0500 Subject: [PATCH 36/62] add back in reporting. --- manifests/gunicorn.pp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index 654d4559..7215f25c 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -64,6 +64,8 @@ ) { include 'edx::newrelic' + # Check if newrelic is needed. + $reporting = hiera('newrelic', false) file { "/etc/init/${name}.conf": ensure => file, From cceb0963ac090171f6870531345b08ec291ec7e6 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 30 Jan 2013 14:08:00 -0500 Subject: [PATCH 37/62] Try and force the scoping. --- templates/gunicorn/gunicorn.conf.erb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index bb876fd4..3aa55de3 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -35,9 +35,9 @@ setuid <%= scope.lookupvar('user') %> <% end -%> <% case scope.lookupvar('app_interface') when 'django' -%> -exec <% if scope.lookupvar('reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> +exec <% if scope.lookupvar('python::gunicorn::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> <% when 'wsgi' -%> -exec <% if scope.lookupvar('reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> +exec <% if scope.lookupvar('python::gunicorn::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> <% when 'python' -%> exec su - www-data -c '<%= scope.lookupvar('virtualenv') %>/bin/python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 2>&1' <% end -%> From 7a7195991a440de2f920053b4de1fdc5a8fca7b0 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Wed, 30 Jan 2013 14:15:27 -0500 Subject: [PATCH 38/62] Check edx::newrelic instead. Why not! --- manifests/gunicorn.pp | 2 -- templates/gunicorn/gunicorn.conf.erb | 4 ++-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index 7215f25c..654d4559 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -64,8 +64,6 @@ ) { include 'edx::newrelic' - # Check if newrelic is needed. - $reporting = hiera('newrelic', false) file { "/etc/init/${name}.conf": ensure => file, diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 3aa55de3..81a65612 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -35,9 +35,9 @@ setuid <%= scope.lookupvar('user') %> <% end -%> <% case scope.lookupvar('app_interface') when 'django' -%> -exec <% if scope.lookupvar('python::gunicorn::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> +exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> <% when 'wsgi' -%> -exec <% if scope.lookupvar('python::gunicorn::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> +exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> <% when 'python' -%> exec su - www-data -c '<%= scope.lookupvar('virtualenv') %>/bin/python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 2>&1' <% end -%> From 53f80c869dc532b13d8f352f7e6d3c4c2171e4b0 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 31 Jan 2013 13:10:56 -0500 Subject: [PATCH 39/62] Tweaks here to ensure that we only install gunicorn one time right now. --- manifests/gunicorn.pp | 5 ----- manifests/init.pp | 11 +++++++++++ 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index 654d4559..e595f2b1 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -83,9 +83,4 @@ subscribe => Class['edx::newrelic'], } - python::pip { 'gunicorn': - ensure => present, - virtualenv => $virtualenv, - } - } diff --git a/manifests/init.pp b/manifests/init.pp index c7ab10f2..d7533924 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -47,4 +47,15 @@ include python::install include python::config + # Move this to here so it gets installed a single time in the virtualenv. If + # we ever want to split into multiple venvs then this will move back to + # gunicorn.pp and we'll enhance python::pip to take arguments so the name + # can be unique and not cause clashes with multiple instances of the lms + # define. + python::pip { 'gunicorn': + ensure => present, + virtualenv => $virtualenv, + require => Class['python::config'], + } + } From 07b69ae970ec83d759e1afb427567f7b158b5cf6 Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 31 Jan 2013 13:14:30 -0500 Subject: [PATCH 40/62] Ensure we have a link between the gunicorn define and the top level python class so pip::install { 'gunicorn' } happens. --- manifests/gunicorn.pp | 1 + 1 file changed, 1 insertion(+) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index e595f2b1..f3b6b340 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -64,6 +64,7 @@ ) { include 'edx::newrelic' + include '::python' file { "/etc/init/${name}.conf": ensure => file, From ee434bd5fa2818f946274cc12ab5f6d2ff50471d Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 31 Jan 2013 13:24:14 -0500 Subject: [PATCH 41/62] OK, this turns out to be a true/false situation ($virtualenv) so lets make a new variable for this kludge. --- manifests/init.pp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index d7533924..3d580f20 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -52,9 +52,10 @@ # gunicorn.pp and we'll enhance python::pip to take arguments so the name # can be unique and not cause clashes with multiple instances of the lms # define. + $virtualenv_location = hiera(virtualenv_location, '/opt/edx') python::pip { 'gunicorn': ensure => present, - virtualenv => $virtualenv, + virtualenv => $virtualenv_location, require => Class['python::config'], } From b66a7a4eaaf46c829cad8816a4cb3ea4732475ce Mon Sep 17 00:00:00 2001 From: Ashley Penney Date: Thu, 31 Jan 2013 13:25:01 -0500 Subject: [PATCH 42/62] Make it a class param. --- manifests/init.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 3d580f20..51e1a2d6 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -33,6 +33,7 @@ $version = 'system', $dev = false, $virtualenv = false, + $virtualenv_location = '/opt/edx', $gunicorn = false ) { @@ -52,7 +53,6 @@ # gunicorn.pp and we'll enhance python::pip to take arguments so the name # can be unique and not cause clashes with multiple instances of the lms # define. - $virtualenv_location = hiera(virtualenv_location, '/opt/edx') python::pip { 'gunicorn': ensure => present, virtualenv => $virtualenv_location, From e03d8815760f0ad8e5bdf76aac7f79ff3d4d14f3 Mon Sep 17 00:00:00 2001 From: e0d Date: Fri, 1 Feb 2013 10:27:46 -0500 Subject: [PATCH 43/62] adding service variant --- templates/gunicorn/gunicorn.conf.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 81a65612..5362da35 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -22,6 +22,7 @@ env WORKERS=<%= 4 * scope.lookupvar('::processorcount').to_i %> env PORT=<%= scope.lookupvar('port') %> env LANG=en_US.UTF-8 env DJANGO_SETTINGS_MODULE=<%= scope.lookupvar('settings_module') %> +env SERVICE_VARIANT=${UPSTART_JOB} pre-start script <% pre_start_commands.each do |cmd| -%> From b7d6165ae1c54fafe218f46fea60eda5866e7487 Mon Sep 17 00:00:00 2001 From: e0d Date: Fri, 1 Feb 2013 14:33:24 -0500 Subject: [PATCH 44/62] changing the way the variant is set --- templates/gunicorn/gunicorn.conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 5362da35..63f7b77e 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -22,7 +22,7 @@ env WORKERS=<%= 4 * scope.lookupvar('::processorcount').to_i %> env PORT=<%= scope.lookupvar('port') %> env LANG=en_US.UTF-8 env DJANGO_SETTINGS_MODULE=<%= scope.lookupvar('settings_module') %> -env SERVICE_VARIANT=${UPSTART_JOB} +env SERVICE_VARIANT="<%= scope.lookupvar('title') %>" pre-start script <% pre_start_commands.each do |cmd| -%> From 6280eb50226c5d0301c7eecab7d613bcd1c4b22f Mon Sep 17 00:00:00 2001 From: e0d Date: Fri, 1 Feb 2013 14:56:21 -0500 Subject: [PATCH 45/62] making pid file actually do something --- templates/gunicorn/gunicorn.conf.erb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 63f7b77e..ef050054 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -36,9 +36,9 @@ setuid <%= scope.lookupvar('user') %> <% end -%> <% case scope.lookupvar('app_interface') when 'django' -%> -exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> +exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -p ${PID} -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> <% when 'wsgi' -%> -exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> +exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn -p ${PID} --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> <% when 'python' -%> -exec su - www-data -c '<%= scope.lookupvar('virtualenv') %>/bin/python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 2>&1' +exec su - www-data -c '<%= scope.lookupvar('virtualenv') %>/bin/python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 1>&1' <% end -%> From 0c808457503b5ed10d3feb4261f32a78b2142f85 Mon Sep 17 00:00:00 2001 From: e0d Date: Fri, 1 Feb 2013 14:59:37 -0500 Subject: [PATCH 46/62] fixing pid path --- templates/gunicorn/gunicorn.conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index ef050054..044c8015 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -11,7 +11,7 @@ respawn respawn limit 3 30 <% end -%> -env PID=/var/run/gunicorn/<%= name %>.pid +env PID=/var/run/<%= name %>.pid env NEW_RELIC_CONFIG_FILE=<%= scope.lookupvar('base') %>/newrelic.ini env NEWRELIC=<%= scope.lookupvar('virtualenv') %>/bin/newrelic-admin <% if scope.lookupvar('workers') -%> From 92d58cb8f2baf101f26e461bddc022b098d2553b Mon Sep 17 00:00:00 2001 From: e0d Date: Fri, 1 Feb 2013 15:07:14 -0500 Subject: [PATCH 47/62] fixing pid path --- templates/gunicorn/gunicorn.conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 044c8015..9322ad4c 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -11,7 +11,7 @@ respawn respawn limit 3 30 <% end -%> -env PID=/var/run/<%= name %>.pid +env PID=/var/tmp/<%= name %>.pid env NEW_RELIC_CONFIG_FILE=<%= scope.lookupvar('base') %>/newrelic.ini env NEWRELIC=<%= scope.lookupvar('virtualenv') %>/bin/newrelic-admin <% if scope.lookupvar('workers') -%> From 557f54e6c459e67399af808d3a0a049910661076 Mon Sep 17 00:00:00 2001 From: e0d Date: Fri, 1 Feb 2013 16:16:38 -0500 Subject: [PATCH 48/62] rolling out service variant changes until merge time. --- templates/gunicorn/gunicorn.conf.erb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 9322ad4c..8f5277ed 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -22,7 +22,6 @@ env WORKERS=<%= 4 * scope.lookupvar('::processorcount').to_i %> env PORT=<%= scope.lookupvar('port') %> env LANG=en_US.UTF-8 env DJANGO_SETTINGS_MODULE=<%= scope.lookupvar('settings_module') %> -env SERVICE_VARIANT="<%= scope.lookupvar('title') %>" pre-start script <% pre_start_commands.each do |cmd| -%> @@ -36,9 +35,9 @@ setuid <%= scope.lookupvar('user') %> <% end -%> <% case scope.lookupvar('app_interface') when 'django' -%> -exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -p ${PID} -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> +exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> <% when 'wsgi' -%> -exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn -p ${PID} --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> +exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> <% when 'python' -%> exec su - www-data -c '<%= scope.lookupvar('virtualenv') %>/bin/python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 1>&1' <% end -%> From 7dbd987de802ae423b2fe33993a7bb2947572432 Mon Sep 17 00:00:00 2001 From: e0d Date: Tue, 5 Feb 2013 22:23:33 -0500 Subject: [PATCH 49/62] reenableing the service variant, adding a switch for edx mode to gunicorn --- manifests/gunicorn.pp | 1 + templates/gunicorn/gunicorn.conf.erb | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index f3b6b340..1291bc95 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -61,6 +61,7 @@ $virtualenv = false, $workers = undef, $wsgi_app = undef, + $edxapp = false, ) { include 'edx::newrelic' diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 8f5277ed..7d0bd3af 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -3,8 +3,13 @@ description "gunicorn server" author "Calen Pennington " +<% if scope.lookupvar(edxapp) == false %> start on runlevel [2345] stop on runlevel [!2345] +<% else -%> +start on started edxapp +stop on stopped edxapp +<% end -%> respawn <% if scope.lookupvar('respawn_limit') != false -%> @@ -22,6 +27,7 @@ env WORKERS=<%= 4 * scope.lookupvar('::processorcount').to_i %> env PORT=<%= scope.lookupvar('port') %> env LANG=en_US.UTF-8 env DJANGO_SETTINGS_MODULE=<%= scope.lookupvar('settings_module') %> +env SERVICE_VARIANT="<%= scope.lookupvar('title') %>" pre-start script <% pre_start_commands.each do |cmd| -%> From 47d63d547fdee1884b125b7ea42fb460a8037459 Mon Sep 17 00:00:00 2001 From: e0d Date: Tue, 5 Feb 2013 22:57:42 -0500 Subject: [PATCH 50/62] fixed syntax error --- templates/gunicorn/gunicorn.conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 7d0bd3af..9196592c 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -3,7 +3,7 @@ description "gunicorn server" author "Calen Pennington " -<% if scope.lookupvar(edxapp) == false %> +<% if scope.lookupvar(edxapp) == false -%> start on runlevel [2345] stop on runlevel [!2345] <% else -%> From 0b76095fc870a1372a9da79df40a9484c4f26012 Mon Sep 17 00:00:00 2001 From: e0d Date: Tue, 5 Feb 2013 23:01:02 -0500 Subject: [PATCH 51/62] fixed different syntax error --- templates/gunicorn/gunicorn.conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 9196592c..034171d2 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -3,7 +3,7 @@ description "gunicorn server" author "Calen Pennington " -<% if scope.lookupvar(edxapp) == false -%> +<% if scope.lookupvar('edxapp') == false -%> start on runlevel [2345] stop on runlevel [!2345] <% else -%> From 145a0cb85ba5b84aa4b7fa8dac296c02e8d2bde8 Mon Sep 17 00:00:00 2001 From: e0d Date: Mon, 11 Feb 2013 07:24:42 -0500 Subject: [PATCH 52/62] quick fix for pre start commands, needs improvement --- manifests/gunicorn.pp | 1 + templates/gunicorn/gunicorn.conf.erb | 9 +++++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index 1291bc95..87e05322 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -62,6 +62,7 @@ $workers = undef, $wsgi_app = undef, $edxapp = false, + $stacked = false, ) { include 'edx::newrelic' diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 034171d2..f04ada38 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -3,7 +3,7 @@ description "gunicorn server" author "Calen Pennington " -<% if scope.lookupvar('edxapp') == false -%> +<% if scope.lookupvar('stacked') == false -%> start on runlevel [2345] stop on runlevel [!2345] <% else -%> @@ -29,11 +29,12 @@ env LANG=en_US.UTF-8 env DJANGO_SETTINGS_MODULE=<%= scope.lookupvar('settings_module') %> env SERVICE_VARIANT="<%= scope.lookupvar('title') %>" +<% if scope.lookupvar('stacked') == false -%> pre-start script -<% pre_start_commands.each do |cmd| -%> - <%= cmd %> -<% end -%> + find ${package_root} -user ${user} -type f -name '*.pyc' -delete || true + find /tmp -user ${user} -type d -name tmp*mako -exec rm -rf {} \\; || true end script +<% end -%> chdir <%= scope.lookupvar('package_root') %> <% if scope.lookupvar('app_interface') != 'python' -%> From 2e25814296238a8254cb8aa229c0bfa80091e166 Mon Sep 17 00:00:00 2001 From: e0d Date: Fri, 22 Feb 2013 13:41:56 -0500 Subject: [PATCH 53/62] adding default --- manifests/gunicorn.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index 87e05322..ad00033a 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -41,7 +41,7 @@ # Sergey Stankevich # define python::gunicorn ( - $reporting, + $reporting = false, $app_interface = 'django', $base = '/opt/wwc', $bind = false, From 226252eef485baf1ccb42fd1c2fd023eeb964597 Mon Sep 17 00:00:00 2001 From: e0d Date: Tue, 5 Mar 2013 21:21:32 -0500 Subject: [PATCH 54/62] refactoring to support waiting for child services --- templates/gunicorn/gunicorn.conf.erb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index f04ada38..1a2ea511 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -48,3 +48,16 @@ exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run- <% when 'python' -%> exec su - www-data -c '<%= scope.lookupvar('virtualenv') %>/bin/python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 1>&1' <% end -%> + +<% if (scope.lookupvar('stacked') == true) && (scope.lookupvar('title') != 'cms') -%> +post-start script + while true + do + if $(curl -s -i localhost:$PORT/heartbeat | egrep -q '200 OK'); then + break; + else + sleep 1; + fi + done +end script +<% end -%> \ No newline at end of file From c353a22836211ca022df20c6599996e1c0cf4b3f Mon Sep 17 00:00:00 2001 From: e0d Date: Tue, 5 Mar 2013 22:01:14 -0500 Subject: [PATCH 55/62] applying even when unstacked. --- templates/gunicorn/gunicorn.conf.erb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 1a2ea511..3f3021cd 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -49,7 +49,10 @@ exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run- exec su - www-data -c '<%= scope.lookupvar('virtualenv') %>/bin/python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 1>&1' <% end -%> -<% if (scope.lookupvar('stacked') == true) && (scope.lookupvar('title') != 'cms') -%> +## +## cms needs a heartbeat +## +<% if (scope.lookupvar('title') != 'cms') -%> post-start script while true do From 59234edecce7165af06f707ba19b6357b6d0c9c4 Mon Sep 17 00:00:00 2001 From: e0d Date: Tue, 5 Mar 2013 22:22:22 -0500 Subject: [PATCH 56/62] making more explicit to deal with other service using this template. --- templates/gunicorn/gunicorn.conf.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 3f3021cd..526cf795 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -52,7 +52,7 @@ exec su - www-data -c '<%= scope.lookupvar('virtualenv') %>/bin/python <%= scope ## ## cms needs a heartbeat ## -<% if (scope.lookupvar('title') != 'cms') -%> +<% if (scope.lookupvar('title') == 'lms-xml') || (scope.lookupvar('title') == 'lms') || (scope.lookupvar('title') == 'lms-preview') -%> post-start script while true do From 1cbc3a2198a2d819a62fd1687840de03795941ec Mon Sep 17 00:00:00 2001 From: e0d Date: Tue, 5 Mar 2013 22:31:13 -0500 Subject: [PATCH 57/62] Removing dangling comment. --- templates/gunicorn/gunicorn.conf.erb | 3 --- 1 file changed, 3 deletions(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 526cf795..c5ea92e4 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -49,9 +49,6 @@ exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run- exec su - www-data -c '<%= scope.lookupvar('virtualenv') %>/bin/python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 1>&1' <% end -%> -## -## cms needs a heartbeat -## <% if (scope.lookupvar('title') == 'lms-xml') || (scope.lookupvar('title') == 'lms') || (scope.lookupvar('title') == 'lms-preview') -%> post-start script while true From 850b24e0f0c729156e7d553382d7208f6a488614 Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Tue, 2 Apr 2013 15:24:19 -0400 Subject: [PATCH 58/62] adding amazon as an acceptable OS --- manifests/init.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/init.pp b/manifests/init.pp index 51e1a2d6..8d0768ae 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -38,7 +38,7 @@ ) { # Module compatibility check - $compatible = [ 'Debian', 'Ubuntu' ] + $compatible = [ 'Debian', 'Ubuntu', 'Amazon' ] if ! ($::operatingsystem in $compatible) { fail("Module is not compatible with ${::operatingsystem}") } From 323278f8c1afd7fe701f3f437f15cfd4afd33666 Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Mon, 8 Jul 2013 13:13:46 -0400 Subject: [PATCH 59/62] upgrade pip before distribute --- manifests/virtualenv.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/virtualenv.pp b/manifests/virtualenv.pp index ebb9834d..0b6b5aa0 100644 --- a/manifests/virtualenv.pp +++ b/manifests/virtualenv.pp @@ -59,7 +59,7 @@ command => "mkdir -p ${venv_dir} \ ${proxy_command} \ && virtualenv -p `/bin/which ${python}` ${venv_dir} \ - && ${venv_dir}/bin/pip install ${proxy_flag} --upgrade distribute pip", + && ${venv_dir}/bin/pip install ${proxy_flag} --upgrade pip distribute", creates => $venv_dir, } From 0cb481c0bbeecd612b2af760f05786a0c17875c5 Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Mon, 8 Jul 2013 18:03:45 -0400 Subject: [PATCH 60/62] adding distribute to virtualenv --- manifests/virtualenv.pp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/manifests/virtualenv.pp b/manifests/virtualenv.pp index 0b6b5aa0..b8811c1d 100644 --- a/manifests/virtualenv.pp +++ b/manifests/virtualenv.pp @@ -58,7 +58,7 @@ exec { "python_virtualenv_${venv_dir}": command => "mkdir -p ${venv_dir} \ ${proxy_command} \ - && virtualenv -p `/bin/which ${python}` ${venv_dir} \ + && virtualenv -p `/bin/which ${python}` ${venv_dir} --distribute \ && ${venv_dir}/bin/pip install ${proxy_flag} --upgrade pip distribute", creates => $venv_dir, } From 0f497da03b1911dc4230a504e93d12db59495bb5 Mon Sep 17 00:00:00 2001 From: Feanil Patel Date: Fri, 13 Sep 2013 09:02:50 -0400 Subject: [PATCH 61/62] Don't start lms-xml when edxapp starts. --- templates/gunicorn/gunicorn.conf.erb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index c5ea92e4..40c01602 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -7,7 +7,9 @@ author "Calen Pennington " start on runlevel [2345] stop on runlevel [!2345] <% else -%> +<% if scope.lookupvar('title') != 'lms-xml' -%> start on started edxapp +<% end -%> stop on stopped edxapp <% end -%> @@ -60,4 +62,4 @@ post-start script fi done end script -<% end -%> \ No newline at end of file +<% end -%> From eee6963b7b7bae574c71d4ddd842d752b7a8bd28 Mon Sep 17 00:00:00 2001 From: John Jarvis Date: Tue, 12 Nov 2013 13:49:35 -0500 Subject: [PATCH 62/62] adding max_requests to gunicorn --- manifests/gunicorn.pp | 1 + templates/gunicorn/gunicorn.conf.erb | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/manifests/gunicorn.pp b/manifests/gunicorn.pp index ad00033a..82330914 100644 --- a/manifests/gunicorn.pp +++ b/manifests/gunicorn.pp @@ -57,6 +57,7 @@ $settings_module = undef, $timeout = '30', $upstart_template = template('python/gunicorn/gunicorn.conf.erb'), + $max_requests = 0, $user = 'www-data', $virtualenv = false, $workers = undef, diff --git a/templates/gunicorn/gunicorn.conf.erb b/templates/gunicorn/gunicorn.conf.erb index 40c01602..e7ecebd2 100644 --- a/templates/gunicorn/gunicorn.conf.erb +++ b/templates/gunicorn/gunicorn.conf.erb @@ -44,9 +44,9 @@ setuid <%= scope.lookupvar('user') %> <% end -%> <% case scope.lookupvar('app_interface') when 'django' -%> -exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> +exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn_django --max-requests <%= scope.lookupvar('max_requests') %> -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> --settings=<%= scope.lookupvar('settings_module') %> <% when 'wsgi' -%> -exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> +exec <% if scope.lookupvar('edx::newrelic::reporting') == true -%>$NEWRELIC run-program <% end -%><%= scope.lookupvar('virtualenv') %>/bin/gunicorn --max-requests <%= scope.lookupvar('max_requests') %> --preload -b 127.0.0.1:$PORT -w $WORKERS --timeout=<%= scope.lookupvar('timeout') %> --pythonpath=<%= scope.lookupvar('package_root') %> <%= scope.lookupvar('wsgi_app') %> <% when 'python' -%> exec su - www-data -c '<%= scope.lookupvar('virtualenv') %>/bin/python <%= scope.lookupvar('package_root') %>/<%= scope.lookupvar('script_name') %> >/dev/null 1>&1' <% end -%>