diff --git a/teamplayer/Makefile b/teamplayer/Makefile index 8b31ead..c42c396 100644 --- a/teamplayer/Makefile +++ b/teamplayer/Makefile @@ -7,19 +7,16 @@ PGVER = 9.3 INSTALL = install AVAHI := NO -M4_DEFS += -D TP_USER=$(TP_USER) -D TP_HOME=$(TP_HOME) -D TP_DB=$(TP_DB) -D TP_HOSTNAME=$(HOSTNAME) +M4_DEFS += -D TP_USER=$(TP_USER) -D TP_HOME=$(TP_HOME) -D TP_DB=$(TP_DB) -D HOSTNAME=$(HOSTNAME) M4C = $(M4) $(M4_DEFS) inroot := chroot $(CHROOT) rcdefault := /etc/runlevels/default post_files = bash_profile settings_local.py start-teamplayer stop-teamplayer -post_files += local.start local.stop issue lighttpd.conf teamplayer.service +post_files += local.start local.stop issue nginx.conf teamplayer.service preinstall: - $(inroot) $(EMERGE) --select -n $(USEPKG) dev-lang/python:2.7 - $(inroot) eselect python set python2.7 - $(inroot) python-updater postinstall: $(post_files) $(SCROBBLER_AUTH) urls.py $(inroot) $(EMERGE) -n $(USEPKG) dev-db/postgresql-server:$(PGVER) @@ -44,7 +41,7 @@ endif cp bash_profile $(CHROOT)$(TP_HOME)/.bash_profile $(inroot) virtualenv $(TP_HOME) $(inroot) bash -c ". $(TP_HOME)/bin/activate ; pip install -e $(TP_HOME)/teamplayer" - $(inroot) bash -c ". $(TP_HOME)/bin/activate ; pip install psycopg2 flup Whoosh setproctitle" + $(inroot) bash -c ". $(TP_HOME)/bin/activate ; pip install psycopg2 uwsgi Whoosh setproctitle" $(inroot) bash -c ". $(TP_HOME)/bin/activate ; django-admin.py startproject project $(TP_HOME)" chmod +x $(CHROOT)/$(TP_HOME)/manage.py $(inroot) ln -sf ../manage.py $(TP_HOME)/bin/manage @@ -69,10 +66,10 @@ endif $(inroot) chmod +x /etc/local.d/teamplayer.start $(inroot) chmod +x /etc/local.d/teamplayer.stop cp issue $(CHROOT)/etc/issue - $(M4C) lighttpd.conf > $(CHROOT)/etc/lighttpd/lighttpd.conf - $(inroot) gpasswd -a lighttpd teamplayer + $(M4C) nginx.conf > $(CHROOT)/etc/nginx/nginx.conf + $(inroot) gpasswd -a nginx teamplayer - $(inroot) ln -sf /etc/init.d/lighttpd $(rcdefault)/lighttpd + $(inroot) ln -sf /etc/init.d/nginx $(rcdefault)/nginx $(inroot) ln -sf /etc/init.d/ntpd $(rcdefault)/ntpd $(inroot) $(EMERGE) --depclean --with-bdeps=n diff --git a/teamplayer/bash_profile b/teamplayer/bash_profile index 06f9bc8..142233b 100644 --- a/teamplayer/bash_profile +++ b/teamplayer/bash_profile @@ -1,3 +1,5 @@ export DJANGO_SETTINGS_MODULE='project.settings_local' +export PYTHONPATH="$HOME" PATH="$HOME/bin:$PATH" +export LANG="en_US.UTF-8" . activate diff --git a/teamplayer/lighttpd.conf b/teamplayer/lighttpd.conf deleted file mode 100644 index 44a57c3..0000000 --- a/teamplayer/lighttpd.conf +++ /dev/null @@ -1,80 +0,0 @@ -var.basedir = "/var/www/localhost" -var.logdir = "/var/log/lighttpd" -var.statedir = "/var/lib/lighttpd" - -server.modules = ( - "mod_rewrite", -# "mod_redirect", - "mod_alias", - "mod_access", - "mod_fastcgi", -# "mod_cml", -# "mod_trigger_b4_dl", -# "mod_auth", -# "mod_status", -# "mod_setenv", -# "mod_proxy", -# "mod_simple_vhost", -# "mod_evhost", -# "mod_userdir", -# "mod_compress", -# "mod_ssi", -# "mod_usertrack", -# "mod_expire", -# "mod_secdownload", -# "mod_rrdtool", -# "mod_webdav", - "mod_accesslog" -) - -include "mime-types.conf" - -# {{{ server settings -server.username = "lighttpd" -server.groupname = "lighttpd" - -server.document-root = var.basedir + "/htdocs" -server.pid-file = "/var/run/lighttpd.pid" - -server.errorlog = var.logdir + "/error.log" -# log errors to syslog instead -# server.errorlog-use-syslog = "enable" - -server.indexfiles = ("index.php", "index.html", - "index.htm", "default.htm") - -# server.tag = "lighttpd" - -server.follow-symlink = "enable" - - -# {{{ mod_accesslog -accesslog.filename = var.logdir + "/access.log" -# }}} - -# {{{ mod_dirlisting -# enable directory listings -dir-listing.activate = "disable" -# - -url.access-deny = ("~", ".inc") - - -# begin TeamPlayer config -server.max-request-size = 100000 -fastcgi.server = ( - "/teamplayer.fcgi" => ( - "main" => ( - "socket" => "TP_DB/teamplayer.sock", - "check-local" => "disable", - ) - ), -) -alias.url = ( - "/static" => "TP_HOME/static/", -) - -url.rewrite-once = ( - "^(/static.*)$" => "$1", - "^(/.*)$" => "/teamplayer.fcgi$1", -) diff --git a/teamplayer/make.conf b/teamplayer/make.conf index 8db501b..a9f62bd 100644 --- a/teamplayer/make.conf +++ b/teamplayer/make.conf @@ -1,5 +1,3 @@ # Settings for TeamPlayer -PYTHON_TARGETS="python2_7 python3_3" -PYTHON_SINGLE_TARGET="python2_7" -USE_PYTHON="2.7" +NGINX_MODULES_HTTP="auth_basic gzip proxy referer rewrite headers_more uwsgi" diff --git a/teamplayer/nginx.conf b/teamplayer/nginx.conf new file mode 100644 index 0000000..14c8daf --- /dev/null +++ b/teamplayer/nginx.conf @@ -0,0 +1,82 @@ +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; + client_max_body_size 100000k; + 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 TP_HOME/teamplayer/teamplayer/static/; + } + + location / { + uwsgi_pass unix://TP_DB/teamplayer.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/teamplayer/package.accept_keywords b/teamplayer/package.accept_keywords index 170c637..ef6a2b9 100644 --- a/teamplayer/package.accept_keywords +++ b/teamplayer/package.accept_keywords @@ -1,5 +1,4 @@ dev-db/postgresql-base dev-db/postgresql-server -dev-lang/python:2.7 sys-kernel/gentoo-sources virtual/python-imaging diff --git a/teamplayer/package.use b/teamplayer/package.use index 489a4a3..b49f4e7 100644 --- a/teamplayer/package.use +++ b/teamplayer/package.use @@ -2,8 +2,8 @@ app-editors/nano ncurses dev-db/sqlite extensions dev-lang/python sqlite ssl threads xml media-libs/flac ogg -media-sound/mpd aac audiofile ffmpeg flac inotify id3tag lame network ogg vorbis mad sqlite -media-video/ffmpeg mmx mxext mp3 network x264 +media-sound/mpd faad audiofile ffmpeg flac inotify id3tag lame network ogg vorbis mad soup sqlite unicode +media-video/ffmpeg avx cpudetection mmx mmxext mp3 network ssse3 x264 sys-apps/kmod openrc tools sys-apps/openrc netifrc sys-apps/portage python3 ipc @@ -12,5 +12,4 @@ sys-fs/udev openrc sys-kernel/gentoo-sources symlink sys-libs/ncurses minimal virtual/ffmpeg x264 mp3 -virtual/python-imaging python_targets_python2_7 -www-servers/lighttpd fastcgi pcre +www-servers/nginx http diff --git a/teamplayer/settings_local.py b/teamplayer/settings_local.py index 42aa4aa..80db099 100644 --- a/teamplayer/settings_local.py +++ b/teamplayer/settings_local.py @@ -1,4 +1,4 @@ -from settings import * +from .settings import * ############################################################################# # Local Settings @@ -127,7 +127,6 @@ TEAMPLAYER = { 'SHAKE_THINGS_UP': 25, 'ALWAYS_SHAKE_THINGS_UP': True, 'HTTP_PORT': 8000, - 'IPC_PORT': 8080, } DATABASES = { @@ -136,7 +135,8 @@ DATABASES = { 'NAME': 'teamplayer', 'HOST': '', 'PASSWORD': '', - 'PORT': '' + 'PORT': '', + 'CONN_MAX_AGE': 300, } } diff --git a/teamplayer/start-teamplayer b/teamplayer/start-teamplayer index 83a49f7..9bf35aa 100755 --- a/teamplayer/start-teamplayer +++ b/teamplayer/start-teamplayer @@ -2,6 +2,7 @@ # this should be run as the TP_USER user PYTHON=python +PYTHONPATH="$HOME" ; export PYTHONPATH DJANGO_SETTINGS_MODULE="project.settings_local" ; export DJANGO_SETTINGS_MODULE cd ~ @@ -12,11 +13,16 @@ if [ ! -f "/etc/firstboot" ] ; then $PYTHON manage.py collectstatic --noinput --verbosity=0 fi -# start the fastcgi daemon -$PYTHON manage.py runfcgi daemonize=true protocol=fcgi maxrequest=20 \ - pidfile="TP_DB/fcgi.pid" socket=TP_DB/teamplayer.sock umask=002 \ - > "/var/log/teamplayer/teamplayer.log" 2>&1 +# start the uwsgi daemon +uwsgi --socket TP_DB/teamplayer.sock \ + --chmod=660 \ + -w project.wsgi \ + --uid teamplayer \ + --gid teamplayer \ + --pidfile TP_DB/uwsgi.pid \ + --daemonize2 /var/log/teamplayer/teamplayer.log \ + -T # Start the Spin Doctor -$PYTHON manage.py spindoctor --verbosity=2 $@ > "/var/log/teamplayer/teamplayer.log" 2>&1 & +$PYTHON manage.py spindoctor --verbosity=2 $@ >> "/var/log/teamplayer/teamplayer.log" 2>&1 & echo $! > "TP_DB/tps.pid" diff --git a/teamplayer/stop-teamplayer b/teamplayer/stop-teamplayer index 25bf488..c21b831 100755 --- a/teamplayer/stop-teamplayer +++ b/teamplayer/stop-teamplayer @@ -2,13 +2,14 @@ # this should be run as the TP_USER user PYTHON=python +PYTHONPATH="$HOME" ; export PYTHONPATH DJANGO_SETTINGS_MODULE="project.settings_local" ; export DJANGO_SETTINGS_MODULE . ~/bin/activate cd ~ -#[ -f "TP_DB/tps.pid" ] && kill $(cat "TP_DB/tps.pid") -[ -f "TP_DB/fcgi.pid" ] && kill $(cat "TP_DB/fcgi.pid") +[ -f "TP_DB/tps.pid" ] && kill $(cat "TP_DB/tps.pid") +[ -f "TP_DB/uwsgi.pid" ] && kill $(cat "TP_DB/uwsgi.pid") $PYTHON manage.py stop_stream >> "/var/log/teamplayer/teamplayer.log" diff --git a/teamplayer/world b/teamplayer/world index 156c174..6682bdd 100644 --- a/teamplayer/world +++ b/teamplayer/world @@ -1,3 +1,3 @@ media-sound/mpd net-misc/ntp -www-servers/lighttpd +www-servers/nginx