~verterok/charms/xenial/gunicorn/set-env-systemd

« back to all changes in this revision

Viewing changes to hooks/wsgi-file-relation-joined

  • Committer: Juan L. Negron
  • Date: 2012-09-14 20:03:09 UTC
  • mfrom: (21.1.2 gunicorn)
  • Revision ID: juan.negron@canonical.com-20120914200309-bum9apt7z0wp5h08
Added support for running gunicorn in django mode in addition to wsgi. Also allow pythonpath to be explicitly set and additional environment variables to be specified.  MP:123481

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
    exit 0 # wait for future handshake
10
10
fi
11
11
 
12
 
variables="wsgi_wsgi_file wsgi_workers wsgi_worker_class wsgi_worker_connections wsgi_max_requests wsgi_timeout wsgi_backlog wsgi_keep_alive wsgi_extra wsgi_user wsgi_group wsgi_umask wsgi_log_file wsgi_log_level wsgi_access_logfile wsgi_access_logformat"
 
12
variables="wsgi_wsgi_file wsgi_workers wsgi_worker_class wsgi_worker_connections wsgi_max_requests wsgi_timeout wsgi_backlog wsgi_keep_alive wsgi_extra wsgi_user wsgi_group wsgi_umask wsgi_log_file wsgi_log_level wsgi_access_logfile wsgi_access_logformat env_extra django_settings python_path"
 
13
 
 
14
if [[ $JUJU_RELATION_ID =~ django.* ]]; then
 
15
    mode=django
 
16
elif [[ $JUJU_RELATION_ID =~ wsgi.* ]]; then
 
17
    mode=wsgi
 
18
else
 
19
    juju-log "Unknown mode ($JUJU_RELATION_ID)"
 
20
    exit 1
 
21
fi
 
22
 
 
23
juju-log "Running in ${mode} mode"
 
24
 
13
25
 
14
26
declare -A VAR
15
27
for v in $variables;do
26
38
    error_logfile="${working_dir}/gunicorn.log"
27
39
fi
28
40
 
 
41
if [ -n "$VAR[django_settings]" ] ; then
 
42
    django_settings="'django_settings': '${VAR[django_settings]}',"
 
43
fi
 
44
 
 
45
# If running in wsgi mode then set a default wsgi file
 
46
if [[ $mode -eq "wsgi" ]] && [[ $(relation-get $wsgi_wsgi_file) -eq "" ]] ; then
 
47
    ${VAR[wsgi_wsgi_file]}="wsgi"
 
48
fi
 
49
 
 
50
if [[ -n $wsgi_wsgi_file ]] ; then
 
51
    wsgi_wsgi_file="'${VAR[wsgi_wsgi_file]}',"
 
52
fi
 
53
 
 
54
if [[ -z ${VAR[python_path]} ]] ; then
 
55
    python_path=${working_dir}
 
56
else
 
57
    python_path=${VAR[python_path]}
 
58
fi
29
59
 
30
60
PORT=8080
31
61
quit=0
43
73
 
44
74
cat > /etc/gunicorn.d/${unit_name}.conf <<EOF
45
75
CONFIG = {
46
 
    'mode': 'wsgi',
 
76
    'mode': '${mode}',
47
77
    'environment': {
48
 
        'PYTHONPATH': '${working_dir}',
 
78
        'PYTHONPATH': '${python_path}',
 
79
        ${VAR[env_extra]}
49
80
    },
 
81
    ${django_settings}
50
82
    'working_dir': '${working_dir}',
51
83
    'user': '${VAR[wsgi_user]}',
52
84
    'group': '${VAR[wsgi_group]}',
66
98
        '--access-logfile=${VAR[wsgi_access_logfile]}',
67
99
        '--access-logformat=${VAR[wsgi_access_logformat]}',
68
100
        ${VAR[wsgi_extra]}
69
 
        '${VAR[wsgi_wsgi_file]}',
 
101
        ${wsgi_wsgi_file}
70
102
    ),
71
103
}
72
104
EOF