forked from voxpupuli/puppet-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgunicorn.pp
More file actions
83 lines (82 loc) · 3.44 KB
/
gunicorn.pp
File metadata and controls
83 lines (82 loc) · 3.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#
# @summary Manages Gunicorn virtual hosts.
#
# @param ensure
# @param config_dir Configure the gunicorn config directory path.
# @param manage_config_dir Set if the gunicorn config directory should be created.
# @param virtualenv Run in virtualenv, specify directory.
# @param mode Gunicorn mode.
# @param dir Application directory.
# @param bind Bind on: 'HOST', 'HOST:PORT', 'unix:PATH'.
# Default: system-wide: unix:/tmp/gunicorn-$name.socket
# virtualenv: unix:${virtualenv}/${name}.socket
# @param environment Set ENVIRONMENT variable.
# @param appmodule Set the application module name for gunicorn to load when not using Django.
# @param osenv Allows setting environment variables for the gunicorn service. Accepts a hash of 'key': 'value' pairs.
# @param timeout Allows setting the gunicorn idle worker process time before being killed. The unit of time is seconds.
# @param template Which ERB template to use.
# @param args Custom arguments to add in gunicorn config file.
#
# @example run gunicorn on vhost in virtualenv /var/www/project1
# python::gunicorn { 'vhost':
# ensure => present,
# virtualenv => '/var/www/project1',
# mode => 'wsgi',
# dir => '/var/www/project1/current',
# bind => 'unix:/tmp/gunicorn.socket',
# environment => 'prod',
# owner => 'www-data',
# group => 'www-data',
# appmodule => 'app:app',
# osenv => { 'DBHOST' => 'dbserver.example.com' },
# timeout => 30,
# template => 'python/gunicorn.erb',
# }
#
define python::gunicorn (
Stdlib::Absolutepath $dir,
Enum['present', 'absent'] $ensure = present,
Stdlib::Absolutepath $config_dir = '/etc/gunicorn.d',
Boolean $manage_config_dir = false,
Variant[Boolean,Stdlib::Absolutepath] $virtualenv = false,
Enum['wsgi', 'django'] $mode = 'wsgi',
Variant[String[1],Boolean] $bind = false,
Variant[String[1],Boolean] $environment = false,
String[1] $owner = 'www-data',
String[1] $group = 'www-data',
String[1] $appmodule = 'app:app',
Variant[Boolean,Hash] $osenv = false,
Integer $timeout = 30,
Variant[Boolean,Integer] $workers = false,
Variant[Boolean,String[1]] $access_log_format = false,
Variant[Boolean,Stdlib::Absolutepath] $accesslog = false,
Variant[Boolean,Stdlib::Absolutepath] $errorlog = false,
Python::Loglevel $log_level = 'error',
String[1] $template = 'python/gunicorn.erb',
Array $args = [],
) {
if $manage_config_dir {
file { $config_dir:
ensure => directory,
mode => '0755',
owner => 'root',
group => 'root',
}
file { "${config_dir}/${name}":
ensure => $ensure,
mode => '0644',
owner => 'root',
group => 'root',
content => template($template),
require => File[$config_dir],
}
} else {
file { "${config_dir}/${name}":
ensure => $ensure,
mode => '0644',
owner => 'root',
group => 'root',
content => template($template),
}
}
}