Created
September 13, 2011 17:17
-
-
Save bkeating/1214381 to your computer and use it in GitHub Desktop.
An example of my Upstart script that can start/stop a Django project.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# PROJECT_NAME.conf - run PROJECT_NAME gunicorninstances | |
# | |
# This runs gunicorn_django for PROJECT_NAME; to install: | |
# * sudo ln -s <this file> /etc/init/PROJECT_NAME.conf | |
# * sudo initctl reload-configuration | |
# to use: | |
# * sudo start/stop/restart/reload/status PROJECT_NAME | |
# | |
# For a full list of configuration options: http://gunicorn.org/configure.html | |
description "PROJECT_NAME Gunicorn instance" # Description of the job. | |
author "Ben Keating <[email protected]>" # Author of the job file. | |
version "0.0.1" # Version of the job file. | |
start on runlevel [2345] # say when to start the job | |
stop on runlevel [!2345] # say when to stop the job | |
# Time to wait between sending TERM and KILL signals | |
kill timeout 5 | |
# The respawn flag means that the process will be restarted if ended unexpectedly. | |
respawn | |
# Set environment variables of the job processes | |
env VENV="/home/django/.virtualenvs/PROJECT_NAME" # Path to projects virtualenv. | |
env HOME="/home/django/projects/PROJECT_NAME" # Path to project itself. | |
# The socket to bind. | |
# | |
# A string of the form: 'HOST', 'HOST:PORT', 'unix:PATH'. An IP is a valid HOST. | |
# Default: 127.0.0.1:8000. Note: unix:PATH is better! | |
env SOCKET="127.0.0.1:9000" | |
# Process Naming - A base to use with setproctitle for process naming. | |
# | |
# This affects things like ps and top. If you're going to be running more than | |
# one instance of Gunicorn you'll probably want to set a name to tell them | |
# apart. This requires that you install the setproctitle module. | |
# Default: 'gunicorn' | |
env NAME="gunicorn_PROJECT_NAME" | |
# The granularity of log outputs. | |
# | |
# Valid level names are: | |
# debug | |
# info (default) | |
# warning | |
# error | |
# critical | |
env LOGLEVEL="info" | |
# Specify main command as a shell script instead of a single-line command. Alternative to exec, can't be used together with it. | |
script | |
exec sudo -u django \ | |
$VENV/bin/gunicorn_django \ | |
--preload \ | |
--workers 3 \ | |
--timeout 60 \ | |
--log-level $LOGLEVEL \ | |
--log-file $VENV/run/gunicorn.log \ | |
--pid $VENV/run/gunicorn.pid \ | |
--bind $SOCKET \ | |
--name $NAME \ | |
$HOME/settings.py | |
end script |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment