Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch from Passenger to gunicorn. #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 44 additions & 2 deletions roles/web/files/bronytv.conf
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
upstream btv {
server localhost:8000 fail_timeout=0;
}

server {
listen 80 default_server;

Expand All @@ -10,7 +14,26 @@ server {
access_log /var/log/nginx/bronytv_access.log;
error_log /var/log/nginx/bronytv_error.log;
root /var/www/bronytv/public;
passenger_enabled on;

location / {
try_files $uri @btv_app;
}

location @btv_app {
include proxy_params;
proxy_redirect off;
proxy_pass http://btv;
}

location /socket.io {
include proxy_params;
proxy_http_version 1.1;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://btv/socket.io;
}

location ^~ /.well-known/acme-challenge/ {
root /var/www/letsencrypt/;
Expand Down Expand Up @@ -43,7 +66,26 @@ server {
server_name bronytv.net www.bronytv.net;

root /var/www/bronytv/public;
passenger_enabled on;

location / {
try_files $uri @btv_app;
}

location @btv_app {
include proxy_params;
proxy_redirect off;
proxy_pass http://btv;
}

location /socket.io {
include proxy_params;
proxy_http_version 1.1;
proxy_redirect off;
proxy_buffering off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_pass http://btv/socket.io;
}

location ^~ /.well-known/acme-challenge/ {
root /var/www/letsencrypt/;
Expand Down
19 changes: 19 additions & 0 deletions roles/web/files/btv-gunicorn.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[Unit]
Description=BronyTV gunicorn daemon
After=network.target

[Service]
PIDFile=/run/btv-gunicorn/pid
User=www-data
Group=www-data
RuntimeDirectory=btv-gunicorn
WorkingDirectory=/var/www/bronytv
ExecStart=/usr/local/bin/gunicorn --pid /run/btv-gunicorn/pid \
--bind localhost:8000 -k eventlet -w 1 passenger_wsgi
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s TERM $MAINPID
PrivateTmp=true
Restart=on-failure

[Install]
WantedBy=multi-user.target nginx.service
2 changes: 0 additions & 2 deletions roles/web/files/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ events {
}

http {
passenger_root /usr/lib/ruby/vendor_ruby/phusion_passenger/locations.ini;
passenger_ruby /usr/bin/passenger_free_ruby;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
Expand Down
14 changes: 9 additions & 5 deletions roles/web/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
- name: Add Phusion APT key
apt_key: keyserver=keyserver.ubuntu.com id=561F9B9CAC40B2F7
- name: Add Phusion Repository
apt_repository: repo='deb https://oss-binaries.phusionpassenger.com/apt/passenger xenial main'
- name: Update APT cache
apt: update_cache=yes
- name: Install required APT packages
apt: name={{ item }} state=latest
with_items:
- nginx
- passenger
- python
- python-dev
- libpq-dev
Expand All @@ -22,10 +17,13 @@
with_items:
- flask
- flask-sqlalchemy
- flask-socketio
- psycopg2
- requests
- bcrypt
- alembic
- gunicorn
- eventlet
- flask-assets
- cssmin
- jsmin
Expand All @@ -36,6 +34,8 @@
copy: src=nginx.conf dest=/etc/nginx/nginx.conf owner=root group=root mode=0660
- name: Copy nginx vhost
copy: src=bronytv.conf dest=/etc/nginx/sites-enabled/bronytv owner=root group=root mode=0660
- name: Copy gunicorn service
copy: src=btv-gunicorn.service dest=/etc/systemd/system/btv-gunicorn.service owner=root group=root mode=0660
- name: Create website directory
file: name=/var/www/bronytv state=directory owner=www-data group=www-data mode=0770

Expand All @@ -51,6 +51,10 @@
- name: Run Alembic migrations
command: /usr/local/bin/alembic upgrade head chdir=/var/www/bronytv

- name: Reload services
systemd: daemon_reload=yes
- name: Enable gunicorn
systemd: name=btv-gunicorn.service enabled=yes state=restarted
- name: Restart nginx
service: name=nginx enabled=yes state=restarted