airport: Misc. Updates.

* Allow to build a particular series (e.g. Airport Europe)

* Refactor start/stop scripts.

* Add script for stopping a game.
This commit is contained in:
Albert Hopkins 2014-01-11 15:05:38 +00:00
parent 85b47adf35
commit af18cc6c91
11 changed files with 91 additions and 37 deletions

View File

@ -8,7 +8,7 @@ rcdefault := /etc/runlevels/default
preinstall: 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) 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) $(inroot) eselect postgresql set $(PGVER)
rm -rf $(CHROOT)/var/lib/postgresql/$(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 $(inroot) $(EMERGE) -1n $(USEPKG) dev-python/virtualenv
rm -rf $(CHROOT)/$(APP_ROOT) rm -rf $(CHROOT)/$(APP_ROOT)
hg clone -u $(AIRPORT_BRANCH) $(AIRPORT_REPO) $(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 $(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 -r $(APP_ROOT)/requirements.txt"
$(inroot) bash -c ". $(APP_ROOT)/bin/activate ; pip install psycopg2 uwsgi" $(inroot) bash -c ". $(APP_ROOT)/bin/activate ; pip install psycopg2 uwsgi"
mkdir -p $(CHROOT)/$(APP_ROOT)/etc mkdir -p $(CHROOT)/$(APP_ROOT)/etc
touch $(CHROOT)/$(APP_ROOT)/etc/__init__.py touch $(CHROOT)/$(APP_ROOT)/etc/__init__.py
cp settings.py $(CHROOT)/$(APP_ROOT)/etc 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) $(inroot) chown -R airport:airport $(APP_ROOT)
cp firstboot.start $(CHROOT)/etc/local.d cp local.start $(CHROOT)/etc/local.d/airport.start
cp zzairport.start $(CHROOT)/etc/local.d 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 cp issue $(CHROOT)/etc/issue
$(M4) -D HOSTNAME=$(HOSTNAME) nginx.conf > $(CHROOT)/etc/nginx/nginx.conf $(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 $(inroot) ln -sf /etc/init.d/nginx $(rcdefault)/nginx
ifeq ($(AVAHI),YES) ifeq ($(AVAHI),YES)
$(inroot) $(EMERGE) -n $(USEPKG) net-dns/avahi $(inroot) $(EMERGE) -n $(USEPKG) net-dns/avahi

View File

@ -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

11
airport/local.start Executable file
View File

@ -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

3
airport/local.stop Executable file
View File

@ -0,0 +1,3 @@
#!/bin/sh
su -c "/var/airport/bin/stop-airport" airport

View File

@ -9,5 +9,6 @@ sys-fs/udev openrc
sys-kernel/gentoo-sources symlink sys-kernel/gentoo-sources symlink
sys-libs/ncurses minimal sys-libs/ncurses minimal
sys-apps/portage python3 ipc sys-apps/portage python3 ipc
sys-apps/openrc netifrc
www-servers/nginx http www-servers/nginx http

View File

@ -98,6 +98,7 @@ TEMPLATE_CONTEXT_PROCESSORS = (
'django.contrib.auth.context_processors.auth', 'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages', 'django.contrib.messages.context_processors.messages',
'airport.context_processors.externals', 'airport.context_processors.externals',
'airport.context_processors.game_name',
) )
MIDDLEWARE_CLASSES = ( MIDDLEWARE_CLASSES = (
@ -150,4 +151,6 @@ LOGGING = {
} }
} }
AUTH_PROFILE_MODULE = 'airport.UserProfile' AIRPORT = {
'GAMESERVER_MULTIPROCESSING': True,
}

View File

@ -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,
}

29
airport/start-airport Executable file
View File

@ -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"

5
airport/stop-airport Executable file
View File

@ -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")

13
airport/stop-game Executable file
View File

@ -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

View File

@ -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