diff --git a/teamplayer/10_teamplayer.conf b/teamplayer/10_teamplayer.conf index 9458234..61dbdfb 100644 --- a/teamplayer/10_teamplayer.conf +++ b/teamplayer/10_teamplayer.conf @@ -5,7 +5,7 @@ ProxyPass /repo/ http://localhost:8000/repo/ 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 WSGIProcessGroup TP_USER diff --git a/teamplayer/issue b/teamplayer/issue new file mode 100644 index 0000000..f987123 --- /dev/null +++ b/teamplayer/issue @@ -0,0 +1,6 @@ + + ------------------------------------------------------------------------------ + TEAMPLAYER CONSOLE + ------------------------------------------------------------------------------ + + diff --git a/teamplayer/local.start b/teamplayer/local.start index 11f1c1b..a933a31 100755 --- a/teamplayer/local.start +++ b/teamplayer/local.start @@ -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 diff --git a/teamplayer/package.use b/teamplayer/package.use index 5aa7ba7..8ebdfa3 100644 --- a/teamplayer/package.use +++ b/teamplayer/package.use @@ -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 diff --git a/teamplayer/postinstall b/teamplayer/postinstall index 5691a3e..2d46800 100755 --- a/teamplayer/postinstall +++ b/teamplayer/postinstall @@ -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 diff --git a/teamplayer/settings_local.py b/teamplayer/settings_local.py index 6d1faaf..74d6027 100644 --- a/teamplayer/settings_local.py +++ b/teamplayer/settings_local.py @@ -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/' diff --git a/teamplayer/start-teamplayer b/teamplayer/start-teamplayer index 515c825..a07fd72 100755 --- a/teamplayer/start-teamplayer +++ b/teamplayer/start-teamplayer @@ -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" diff --git a/teamplayer/stop-teamplayer b/teamplayer/stop-teamplayer index 44ca610..31c8daa 100755 --- a/teamplayer/stop-teamplayer +++ b/teamplayer/stop-teamplayer @@ -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" diff --git a/teamplayer/teamplayer.wsgi b/teamplayer/teamplayer.wsgi index f89ac81..4ae50d8 100644 --- a/teamplayer/teamplayer.wsgi +++ b/teamplayer/teamplayer.wsgi @@ -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 diff --git a/teamplayer/world b/teamplayer/world index f898ce1..3288607 100644 --- a/teamplayer/world +++ b/teamplayer/world @@ -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