airport: updates

This commit is contained in:
Albert Hopkins 2015-12-12 21:42:37 +00:00
parent c907bdf048
commit 6dbe6c0b98
10 changed files with 67 additions and 78 deletions

View File

@ -1,43 +1,39 @@
APP_ROOT := /var/airport
APP_ROOT := /var/lib/airport
AIRPORT_REPO ?= https://bitbucket.org/marduk/airport
AIRPORT_BRANCH ?= default
AIRPORT_BRANCH ?= stable
PGVER := 9.4
preinstall:
postinstall: airport.service settings.py local.start local.stop issue nginx.conf start-airport stop-airport stop-game
postinstall: airport.service settings.py issue nginx.conf airport-pre.service airport-gameserver.service airport-wsgi.service
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)
$(inroot) bash -c "echo y |$(EMERGE) --config postgresql:$(PGVER)"
$(inroot) systemctl enable postgresql-$(PGVER)
$(inroot) $(EMERGE) --oneshot --noreplace $(USEPKG) dev-python/virtualenv
$(inroot) $(EMERGE) --oneshot --noreplace $(USEPKG) dev-python/setuptools dev-python/virtualenv
rm -rf $(CHROOT)/$(APP_ROOT)
hg clone -u $(AIRPORT_BRANCH) $(AIRPORT_REPO) $(CHROOT)/$(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
cp settings.py $(CHROOT)/$(APP_ROOT)/djangoproject/djangoproject
$(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 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
cat settings_$(AIRPORT_SERIES).py >> $(CHROOT)/$(APP_ROOT)/djangoproject/djangoproject/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 -u airport-pre.service $(CHROOT)/etc/systemd/system/airport-pre.service
cp -u airport-wsgi.service $(CHROOT)/etc/systemd/system/airport-wsgi.service
cp -u airport-gameserver.service $(CHROOT)/etc/systemd/system/airport-gameserver.service
$(M4) -D HOSTNAME=$(HOSTNAME) nginx.conf > $(CHROOT)/etc/nginx/nginx.conf
$(inroot) gpasswd -a nginx airport
$(inroot) systemctl enable nginx
$(inroot) systemctl enable airport-wsgi.service
$(inroot) systemctl enable airport-gameserver.service
ifeq ($(AVAHI),YES)
$(inroot) $(EMERGE) --noreplace $(USEPKG) net-dns/avahi
$(inroot) rm -f /etc/avahi/services/*

View File

@ -0,0 +1,16 @@
[Unit]
Description=Airport Game Server
Documentation=https://bitbucket.org/marduk/airport/
Requires=airport-pre.service
After=airport-pre.service
After=airport-wsgi.service
[Service]
User=airport
Environment=PYTHONPATH=/var/lib/airport/djangoproject
Environment=DJANGO_SETTINGS_MODULE=djangoproject.settings
WorkingDirectory=/var/lib/airport
ExecStart=/var/lib/airport/bin/python djangoproject/manage.py gameserver --verbosity=2
[Install]
WantedBy=multi-user.target

View File

@ -0,0 +1,16 @@
[Unit]
Description=Airport (Pre)
Documentation=https://bitbucket.org/marduk/airport/
Requires=postgresql-9.4.service
After=postgresql-9.4.service
[Service]
Type=oneshot
User=airport
Environment=PYTHONPATH=/var/lib/airport/djangoproject
Environment=DJANGO_SETTINGS_MODULE=djangoproject.settings
WorkingDirectory=/var/lib/airport
ExecStart=-/usr/bin/createuser -U postgres -D -S -R airport
ExecStart=-/usr/bin/createdb -U postgres airport
ExecStart=/var/lib/airport/bin/python djangoproject/manage.py migrate auth --noinput
ExecStart=/var/lib/airport/bin/python djangoproject/manage.py migrate --noinput

View File

@ -0,0 +1,22 @@
[Unit]
Description=Airport WSGI Server
Documentation=https://bitbucket.org/marduk/airport/
Requires=airport-pre.service
After=airport-pre.service
Wants=nginx.service
[Service]
Type=notify
User=airport
WorkingDirectory=/var/lib/airport
Environment=PYTHONPATH=/var/lib/airport/djangoproject
Environment=DJANGO_SETTINGS_MODULE=djangoproject.settings
ExecStart=/var/lib/airport/bin/uwsgi --master -p 4 \
--socket=/var/lib/airport/airport.sock \
--chmod=660 -w djangoproject.wsgi --uid=airport --gid=airport \
--pidfile=/var/lib/airport/airport.pid
PIDFile=/var/lib/airport/airport.pid
KillSignal=SIGQUIT
[Install]
WantedBy=multi-user.target

View File

@ -1,11 +0,0 @@
#!/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

View File

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

View File

@ -50,11 +50,11 @@ http {
server_name HOSTNAME;
location /static/ {
alias /var/airport/djangoproject/airport/static/;
alias /var/lib/airport/djangoproject/airport/static/;
}
location / {
uwsgi_pass unix:///var/airport/airport.sock;
uwsgi_pass unix:///var/lib/airport/airport.sock;
include /etc/nginx/uwsgi_params;
}

View File

@ -1,29 +0,0 @@
#!/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"

View File

@ -1,5 +0,0 @@
#!/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")

View File

@ -1,13 +0,0 @@
#!/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