application()
function at wsgi/application
you instead provide the application()
function at app.py
. This file will be used directly by all the available servers.
22 |
23 | By default **wsgiref** is used so a working environment can be provided immediately. This is easily changed by setting the OPENSHIFT_PYTHON_SERVER
environment variable and then restarting or redeploying the app.
24 |
25 | rhc env set OPENSHIFT_PYTHON_SERVER=gunicorn
26 | rhc app restart
27 |
28 | Be aware, however, that restarting/redeploying after changing servers for the first time might take a fair amount of time. This is because the server packages get compiled and installed on an as needed basis. Gevent and Gunicorn (which is configured to use gevent as its workers), for example, needs to be compiled within the app as OpenShift doesn't provide it as a system level package.
29 |
30 |
31 | ### Supported servers
32 |
33 | - wsgiref
34 | - gevent
35 | - gunicorn
36 |
37 |
38 | ### Configuration
39 |
40 | There is little to no configuration required as most of the details lay in the interaction between Nginx and the WSGI server package. All that is required is to define the application()
function in app.py
.
41 | Any configuration for the server package will be exposed via environment variables.
42 |
43 | #### Environment Variables
44 |
45 | OPENSHIFT_PYTHON_WORKERS
- The number of workers to spawn for packages like gunicorn.
46 | Default: number of CPUs * 2 + 1
47 |
48 |
49 | ### Static files
50 |
51 | Static files will be served from the public/
directory. These files will be served directly by Nginx.
52 |
53 |
54 | ### Web Sockets
55 |
56 | Web socket support is enabled in Nginx, however it does little more than passing the requests through with the appropriate upgrade headers. More complex websocket environments will need to go for the customised nginx.conf
option.
57 |
58 | In the future there might be a nicer way to support websockets as a completely separate server. For example, the application might be served out by gunicorn, but websocket services served out with twisted or tornado. These are purely thoughts at the moment however.
59 |
60 |
61 | ### Custom nginx.conf
62 |
63 | Like the standalone Nginx cartridge, its possible to provide your own server configuration to be included in the main nginx.conf
file. A sample is provided in the cloned repo as nginx.conf.erb.sample
. Simply remove the .sample suffix and commit the changes.nginx.conf.erb
will be processed and included in the main configuration every time the server starts.
64 |
--------------------------------------------------------------------------------
/bin/control:
--------------------------------------------------------------------------------
1 | #!/bin/bash -e
2 |
3 | source $OPENSHIFT_CARTRIDGE_SDK_BASH
4 |
5 |
6 | NGINX_DIR=$OPENSHIFT_ADVANCED_PYTHON_DIR/usr/nginx/versions/$NGINX_VERSION
7 | PYTHON_DIR=$OPENSHIFT_ADVANCED_PYTHON_DIR/usr/python/versions/$OPENSHIFT_ADVANCED_PYTHON_VERSION
8 |
9 |
10 | case $1 in
11 | update-configuration)
12 | source $PYTHON_DIR/lib/update-configuration
13 | update-configuration $PYTHON_VERSION
14 | ;;
15 | stop)
16 | $NGINX_DIR/bin/control "$@"
17 | $PYTHON_DIR/bin/control "$@"
18 | ;;
19 | restart)
20 | $NGINX_DIR/bin/control "stop"
21 | $PYTHON_DIR/bin/control "stop"
22 | $PYTHON_DIR/bin/control "start"
23 | $NGINX_DIR/bin/control "start"
24 | ;;
25 | *)
26 | $PYTHON_DIR/bin/control "$@"
27 | $NGINX_DIR/bin/control "$@"
28 | ;;
29 | esac
--------------------------------------------------------------------------------
/bin/install:
--------------------------------------------------------------------------------
1 | #!/bin/bash -eu
2 |
3 | source $OPENSHIFT_CARTRIDGE_SDK_BASH
4 |
5 | case "$1" in
6 | -v|--version)
7 | version="$2"
8 | esac
9 |
10 |
11 | echo "$version" > env/OPENSHIFT_ADVANCED_PYTHON_VERSION
12 | echo "1.4" > env/NGINX_VERSION
13 |
14 |
15 | for dir in logs run; do
16 | mkdir -p $dir
17 | done
18 |
19 | # Call the version specific install script
20 | exec $OPENSHIFT_ADVANCED_PYTHON_DIR/usr/python/versions/$version/bin/install $version
--------------------------------------------------------------------------------
/bin/setup:
--------------------------------------------------------------------------------
1 | #!/bin/bash -eu
2 |
3 | source $OPENSHIFT_CARTRIDGE_SDK_BASH
4 |
5 | case "$1" in
6 | -v|--version)
7 | version="$2"
8 | esac
9 |
10 | # Update environment
11 | source $OPENSHIFT_ADVANCED_PYTHON_DIR/usr/python/versions/$version/lib/update-configuration
12 | update-configuration
13 |
14 | # Call the version specific setup script
15 | exec $OPENSHIFT_ADVANCED_PYTHON_DIR/usr/python/versions/$version/bin/setup $version
--------------------------------------------------------------------------------
/bin/upgrade:
--------------------------------------------------------------------------------
1 | #!/bin/bash -eu
2 |
3 | python_version="$1"
4 |
5 | upgrade_script="$OPENSHIFT_ADVANCED_PYTHON_DIR/usr/python/versions/$python_version/bin/upgrade"
6 |
7 |
8 | if [ -e "$upgrade_script" ]
9 | then
10 | exec "$upgrade_script" "$@"
11 | fi
12 |
13 | exit 0
14 |
--------------------------------------------------------------------------------
/conf/gunicorn.py:
--------------------------------------------------------------------------------
1 | import os
2 | import multiprocessing
3 |
4 | cart_dir = os.environ["OPENSHIFT_ADVANCED_PYTHON_DIR"]
5 | tmp_dir = os.environ["OPENSHIFT_TMP_DIR"]
6 |
7 |
8 | if os.environ.has_key("OPENSHIFT_PYTHON_WORKERS"):
9 | workers = os.environ["OPENSHIFT_PYTHON_WORKERS"]
10 | else:
11 | workers = multiprocessing.cpu_count() * 2 + 1
12 |
13 |
14 | worker_class = "gevent"
15 | daemon = True
16 | bind = "unix:{0}run/appserver.sock".format(cart_dir)
17 | pidfile = "{0}run/appserver.pid".format(cart_dir)
18 |
19 | accesslog = "{0}logs/appserver.access.log".format(cart_dir)
20 | errorlog = "{0}logs/appserver.error.log".format(cart_dir)
21 |
22 | worker_tmp_dir = "{0}".format(tmp_dir)
23 | tmp_upload_dir = "{0}".format(tmp_dir)
--------------------------------------------------------------------------------
/conf/mime.types:
--------------------------------------------------------------------------------
1 |
2 | types {
3 | text/html html htm shtml;
4 | text/css css;
5 | text/xml xml;
6 | image/gif gif;
7 | image/jpeg jpeg jpg;
8 | application/x-javascript js;
9 | application/atom+xml atom;
10 | application/rss+xml rss;
11 |
12 | text/mathml mml;
13 | text/plain txt;
14 | text/vnd.sun.j2me.app-descriptor jad;
15 | text/vnd.wap.wml wml;
16 | text/x-component htc;
17 |
18 | image/png png;
19 | image/tiff tif tiff;
20 | image/vnd.wap.wbmp wbmp;
21 | image/x-icon ico;
22 | image/x-jng jng;
23 | image/x-ms-bmp bmp;
24 | image/svg+xml svg svgz;
25 | image/webp webp;
26 |
27 | application/java-archive jar war ear;
28 | application/mac-binhex40 hqx;
29 | application/msword doc;
30 | application/pdf pdf;
31 | application/postscript ps eps ai;
32 | application/rtf rtf;
33 | application/vnd.ms-excel xls;
34 | application/vnd.ms-powerpoint ppt;
35 | application/vnd.wap.wmlc wmlc;
36 | application/vnd.google-earth.kml+xml kml;
37 | application/vnd.google-earth.kmz kmz;
38 | application/x-7z-compressed 7z;
39 | application/x-cocoa cco;
40 | application/x-java-archive-diff jardiff;
41 | application/x-java-jnlp-file jnlp;
42 | application/x-makeself run;
43 | application/x-perl pl pm;
44 | application/x-pilot prc pdb;
45 | application/x-rar-compressed rar;
46 | application/x-redhat-package-manager rpm;
47 | application/x-sea sea;
48 | application/x-shockwave-flash swf;
49 | application/x-stuffit sit;
50 | application/x-tcl tcl tk;
51 | application/x-x509-ca-cert der pem crt;
52 | application/x-xpinstall xpi;
53 | application/xhtml+xml xhtml;
54 | application/zip zip;
55 |
56 | application/octet-stream bin exe dll;
57 | application/octet-stream deb;
58 | application/octet-stream dmg;
59 | application/octet-stream eot;
60 | application/octet-stream iso img;
61 | application/octet-stream msi msp msm;
62 |
63 | audio/midi mid midi kar;
64 | audio/mpeg mp3;
65 | audio/ogg ogg;
66 | audio/x-m4a m4a;
67 | audio/x-realaudio ra;
68 |
69 | video/3gpp 3gpp 3gp;
70 | video/mp4 mp4;
71 | video/mpeg mpeg mpg;
72 | video/quicktime mov;
73 | video/webm webm;
74 | video/x-flv flv;
75 | video/x-m4v m4v;
76 | video/x-mng mng;
77 | video/x-ms-asf asx asf;
78 | video/x-ms-wmv wmv;
79 | video/x-msvideo avi;
80 | }
81 |
--------------------------------------------------------------------------------
/env/PYTHON_EGG_CACHE.erb:
--------------------------------------------------------------------------------
1 | <%= ENV['OPENSHIFT_ADVANCED_PYTHON_DIR'] %>virtenv/.python-eggs/
2 |
--------------------------------------------------------------------------------
/lib/util:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 | # Utility functions for use in the cartridge scripts.
3 |
4 | function parse_args {
5 | while :
6 | do
7 | case $1 in
8 | -h | --help | -\?)
9 | echo "usage: $0 [--version[=]OpenShift uses the Git version control system for your source code, and grants you access to it via the Secure Shell (SSH) protocol. In order to upload and download code to your application you need to give us your public SSH key. You can upload it within the web console or install the RHC command line tool and run rhc setup
to generate and upload your key automatically.
If you created your application from the command line and uploaded your SSH key, rhc will automatically download a copy of that source code repository (Git calls this 'cloning') to your local system.
236 | 237 |If you created the application from the web console, you'll need to manually clone the repository to your local system. Copy the application's source code Git URL and then run:
238 | 239 |$ git clone <git_url> <directory_to_create> 240 | 241 | # Within your project directory 242 | # Commit your changes and push to OpenShift 243 | 244 | $ git commit -a -m 'Some commit message' 245 | $ git push246 |
You can use the OpenShift web console to enable additional capabilities via cartridges, add collaborator access authorizations, designate custom domain aliases, and manage domain memberships.
261 | 262 |Installing the OpenShift RHC client tools allows you complete control of your cloud environment. Read more on how to manage your application from the command line in our User Guide. 264 |
265 | 266 |