diff --git a/appliances/airport/Makefile b/appliances/airport/Makefile index 5768d1a..761cc5e 100644 --- a/appliances/airport/Makefile +++ b/appliances/airport/Makefile @@ -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/* diff --git a/appliances/airport/airport-gameserver.service b/appliances/airport/airport-gameserver.service new file mode 100644 index 0000000..ee22832 --- /dev/null +++ b/appliances/airport/airport-gameserver.service @@ -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 diff --git a/appliances/airport/airport-pre.service b/appliances/airport/airport-pre.service new file mode 100644 index 0000000..e9aafb9 --- /dev/null +++ b/appliances/airport/airport-pre.service @@ -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 diff --git a/appliances/airport/airport-wsgi.service b/appliances/airport/airport-wsgi.service new file mode 100644 index 0000000..732ea37 --- /dev/null +++ b/appliances/airport/airport-wsgi.service @@ -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 diff --git a/appliances/airport/local.start b/appliances/airport/local.start deleted file mode 100755 index 1c1986f..0000000 --- a/appliances/airport/local.start +++ /dev/null @@ -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 diff --git a/appliances/airport/local.stop b/appliances/airport/local.stop deleted file mode 100755 index be94b1d..0000000 --- a/appliances/airport/local.stop +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh - -su -c "/var/airport/bin/stop-airport" airport diff --git a/appliances/airport/nginx.conf b/appliances/airport/nginx.conf index a40720c..3dd9989 100644 --- a/appliances/airport/nginx.conf +++ b/appliances/airport/nginx.conf @@ -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; } diff --git a/appliances/airport/start-airport b/appliances/airport/start-airport deleted file mode 100755 index bff854f..0000000 --- a/appliances/airport/start-airport +++ /dev/null @@ -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" diff --git a/appliances/airport/stop-airport b/appliances/airport/stop-airport deleted file mode 100755 index 1ce2050..0000000 --- a/appliances/airport/stop-airport +++ /dev/null @@ -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") diff --git a/appliances/airport/stop-game b/appliances/airport/stop-game deleted file mode 100755 index 68d2d6e..0000000 --- a/appliances/airport/stop-game +++ /dev/null @@ -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