Skip to content

Commit 57df10f

Browse files
committed
Creating gunicorn config file by default
1 parent 3f7b605 commit 57df10f

File tree

2 files changed

+60
-4
lines changed

2 files changed

+60
-4
lines changed

manifests/django.pp

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11

22
define appdeploy::django (
33
$user,
4-
$ip = '127.0.0.1',
5-
$port = 8001,
64
$environment = undef,
75
$celery = false,
86
$proxy = true,
97
$proxy_hosts = [],
108
$directory = "/home/$user/$title/src",
11-
$gunicorn_cfg = "$title/gunicorn.conf.py",
129
$vhost_cfg_append = undef,
10+
$gunicorn = {
11+
workers => 'auto',
12+
worker_class => 'eventlet',
13+
loglevel => 'error',
14+
bind => '127.0.0.1:8001',
15+
errorlog => "~/$title.log",
16+
},
17+
18+
# Deprecated params
19+
$ip = undef,
20+
$port = undef,
21+
$gunicorn_cfg = undef,
1322
) {
1423
include supervisor
1524

@@ -24,11 +33,40 @@
2433
environment => $environment,
2534
}
2635

36+
validate_hash($gunicorn)
37+
2738
$virtualenv_path = "/home/$user/.virtualenvs/$title"
2839
$manage_path = "$virtualenv_path/bin/python $directory/manage.py"
2940

41+
$default_gunicorn_cfg_path = "/etc/gunicorn-$title.conf.py"
42+
43+
$gunicorn_cfg_path = pick($gunicorn_cfg, '/etc/gunicorn-$title.conf.py')
44+
if $gunicorn_cfg {
45+
warning('Passing "gunicorn_cfg" to appdeploy::django is deprecated; please use the gunicorn parameter instead.')
46+
$gunicorn_cfg_path = $gunicorn_cfg
47+
48+
} else {
49+
$gunicorn_cfg_path = $default_gunicorn_cfg_path
50+
51+
file { "$title-gunicorn-config":
52+
path => $gunicorn_cfg_path,
53+
content => template("appdeploy/django/gunicorn.conf.py.erb"),
54+
before => Supervisor::App[$title],
55+
}
56+
}
57+
58+
if $ip or $port {
59+
# IP and Port should be set using $gunicorn hash map
60+
warning('Passing "ip" and/or "port" to appdeploy::django is deprecated; please use gunicorn["bind"] parameter instead.')
61+
$port_ = pick($port, '8001')
62+
$ip_ = pick($ip, '127.0.0.1')
63+
$app_cmd = "$virtualenv_path/bin/gunicorn $title.wsgi:application --bind=$ip_:$port_ --config=$gunicorn_cfg_path"
64+
} else {
65+
$app_cmd = "$virtualenv_path/bin/gunicorn $title.wsgi:application --config=$gunicorn_cfg_path"
66+
}
67+
3068
supervisor::app { $title:
31-
command => "$virtualenv_path/bin/gunicorn $title.wsgi:application --bind=$ip:$port --config=$gunicorn_cfg",
69+
command => $app_cmd,
3270
}
3371

3472
if $celery {

templates/django/gunicorn.conf.py.erb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## DO NOT CHANGE MANUALLY!
2+
## Puppet generated file
3+
4+
import os
5+
6+
<%- @gunicorn.each_pair do |key,value| -%>
7+
<%- if key == 'workers' && value == 'auto' -%>
8+
import multiprocessing
9+
workers = multiprocessing.cpu_count() * 2 + 1
10+
<%- elsif key == 'errorlog' -%>
11+
errorlog = os.path.expanduser('<%= value %>')
12+
if not os.path.exists(errorlog):
13+
open(errorlog, 'a').close() # touch
14+
<%- elsif key == 'bind' && (@ip || @port) -%>
15+
<%- else -%>
16+
<%= key %> = '<%= value %>'
17+
<%- end %>
18+
<%- end -%>

0 commit comments

Comments
 (0)