* Make non-public services only listen on localhost

* /opt/teamplayer/* is owned by root and thus not writeable

* Put config files in /etc/teamplayer

* Switch DBMS from Sqlite to PostgreSQL
This commit is contained in:
Albert Hopkins 2010-08-15 18:04:54 -04:00
parent eaf9c7cf82
commit 71c7629cb3
10 changed files with 61 additions and 22 deletions

View File

@ -5,7 +5,7 @@ ProxyPass /repo/ http://localhost:8000/repo/
<VirtualHost *>
DocumentRoot TP_HOME/web/
WSGIDaemonProcess TP_USER user=TP_USER group=TP_USER processes=1 threads=5
WSGIScriptAlias / TP_HOME/teamplayer.wsgi
WSGIScriptAlias / /etc/teamplayer/teamplayer.wsgi
<Location "/">
WSGIProcessGroup TP_USER

6
teamplayer/issue Normal file
View File

@ -0,0 +1,6 @@

------------------------------------------------------------------------------
TEAMPLAYER CONSOLE
------------------------------------------------------------------------------

View File

@ -1,8 +1,18 @@
#!/bin/sh
if [ ! -f /etc/firstboot ] ; then
echo "Creating TeamPlayer database ..."
createuser -U postgres -D -S -R teamplayer
createdb -U postgres teamplayer
touch /var/log/teamplayer/teamplayer.log
chown TP_USER:TP_USER /var/log/teamplayer/teamplayer.log
fi
su -c "TP_HOME/bin/start-teamplayer" TP_USER
tailf TP_HOME/teamplayer.log > /dev/tty7 &
tailf /var/log/teamplayer/teamplayer.log > /dev/tty7 &
# put some ionice on mpd
sleep 3
ionice -c2 -n0 -p$(cat TP_DB/mpd/mpd.pid)
touch /etc/firstboot

View File

@ -4,6 +4,6 @@ sys-kernel/gentoo-sources symlink
media-sound/mpd audiofile ffmpeg flac id3 lame network ogg vorbis mad sqlite
media-video/ffmpeg mmx mxext mp3 network x264
media-libs/flac ogg
dev-python/django sqlite
dev-python/django postgres
dev-db/sqlite threadsafe
www-servers/apache threads

View File

@ -1,4 +1,4 @@
#!/bin/sh -e
#!/bin/sh -ve
CHROOT="$1"
HOSTNAME="$2"
@ -7,7 +7,8 @@ APPLIANCE="`dirname $0`"
HG_REPO="../teamplayer"
TP_USER="teamplayer"
TP_HOME="/opt/teamplayer"
TP_DB="/var/db/teamplayer"
TP_DB="/var/run/teamplayer"
PGVER="8.4"
INSTALL="/usr/bin/install"
M4="/usr/bin/m4"
@ -15,14 +16,23 @@ M4_DEFS="-D HOSTNAME=${HOSTNAME} -D TP_USER=${TP_USER} -D TP_HOME=${TP_HOME}"
M4_DEFS="${M4_DEFS} -D TP_DB=${TP_DB}"
M4C="${M4} ${M4_DEFS}"
# Postgres config
chroot ${CHROOT} passwd -d postgres
yes | chroot ${CHROOT} emerge --config =postgresql-server-${PGVER}*
chroot ${CHROOT} rc-update add postgresql-${PGVER} default
chroot ${CHROOT} getent passwd ${TP_USER} || \
chroot ${CHROOT} useradd -c "Teamplayer Server" -U -d ${TP_HOME} \
${TP_USER}
chroot ${CHROOT} useradd -c "Teamplayer Server" -G postgres -U \
-d ${TP_HOME} ${TP_USER}
rm -rf ${TP_HOME}
hg clone --pull ${HG_REPO} ${CHROOT}/${TP_HOME}
cp ${APPLIANCE}/teamplayer.wsgi ${CHROOT}${TP_HOME}/teamplayer.wsgi
cp ${APPLIANCE}/bash_profile ${CHROOT}${TP_HOME}/.bash_profile
${M4C} ${APPLIANCE}/settings_local.py > ${CHROOT}${TP_HOME}/web/settings_local.py
chroot ${CHROOT} mkdir -p /etc/teamplayer
${M4C} ${APPLIANCE}/teamplayer.wsgi > ${CHROOT}/etc/teamplayer/teamplayer.wsgi
${M4C} ${APPLIANCE}/settings_local.py > ${CHROOT}/etc/teamplayer/settings_local.py
mkdir -p ${CHROOT}${TP_HOME}/bin
${M4C} ${APPLIANCE}/start-teamplayer > ${CHROOT}${TP_HOME}/bin/start-teamplayer
chmod +x ${CHROOT}${TP_HOME}/bin/start-teamplayer
@ -33,10 +43,12 @@ chroot ${CHROOT} ${INSTALL} -d -o ${TP_USER} -g ${TP_USER} ${TP_DB}/songs
chroot ${CHROOT} rm -rf ${TP_HOME}/web/media/songs
chroot ${CHROOT} ln -s ${TP_DB}/songs ${TP_HOME}/web/media/songs
chroot ${CHROOT} ${INSTALL} -d -o ${TP_USER} -g ${TP_USER} ${TP_DB}/mpd
chroot ${CHROOT} chown -R ${TP_USER}:${TP_USER} ${TP_HOME}
chroot ${CHROOT} ${INSTALL} -d -o ${TP_USER} -g ${TP_USER} /var/log/teamplayer
${M4C} ${APPLIANCE}/10_teamplayer.conf > ${CHROOT}/etc/apache2/vhosts.d/10_teamplayer.conf
cp ${APPLIANCE}/apache2.conf ${CHROOT}/etc/conf.d/apache2
${M4C} ${APPLIANCE}/local.start > ${CHROOT}/etc/conf.d/local.start
${M4C} ${APPLIANCE}/local.stop > ${CHROOT}/etc/conf.d/local.stop
sed -i 's/Gentoo Virtual Machine/TEAMPLAYER CONSOLE/' ${CHROOT}/etc/issue
cp ${APPLIANCE}/issue ${CHROOT}/etc/issue
chroot ${CHROOT} rc-update add apache2 default
chroot ${CHROOT} rc-update add ntpd default

View File

@ -6,8 +6,10 @@ TP_STREAM_URL = '/stream.mp3'
`TP_HOME' = 'TP_HOME'
DEBUG = False
TEMPLATE_DEBUG = DEBUG
DATABASE_ENGINE = 'sqlite3'
DATABASE_NAME = 'TP_DB/teamplayer.db'
#SONG_STORAGE = 'TP_DB/songs'
DATABASE_ENGINE = 'postgresql_psycopg2'
DATABASE_NAME = 'teamplayer'
DATABASE_HOST = ''
DATABASE_PASSWORD = ''
DATABASE_PORT = ''
TP_MPD_HOME = 'TP_DB/mpd'
TP_REPO_URL = '/repo/'

View File

@ -1,15 +1,18 @@
#!/bin/sh
# this should be run as the TP_USER user
PYTHONPATH="/etc/teamplayer:$PYTHONPATH"
export PYTHONPATH
cd ~
hg serve -p 8000 --prefix /repo/ > $HOME/hgserve.log 2>&1 &
hg serve -p 8000 --prefix /repo/ > /var/log/teamplayer/hgserve.log 2>&1 &
cd ~/web
if [ ! -f "TP_DB/teamplayer.db" ] ; then
if [ ! -f "/etc/firstboot" ] ; then
python manage.py syncdb
fi
# spin!
python manage.py spin --verbosity=2 $@ > "$HOME/teamplayer.log" 2>&1 &
echo $! > "$HOME/tps.pid"
python manage.py spin --verbosity=2 $@ > "/var/log/teamplayer/teamplayer.log" 2>&1 &
echo $! > "TP_DB/tps.pid"

View File

@ -2,6 +2,9 @@
# this should be run as the TP_USER user
cd ~/web
PYTHONPATH="/etc/teamplayer:$PYTHONPATH"
[ -f "$HOME/tps.pid" ] && kill $(cat "$HOME/tps.pid")
python manage.py stop_stream > "$HOME/teamplayer.log"
export PYTHONPATH
[ -f "$HOME/tps.pid" ] && kill $(cat "TP_DB/tps.pid")
python manage.py stop_stream >> "/var/log/teamplayer/teamplayer.log"

View File

@ -1,8 +1,9 @@
import os
import sys
path = os.path.dirname(__file__)
path = os.path.dirname(`__file__')
sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'web.settings'
sys.path.append('TP_HOME/web')
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
import django.core.handlers.wsgi

View File

@ -1,3 +1,4 @@
=dev-db/postgresql-server-8.4*
dev-python/django
dev-python/python-mpd
dev-vcs/mercurial
@ -5,5 +6,6 @@ media-libs/mutagen
media-sound/mpc
media-sound/mpd
net-misc/dhcpcd
net-misc/ntp
www-apache/mod_wsgi
www-servers/apache