Last active
September 8, 2016 17:17
-
-
Save alexander-ae/43caf190c31fedb14f80 to your computer and use it in GitHub Desktop.
Digital Ocean: Django + Nginx + uwsgi
This file contains 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
# */2 * * * * /home/devstaff/opt/nginx/sbin/nginx -c /home/devstaff/opt/nginx/conf/nginx.conf >> $HOME/tmp/cron.log 2>&1 ; | |
*/2 * * * * cd /usr/local/bin/supervisord; /home/devstaff/etc/supervisord.sh start >> $HOME/tmp/cron.log 2>&1 ; |
This file contains 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
#! /bin/bash | |
PS=supervisord | |
SUPERVISORD=/usr/local/bin/supervisord | |
SUPERVISORCTL=/usr/local/bin/supervisorctl | |
PIDFILE=/home/devstaff/tmp/supervisord.pid | |
OPTS="-c /home/devstaff/etc/supervisord.conf" | |
TRUE=1 | |
FALSE=0 | |
test -x $SUPERVISORD || exit 0 | |
log() { | |
echo $(date -R): ${1} | |
} | |
isRunning() { | |
if [ "$(ps -p `cat ${PIDFILE}` | wc -l)" -gt 1 ]; then | |
return 1 | |
else | |
log "Supervisor not already running." | |
return 0 | |
fi | |
} | |
start () { | |
log "Checking Supervisor status." | |
isRunning | |
isAlive=$? | |
if [ "${isAlive}" -eq $TRUE ]; then | |
log "Supervisor is already running." | |
else | |
log "Starting Supervisor daemon." | |
$SUPERVISORD $OPTS || log "Failed!" | |
fi | |
} | |
stop () { | |
log "Stopping Supervisor daemon." | |
$SUPERVISORCTL $OPTS shutdown || log "Failed!" | |
} | |
case "$1" in | |
start) | |
start | |
;; | |
stop) | |
stop | |
;; | |
restart) | |
stop | |
start | |
;; | |
esac | |
exit 0 |
This file contains 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
[unix_http_server] | |
file=~/tmp/supervisor.sock ; (the path to the socket file) | |
;chmod=0700 ; socket file mode (default 0700) | |
;chown=nobody:nogroup ; socket file uid:gid owner | |
[supervisord] | |
logfile=~/tmp/supervisord.log ; (main log file;default $CWD/supervisord.log) | |
logfile_maxbytes=25MB ; (max main logfile bytes b4 rotation;default 50MB) | |
logfile_backups=10 ; (num of main logfile rotation backups;default 10) | |
loglevel=info ; (log level;default info; others: debug,warn,trace) | |
pidfile=~/tmp/supervisord.pid ; (supervisord pidfile;default supervisord.pid) | |
nodaemon=false ; (start in foreground if true;default false) | |
minfds=1024 ; (min. avail startup file descriptors;default 1024) | |
minprocs=200 ; (min. avail process descriptors;default 200) | |
;umask=022 ; (process file creation umask;default 022) | |
;user=chrism ; (default is current user, required if root) | |
;identifier=supervisor ; (supervisord identifier, default is 'supervisor') | |
;directory=/tmp ; (default is not to cd during start) | |
;nocleanup=true ; (don't clean up tempfiles at start;default false) | |
;environment=KEY="value" ; (key value pairs to add to environment) | |
[rpcinterface:supervisor] | |
supervisor.rpcinterface_factory = supervisor.rpcinterface:make_main_rpcinterface | |
[supervisorctl] | |
serverurl=unix:///home/alex/tmp/supervisor.sock ; use a unix:// URL for a unix socket | |
history_file=~/.sc_history ; use readline history if available | |
[include] | |
files = ini/*.ini |
This file contains 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
[program:base] | |
command=/usr/local/bin/uwsgi /home/devstaff/webapps/proyecto-base-django/uwsgi.ini |
This file contains 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
user devstaff; | |
worker_processes 4; | |
error_log logs/error.log crit; | |
pid logs/nginx.pid; | |
events { | |
worker_connections 1024; | |
use epoll; | |
multi_accept on; | |
} | |
http { | |
include mime.types; | |
default_type application/octet-stream; | |
log_format main '$remote_addr - $remote_user [$time_local] "$request" ' | |
'$status $body_bytes_sent "$http_referer" ' | |
'"$http_user_agent" "$http_x_forwarded_for"'; | |
access_log off; | |
server_tokens off; | |
sendfile on; | |
tcp_nopush on; | |
tcp_nodelay on; | |
keepalive_timeout 60; | |
client_max_body_size 25M; | |
gzip on; | |
gzip_min_length 10240; | |
gzip_types text/plain application/javascript application/x-javascript text/javascript text/xml text/css; | |
include /home/devstaff/opt/nginx/sites-available/*.conf; | |
} |
This file contains 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
server { | |
listen 80; | |
# server_name base.pe; | |
#location = /favicon.ico { | |
# rewrite "/favicon.ico" "/static_ciudaris/img/favicon/favicon-256.png"; | |
# expires 7d; | |
#} | |
location /static { | |
alias /home/devstaff/webapps/static/ ; | |
expires 7d; | |
} | |
location /media { | |
alias /home/devstaff/webapps/media/ ; | |
} | |
location / { | |
include uwsgi_params; | |
uwsgi_pass unix:///home/devstaff/webapps/proyecto-base-django/uwsgi.sock; | |
} | |
#error_page 404 /404.html; | |
error_page 500 502 503 504 /50x.html; | |
location = /50x.html { | |
root html; | |
} | |
} |
This file contains 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
[uwsgi] | |
;placeholders | |
home = /home/devstaff | |
webapps = %(home)/webapps/ | |
app = %(webapps)/proyecto-base-django | |
daemonize = %(home)/logs/uwsgi-@(exec://date +%%Y-%%m-%%d).log | |
log-reopen = true | |
;config | |
env = %(app)/src/settings/production.py | |
venv = %(home)/.envs/django_1_5 | |
chdir = %(app)/src | |
module = wsgi | |
; spawn the master and 2 processes | |
uwsgi-socket = %(app)/uwsgi.sock | |
master = true | |
processes = 2 | |
threads = 2 | |
thread-stacksize = 512 | |
reload-on-rss = 60 | |
# cheaper | |
cheaper = N | |
cheaper-algo = spare | |
cheaper = 1 | |
cheaper-initial = 1 | |
cheaper-step = 1 | |
harakiri = 30 ;numero máximo de segundos a mantener un request activo | |
vacuum = True | |
; log | |
logto = %(app)/uwsgi.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment