From 80bd6a3d83f282b57a7111b7561a9317d8713807 Mon Sep 17 00:00:00 2001 From: Albert Hopkins Date: Fri, 27 Sep 2013 14:34:15 +0000 Subject: [PATCH] airport: Update to work with new django1.5 version of airport. * Only just python 3 * Update postgres dependency to 9.3 * Remove apache. Replace with nginx/uwsgi mix. * Don't double-install packages in both portage and virtualenv. --- airport/Makefile | 21 ++++----- airport/airport.wsgi | 16 ------- airport/default_vhost.include | 24 ----------- airport/make.conf | 7 ++- airport/nginx.conf | 81 +++++++++++++++++++++++++++++++++++ airport/package.keywords | 5 +-- airport/package.use | 4 +- airport/world | 5 +-- airport/zzairport.start | 17 ++++++++ 9 files changed, 116 insertions(+), 64 deletions(-) delete mode 100644 airport/airport.wsgi delete mode 100644 airport/default_vhost.include create mode 100644 airport/nginx.conf create mode 100755 airport/zzairport.start diff --git a/airport/Makefile b/airport/Makefile index cb6f683..a6928e9 100644 --- a/airport/Makefile +++ b/airport/Makefile @@ -1,18 +1,13 @@ APP_ROOT := /var/airport AIRPORT_REPO ?= https://bitbucket.org/marduk/airport -PGVER := 9.2 +PGVER := 9.3 rcdefault := /etc/runlevels/default preinstall: - $(inroot) $(EMERGE) -n $(USEPKG) python:2.7 - $(inroot) eselect python set python2.7 - $(inroot) python-updater -postinstall: airport.service settings.py airport.wsgi default_vhost.include firstboot.start issue - sed -i 's/^APACHE2_OPTS=.*/APACHE2_OPTS="-D DEFAULT_VHOST -D INFO -D WSGI"/' $(CHROOT)/etc/conf.d/apache2 - $(inroot) rc-update add apache2 default +postinstall: airport.service settings.py firstboot.start zzairport.start issue nginx.conf sed -i 's/^PG_INITDB_OPTS.*/PG_INITDB_OPTS="--locale=en_US.UTF-8"/' $(CHROOT)/etc/conf.d/postgresql-$(PGVER) $(inroot) eselect postgresql set $(PGVER) rm -rf $(CHROOT)/var/lib/postgresql/$(PGVER) @@ -23,24 +18,26 @@ postinstall: airport.service settings.py airport.wsgi default_vhost.include firs rm -rf $(CHROOT)/$(APP_ROOT) hg clone $(AIRPORT_REPO) $(CHROOT)/$(APP_ROOT) echo 'VERSION="'`date +1.%y%m%d.%H%m`'"' > $(CHROOT)/$(APP_ROOT)/djangoproject/airport/__init__.py - chroot $(CHROOT) virtualenv -p /usr/bin/python2.7 $(APP_ROOT) + chroot $(CHROOT) virtualenv -p /usr/bin/python3.2 $(APP_ROOT) $(inroot) bash -c ". $(APP_ROOT)/bin/activate ; pip install -r $(APP_ROOT)/requirements.txt" - $(inroot) bash -c ". $(APP_ROOT)/bin/activate ; pip install psycopg2" + $(inroot) bash -c ". $(APP_ROOT)/bin/activate ; pip install psycopg2 uwsgi" mkdir -p $(CHROOT)/$(APP_ROOT)/etc touch $(CHROOT)/$(APP_ROOT)/etc/__init__.py cp settings.py $(CHROOT)/$(APP_ROOT)/etc - cp default_vhost.include $(CHROOT)/etc/apache2/vhosts.d - cp airport.wsgi $(CHROOT)/var/www/localhost $(inroot) id -u airport >/dev/null || $(inroot) useradd -d $(APP_ROOT) -M -s /bin/false -U -G postgres airport - $(inroot) gpasswd -a apache postgres + $(inroot) chown -R airport:airport $(APP_ROOT) cp firstboot.start $(CHROOT)/etc/local.d + cp zzairport.start $(CHROOT)/etc/local.d cp issue $(CHROOT)/etc/issue + $(M4) -D HOSTNAME=$(HOSTNAME) nginx.conf > $(CHROOT)/etc/nginx/nginx.conf + $(inroot) ln -sf /etc/init.d/nginx $(rcdefault)/nginx ifeq ($(AVAHI),YES) $(inroot) $(EMERGE) -n $(USEPKG) net-dns/avahi $(inroot) rm -f /etc/avahi/services/* cp airport.service $(CHROOT)/etc/avahi/services $(inroot) ln -sf /etc/init.d/avahi-daemon $(rcdefault)/avahi-daemon endif + $(inroot) $(EMERGE) --depclean --with-bdeps=n clean: diff --git a/airport/airport.wsgi b/airport/airport.wsgi deleted file mode 100644 index 8338228..0000000 --- a/airport/airport.wsgi +++ /dev/null @@ -1,16 +0,0 @@ -import os -import sys -sys.stdout = sys.stderr - -import site -site.addsitedir('/var/airport/lib/python2.7/site-packages') - -sys.path.append('/var/airport') -sys.path.append('/var/airport/djangoproject') -os.environ['DJANGO_SETTINGS_MODULE'] = 'etc.settings' -os.environ['VIRTUAL_ENV'] = '/var/airport/' - -import django.core.handlers.wsgi -application = django.core.handlers.wsgi.WSGIHandler() - -# vim: filetype=python diff --git a/airport/default_vhost.include b/airport/default_vhost.include deleted file mode 100644 index 87bdb7c..0000000 --- a/airport/default_vhost.include +++ /dev/null @@ -1,24 +0,0 @@ -ServerAdmin root@localhost -KeepAlive Off - -DocumentRoot "/var/www/localhost/htdocs" - -# This should be changed to whatever you set DocumentRoot to. - - Options Indexes FollowSymLinks - AllowOverride All - - # Controls who can get stuff from this server. - Order allow,deny - Allow from all - - - -WSGIDaemonProcess airport display-name=airport user=airport processes=2 threads=15 -WSGISCriptAlias / /var/www/localhost/airport.wsgi - - AllowOverride None - Order Deny,Allow - - -# vim: ts=4 filetype=apache diff --git a/airport/make.conf b/airport/make.conf index d8b16f2..eecc4bb 100644 --- a/airport/make.conf +++ b/airport/make.conf @@ -1,5 +1,4 @@ - # Settings for Airport -PYTHON_TARGETS="python2_7" -APACHE2_MPMS="prefork" -APACHE2_MODULES="auth_basic authz_host env include info" +PYTHON_TARGETS="python3_2" +USE_PYTHON="3.2" +NGINX_MODULES_HTTP="auth_basic gzip proxy referer rewrite headers_more uwsgi" diff --git a/airport/nginx.conf b/airport/nginx.conf new file mode 100644 index 0000000..a40720c --- /dev/null +++ b/airport/nginx.conf @@ -0,0 +1,81 @@ +user nginx nginx; +worker_processes 1; + +error_log /var/log/nginx/error_log info; + +events { + worker_connections 1024; + use epoll; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main + '$remote_addr - $remote_user [$time_local] ' + '"$request" $status $bytes_sent ' + '"$http_referer" "$http_user_agent" ' + '"$gzip_ratio"'; + + client_header_timeout 10m; + client_body_timeout 10m; + send_timeout 10m; + + connection_pool_size 256; + client_header_buffer_size 1k; + large_client_header_buffers 4 2k; + request_pool_size 4k; + + gzip on; + gzip_min_length 1100; + gzip_buffers 4 8k; + gzip_types text/plain; + + output_buffers 1 32k; + postpone_output 1460; + + sendfile on; + tcp_nopush on; + tcp_nodelay on; + + keepalive_timeout 75 20; + + ignore_invalid_headers on; + + index index.html; + + server { + listen 0.0.0.0; + server_name HOSTNAME; + + location /static/ { + alias /var/airport/djangoproject/airport/static/; + } + + location / { + uwsgi_pass unix:///var/airport/airport.sock; + include /etc/nginx/uwsgi_params; + } + + access_log /var/log/nginx/HOSTNAME.access_log main; + error_log /var/log/nginx/HOSTNAME.error_log info; + + root /var/www/localhost/htdocs; + } + + # SSL example + #server { + # listen 127.0.0.1:443; + # server_name localhost; + + # ssl on; + # ssl_certificate /etc/ssl/nginx/nginx.pem; + # ssl_certificate_key /etc/ssl/nginx/nginx.key; + + # access_log /var/log/nginx/localhost.ssl_access_log main; + # error_log /var/log/nginx/localhost.ssl_error_log info; + + # root /var/www/localhost/htdocs; + #} +} diff --git a/airport/package.keywords b/airport/package.keywords index fdd2418..3e488a7 100644 --- a/airport/package.keywords +++ b/airport/package.keywords @@ -1,4 +1,3 @@ -=dev-python/django-1.4* ** -dev-db/postgresql-base:9.2 ** -dev-db/postgresql-server:9.2 ** +dev-db/postgresql-base:9.3 ** +dev-db/postgresql-server:9.3 ** sys-kernel/gentoo-sources ~amd64 ~x86 diff --git a/airport/package.use b/airport/package.use index f2e22c3..e6d001f 100644 --- a/airport/package.use +++ b/airport/package.use @@ -1,9 +1,11 @@ app-editors/nano ncurses dev-lang/python ssl threads xml +dev-libs/libpcre cxx net-misc/dhcp client sys-apps/kmod tools -sys-apps/portage python2 sys-devel/gcc cxx nptl sys-kernel/gentoo-sources symlink sys-libs/ncurses minimal +sys-apps/portage python3 ipc + www-servers/nginx http diff --git a/airport/world b/airport/world index 9b13158..b53561a 100644 --- a/airport/world +++ b/airport/world @@ -1,5 +1,2 @@ -dev-db/postgresql-server:9.2 -www-apache/mod_wsgi -dev-python/django -dev-python/psycopg +dev-db/postgresql-server:9.3 www-servers/nginx diff --git a/airport/zzairport.start b/airport/zzairport.start new file mode 100755 index 0000000..5bfd2e8 --- /dev/null +++ b/airport/zzairport.start @@ -0,0 +1,17 @@ +#!/bin/sh -e + +PYTHONPATH=/var/airport ; export PYTHONPATH +DJANGO_SETTINGS_MODULE="etc.settings" ; export DJANGO_SETTINGS_MODULE + +cd /var/airport +. bin/activate +cd djangoproject +uwsgi --socket /var/airport/airport.sock \ + -w djangoproject.wsgi \ + --uid airport \ + --gid airport \ + --daemonize2 /var/airport/airport.log \ + -T + +chown airport:nginx /var/airport/airport.sock +chmod g+rw /var/airport/airport.sock