From 890ed5bd035f3ac3a9809f39388624c41c3a12ac Mon Sep 17 00:00:00 2001 From: Matt Jia Date: May 03 2017 05:11:42 +0000 Subject: [PATCH 1/2] add the entry point for Gunicorn This will allow us to run waiverdb with Gunicorn: gunicorn -b 0.0.0.0:5004 waiverdb.wsgi:app --- diff --git a/waiverdb/wsgi.py b/waiverdb/wsgi.py new file mode 100644 index 0000000..5038188 --- /dev/null +++ b/waiverdb/wsgi.py @@ -0,0 +1,16 @@ + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# + +from waiverdb.app import create_app, init_db +app = create_app() +init_db(app) + From bf5fb48e4bbbb41651ee4eab17cc7dee62392e92 Mon Sep 17 00:00:00 2001 From: Matt Jia Date: May 03 2017 05:39:35 +0000 Subject: [PATCH 2/2] systemd unit files They are configuration files for using systemd to create a unix socket when using Gunicorn to deploy. See more discussions in https://pagure.io/waiverdb/issue/34 --- diff --git a/MANIFEST.in b/MANIFEST.in index f374432..73382b0 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -7,5 +7,6 @@ include tests/*.py tests/client_secrets.json include tox.ini include runapp.py include fedmsg.d/*.py +recursive-include systemd * recursive-include conf * recursive-include docs *.py *.rst Makefile diff --git a/systemd/waiverdb.service b/systemd/waiverdb.service new file mode 100644 index 0000000..085cc42 --- /dev/null +++ b/systemd/waiverdb.service @@ -0,0 +1,11 @@ +[Unit] +Description=WaiverDB Daemon +Requires=waiverdb.socket +After=network.target + +[Service] +ExecStart=/usr/bin/gunicorn --bind unix:/run/waiverdb/socket \ + waiverdb.wsgi:app + +[Install] +WantedBy=multi-user.target diff --git a/systemd/waiverdb.socket b/systemd/waiverdb.socket new file mode 100644 index 0000000..6b8fcf8 --- /dev/null +++ b/systemd/waiverdb.socket @@ -0,0 +1,8 @@ +[Unit] +Description=WaiverDB Socket + +[Socket] +ListenStream=/run/waiverdb/socket + +[Install] +WantedBy=sockets.target diff --git a/waiverdb.spec b/waiverdb.spec index e943a2b..406b986 100644 --- a/waiverdb.spec +++ b/waiverdb.spec @@ -21,6 +21,8 @@ BuildRequires: python-mock BuildRequires: pytest BuildRequires: fedmsg BuildRequires: python-flask-oidc +%{?systemd_requires} +BuildRequires: systemd BuildArch: noarch Requires: python-flask Requires: python-sqlalchemy @@ -42,6 +44,13 @@ WaiverDB is a companion service to ResultsDB, for recording waivers against test %install %py2_install +install -d %{buildroot}%{_sysconfdir}/waiverdb +install -p -m 0644 conf/settings.py.example %{buildroot}%{_sysconfdir}/waiverdb/settings.py +install -d %{buildroot}%{_unitdir} +install -m0644 \ + systemd/%{name}.service \ + systemd/%{name}.socket \ + %{buildroot}%{_unitdir} %check export PYTHONPATH=%{buildroot}/%{python2_sitelib} @@ -52,5 +61,19 @@ py.test tests/ %doc README.md conf docs %{python2_sitelib}/%{name} %{python2_sitelib}/%{name}*.egg-info +%{_sysconfdir}/waiverdb +%{_unitdir}/%{name}.service +%{_unitdir}/%{name}.socket + +%post +%systemd_post %{name}.service +%systemd_post %{name}.socket + +%preun +%systemd_preun %{name}.service +%systemd_preun %{name}.socket + +%postun +%systemd_postun_with_restart %{name}.service %changelog