#36 an entry point for Gunicorn and systemd unit files
Merged 6 years ago by mjia. Opened 7 years ago by mjia.
mjia/waiverdb master  into  master

file modified
+1
@@ -7,5 +7,6 @@ 

  include tox.ini

  include runapp.py

  include fedmsg.d/*.py

+ recursive-include systemd *

  recursive-include conf *

  recursive-include docs *.py *.rst Makefile

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

@@ -0,0 +1,8 @@ 

+ [Unit]

+ Description=WaiverDB Socket

+ 

+ [Socket]

+ ListenStream=/run/waiverdb/socket

+ 

+ [Install]

+ WantedBy=sockets.target

file modified
+23
@@ -21,6 +21,8 @@ 

  BuildRequires:  pytest

  BuildRequires:  fedmsg

  BuildRequires:  python-flask-oidc

+ %{?systemd_requires}

+ BuildRequires:  systemd

  BuildArch:      noarch

  Requires:       python-flask

  Requires:       python-sqlalchemy
@@ -42,6 +44,13 @@ 

  

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

  %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

file added
+16
@@ -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)

+ 

This will allow us to use systemd to create a unix socket for incoming Gunicorn requests when deploying.

@mjia what was the thought process of using Gunicorn over Apache + mod_wsgi? With Apache you wouldn't have to deal with systemd unit files. I suppose Apache is rather heavy for a container deployment, but you wouldn't be using systemd in a container anyways.

I'd vote for Apache + mod_wsgi simply because it's what we use in every other Fedora app (that I'm aware of)

There was some discussion of this in #34 ... @mjia can you make your commit message reference that issue please.

I am completely on the fence about whether we should or should not ship a systemd unit in waiverdb itself (vs. install one by Ansible). You are right that in OpenShift the systemd unit will not be used. It will run gunicorn inside the container directly as pid 1.

The commit message has been updated. I have successfully deployed the internal dev server with nginx + Guncorn + systemd as a chance of learning.

As jcline said, I guess we should use Apache + mod_wsgi to keep the consistency.

2 new commits added

  • systemd unit files
  • add the entry point for Gunicorn
7 years ago

rebased

6 years ago

We are shipping two units (the .socket and the .service) so both need to be mentioned here. Same for %systemd_preun.

It doesn't make sense to restart a .socket unit, we actually want to restart just the .service.

rebased

6 years ago

2 new commits added

  • systemd unit files
  • add the entry point for Gunicorn
6 years ago

This is ready to review again.

Typo, should be %systemd_preun

2 new commits added

  • systemd unit files
  • add the entry point for Gunicorn
6 years ago

The typo is fixed. :-)

Pull-Request has been merged by mjia

6 years ago