diff --git a/airport/Makefile b/airport/Makefile index 5660bf9..c7c7f3c 100644 --- a/airport/Makefile +++ b/airport/Makefile @@ -8,7 +8,7 @@ rcdefault := /etc/runlevels/default preinstall: -postinstall: airport.service settings.py firstboot.start zzairport.start issue nginx.conf +postinstall: airport.service settings.py local.start local.stop issue nginx.conf start-airport stop-airport stop-game 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) @@ -18,19 +18,28 @@ postinstall: airport.service settings.py firstboot.start zzairport.start issue n $(inroot) $(EMERGE) -1n $(USEPKG) dev-python/virtualenv rm -rf $(CHROOT)/$(APP_ROOT) hg clone -u $(AIRPORT_BRANCH) $(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/python3.2 $(APP_ROOT) + chroot $(CHROOT) virtualenv -p /usr/bin/python3 $(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 uwsgi" mkdir -p $(CHROOT)/$(APP_ROOT)/etc touch $(CHROOT)/$(APP_ROOT)/etc/__init__.py cp settings.py $(CHROOT)/$(APP_ROOT)/etc - $(inroot) id -u airport >/dev/null || $(inroot) useradd -d $(APP_ROOT) -M -s /bin/false -U -G postgres airport + $(inroot) id -u airport >/dev/null || $(inroot) useradd -d $(APP_ROOT) -M -U -G postgres airport + mkdir -p $(CHROOT)/$(APP_ROOT)/bin + cp start-airport $(CHROOT)/$(APP_ROOT)/bin/start-airport + cp stop-airport $(CHROOT)/$(APP_ROOT)/bin/stop-airport + cp stop-game $(CHROOT)/$(APP_ROOT)/bin/stop-game $(inroot) chown -R airport:airport $(APP_ROOT) - cp firstboot.start $(CHROOT)/etc/local.d - cp zzairport.start $(CHROOT)/etc/local.d + cp local.start $(CHROOT)/etc/local.d/airport.start + cp local.stop $(CHROOT)/etc/local.d/airport.stop +ifdef AIRPORT_SERIES + cat settings_$(AIRPORT_SERIES).py >> $(CHROOT)/$(APP_ROOT)/etc/settings.py + cp $(CHROOT)/$(APP_ROOT)/djangoproject/airport/fixtures/$(AIRPORT_SERIES).json \ + $(CHROOT)/$(APP_ROOT)/djangoproject/airport/fixtures/initial_data.json +endif cp issue $(CHROOT)/etc/issue $(M4) -D HOSTNAME=$(HOSTNAME) nginx.conf > $(CHROOT)/etc/nginx/nginx.conf + $(inroot) gpasswd -a nginx airport $(inroot) ln -sf /etc/init.d/nginx $(rcdefault)/nginx ifeq ($(AVAHI),YES) $(inroot) $(EMERGE) -n $(USEPKG) net-dns/avahi diff --git a/airport/firstboot.start b/airport/firstboot.start deleted file mode 100755 index abea7ba..0000000 --- a/airport/firstboot.start +++ /dev/null @@ -1,13 +0,0 @@ -#!/bin/sh -e - -echo Creating Airport database... -createuser -U postgres -D -l -R -S airport -createdb -U postgres -E utf8 -O airport airport - -PYTHONPATH=/var/airport ; export PYTHONPATH -cd /var/airport -. bin/activate -cd djangoproject -./manage.py syncdb --settings=etc.settings --noinput - -mv /etc/local.d/firstboot.start /etc/local.d/firstboot.start.disabled diff --git a/airport/local.start b/airport/local.start new file mode 100755 index 0000000..1c1986f --- /dev/null +++ b/airport/local.start @@ -0,0 +1,11 @@ +#!/bin/sh -e + +if [ ! -f /etc/firstboot ] ; then + echo Creating Airport database... + createuser -U postgres -D -l -R -S airport + createdb -U postgres -E utf8 -O airport airport +fi + +su -c "/var/airport/bin/start-airport" airport + +touch /etc/firstboot diff --git a/airport/local.stop b/airport/local.stop new file mode 100755 index 0000000..be94b1d --- /dev/null +++ b/airport/local.stop @@ -0,0 +1,3 @@ +#!/bin/sh + +su -c "/var/airport/bin/stop-airport" airport diff --git a/airport/package.use b/airport/package.use index 77cd46a..76a6b73 100644 --- a/airport/package.use +++ b/airport/package.use @@ -9,5 +9,6 @@ sys-fs/udev openrc sys-kernel/gentoo-sources symlink sys-libs/ncurses minimal sys-apps/portage python3 ipc +sys-apps/openrc netifrc www-servers/nginx http diff --git a/airport/settings.py b/airport/settings.py index b220d6e..72d4a32 100644 --- a/airport/settings.py +++ b/airport/settings.py @@ -98,6 +98,7 @@ TEMPLATE_CONTEXT_PROCESSORS = ( 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', 'airport.context_processors.externals', + 'airport.context_processors.game_name', ) MIDDLEWARE_CLASSES = ( @@ -150,4 +151,6 @@ LOGGING = { } } -AUTH_PROFILE_MODULE = 'airport.UserProfile' +AIRPORT = { + 'GAMESERVER_MULTIPROCESSING': True, +} diff --git a/airport/settings_europe.py b/airport/settings_europe.py new file mode 100644 index 0000000..0814816 --- /dev/null +++ b/airport/settings_europe.py @@ -0,0 +1,10 @@ + +AIRPORT = { + 'GAME_NAME': 'Airport Europe', + 'SCALE_FLIGHT_TIMES': False, + 'GAMESERVER_MULTIPROCESSING': True, + 'CRUISE_SPEED': 13.0, + 'GAMESERVER_LOOP_DELAY': 3, + 'MAP_INITIAL_LATITUDE': 53.58, + 'MAP_INITIAL_LONGITUDE': 23.11, +} diff --git a/airport/start-airport b/airport/start-airport new file mode 100755 index 0000000..bff854f --- /dev/null +++ b/airport/start-airport @@ -0,0 +1,29 @@ +#!/bin/sh +# this should be run as the airport user + +PYTHON=python +PYTHONPATH=/var/airport ; export PYTHONPATH +DJANGO_SETTINGS_MODULE="etc.settings" ; export DJANGO_SETTINGS_MODULE + +cd ~ +. bin/activate +cd djangoproject + +if [ ! -f "/etc/firstboot" ] ; then + $PYTHON manage.py syncdb --noinput --verbosity=0 + $PYTHON manage.py collectstatic --noinput --verbosity=0 +fi + +# start the uwsgi daemon +uwsgi --socket /var/airport/airport.sock \ + --chmod=660 \ + -w djangoproject.wsgi \ + --uid airport \ + --gid airport \ + --pidfile /var/airport/uwsgi.pid \ + --daemonize2 /var/airport/airport.log \ + -T + +# Start the Game Server +$PYTHON manage.py gameserver --verbosity=2 $@ > "/var/airport/gameserver.log" 2>&1 & +echo $! > "/var/airport/gameserver.pid" diff --git a/airport/stop-airport b/airport/stop-airport new file mode 100755 index 0000000..1ce2050 --- /dev/null +++ b/airport/stop-airport @@ -0,0 +1,5 @@ +#!/bin/sh +# this should be run as the airport user + +[ -f "/var/airport/gameserver.pid" ] && kill $(cat "/var/airport/gameserver.pid") +[ -f "/var/airport/uwsgi.pid" ] && kill $(cat "/var/airport/uwsgi.pid") diff --git a/airport/stop-game b/airport/stop-game new file mode 100755 index 0000000..68d2d6e --- /dev/null +++ b/airport/stop-game @@ -0,0 +1,13 @@ +#!/bin/sh +# this should be run as the airport user + +PYTHON=python +PYTHONPATH=/var/airport ; export PYTHONPATH +DJANGO_SETTINGS_MODULE="etc.settings" ; export DJANGO_SETTINGS_MODULE + +game_id=$1 +cd ~ +. bin/activate +cd djangoproject + +$PYTHON manage.py gameserver --forcequit $1 diff --git a/airport/zzairport.start b/airport/zzairport.start deleted file mode 100755 index 5bfd2e8..0000000 --- a/airport/zzairport.start +++ /dev/null @@ -1,17 +0,0 @@ -#!/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