Skip to content

Instantly share code, notes, and snippets.

@felipe-prenholato
Created November 18, 2011 17:11
Show Gist options
  • Save felipe-prenholato/1377083 to your computer and use it in GitHub Desktop.
Save felipe-prenholato/1377083 to your computer and use it in GitHub Desktop.
#! /bin/sh
# /etc/init.d/portal_prd
### BEGIN INIT INFO
# Provides: portal
# Required-Start: $nginx
# Required-Stop:
# Default-Start: 1
# Default-Stop:
# Short-Description: start uwsgi server sistemas.pdg.com.br:80
### END INIT INFO
. /lib/lsb/init-functions
do_start () {
echo "Starting sistemas.pdg.com.br:80"
exec /home/sistemas/virtualenvs/prd/bin/uwsgi --ini /home/sistemas/virtualenvs/prd/portal/deploy/uwsgi.ini
}
do_stop () {
for p in $(ps aux | grep "/home/sistemas/virtualenvs/prd/bin/uwsgi" | grep -v grep | awk '{print $2}');
do
echo "Killing $p"
kill $p
done
}
case "$1" in
start)
do_start
;;
restart|reload|force-reload)
do_stop
do_start
;;
stop)
do_stop
;;
*)
echo "Usage: $0 start|stop|restart" >&2
exit 3
;;
esac
# /home/sistemas/virtualenvs/prd/portal/deploy/nginx.conf
server {
listen 80;
server_name sistemas.pdg.com.br;
root /home/sistemas/virtualenvs/prd/portal;
access_log /home/sistemas/virtualenvs/prd/logs/nginx_access.log;
error_log /home/sistemas/virtualenvs/prd/logs/nginx_error.log;
location /media/ {
root /home/sistemas/virtualenvs/prd/portal;
expires max;
}
location / {
uwsgi_read_timeout 120;
uwsgi_send_timeout 120;
uwsgi_pass unix:///home/sistemas/virtualenvs/prd/tmp/uwsgi.sock;
include uwsgi_params;
#uwsgi_pass 127.0.0.1:1080;
}
}
# vim: ft=nginx
;# /home/sistemas/virtualenvs/prd/portal/deploy/uwsgi.ini
[uwsgi]
; uwsgi configuration options: http://projects.unbit.it/uwsgi/wiki/Doc
; venv dir, socket, pid, uid, etc
env=DJANGO_SETTINGS_MODULE=portal.settings
virtualenv=/home/sistemas/virtualenvs/prd/
module=portal.deploy.wsgi_app
socket=/home/sistemas/virtualenvs/prd/tmp/uwsgi.sock
pidfile=/home/sistemas/virtualenvs/prd/tmp/uwsgi.pid
touch-reload=/home/sistemas/virtualenvs/prd/tmp/restart.txt
uid=sistemas
gid=sistemas
no-orphans=true
die-on-term=true
#vacuum=true
; process is number of workers, one worker per core.
; cpu-affinity make sure that 1 worker don't change between various cores.
;
; listen isn't port that will listen for connections!
processes=4
;cpu-affinity=1
listen=5000
#master=true
; Every request that take longer than 60 seconds will die!
harakiri=300
harakiri-verbose=true
post-buffering=16000
buffer-size=25000
; logging stuff
daemonize=/home/sistemas/virtualenvs/prd/logs/uwsgi.log
; when true, disable-logging will disable request logging, only errors will be logged.
disable-logging=true
logdate=true
log-zero=true
log-5xx=true
# vim: ft=dosini
# coding: utf-8
# /home/sistemas/virtualenvs/prd/portal/deploy/wsgi_app.py
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
(prd)sistemas@server:~$ ls -l /home/sistemas/virtualenvs/prd/portal/deploy/wsgi_app.py /home/sistemas/virtualenvs/prd/tmp/
-rw-rw-r-- 1 sistemas sistemas 103 2011-11-09 19:26 /home/sistemas/virtualenvs/prd/portal/deploy/wsgi_app.py
/home/sistemas/virtualenvs/prd/tmp/:
total 4
-rw-rw-r-- 1 sistemas sistemas 0 2011-11-18 15:09 restart.txt
-rw-rw-rw- 1 sistemas sistemas 6 2011-11-18 15:09 uwsgi.pid
srwxrwxrwx 1 sistemas sistemas 0 2011-11-18 15:09 uwsgi.sock
Fri Nov 18 15:09:21 2011 - *** /home/sistemas/virtualenvs/prd/tmp/restart.txt has been touched... grace them all !!! ***
Fri Nov 18 15:09:21 2011 - ...gracefully killing workers...
Fri Nov 18 15:09:21 2011 - Gracefully killing worker 4 (pid: 15805)...
Fri Nov 18 15:09:21 2011 - Gracefully killing worker 1 (pid: 15802)...
Fri Nov 18 15:09:21 2011 - Gracefully killing worker 2 (pid: 15803)...
Fri Nov 18 15:09:21 2011 - Gracefully killing worker 3 (pid: 15804)...
Fri Nov 18 15:09:22 2011 - binary reloading uWSGI...
Fri Nov 18 15:09:22 2011 - chdir(): Permission denied [master.c line 594]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment