Defined Type: python::gunicorn

Defined in:
manifests/gunicorn.pp

Summary

Manages Gunicorn virtual hosts.

Overview

Examples:

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',
}

Parameters:

  • ensure (Enum['present', 'absent']) (defaults to: present)
  • config_dir (Stdlib::Absolutepath) (defaults to: '/etc/gunicorn.d')

    Configure the gunicorn config directory path.

  • manage_config_dir (Boolean) (defaults to: false)

    Set if the gunicorn config directory should be created.

  • virtualenv (Variant[Boolean,Stdlib::Absolutepath]) (defaults to: false)

    Run in virtualenv, specify directory.

  • mode (Enum['wsgi', 'django']) (defaults to: 'wsgi')

    Gunicorn mode.

  • dir (Stdlib::Absolutepath)

    Application directory.

  • bind (Variant[String[1],Boolean]) (defaults to: false)

    Bind on: ‘HOST’, ‘HOST:PORT’, ‘unix:PATH’. Default: system-wide: unix:/tmp/gunicorn-$name.socket

    virtualenv:  unix:${virtualenv}/${name}.socket
    
  • environment (Variant[String[1],Boolean]) (defaults to: false)

    Set ENVIRONMENT variable.

  • appmodule (String[1]) (defaults to: 'app:app')

    Set the application module name for gunicorn to load when not using Django.

  • osenv (Variant[Boolean,Hash]) (defaults to: false)

    Allows setting environment variables for the gunicorn service. Accepts a hash of ‘key’: ‘value’ pairs.

  • timeout (Integer) (defaults to: 30)

    Allows setting the gunicorn idle worker process time before being killed. The unit of time is seconds.

  • template (String[1]) (defaults to: 'python/gunicorn.erb')

    Which ERB template to use.

  • args (Array) (defaults to: [])

    Custom arguments to add in gunicorn config file.

  • owner (String[1]) (defaults to: 'www-data')
  • group (String[1]) (defaults to: 'www-data')
  • workers (Variant[Boolean,Integer]) (defaults to: false)
  • access_log_format (Variant[Boolean,String[1]]) (defaults to: false)
  • accesslog (Variant[Boolean,Stdlib::Absolutepath]) (defaults to: false)
  • errorlog (Variant[Boolean,Stdlib::Absolutepath]) (defaults to: false)
  • log_level (Python::Loglevel) (defaults to: 'error')


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
# File 'manifests/gunicorn.pp', line 36

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),
    }
  }
}