From 7710c5d15bbb84b22dc9d19333735cdb24de8a08 Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Sun, 1 Nov 2015 21:05:59 +0000 Subject: [PATCH] First draft of a statscache/frontend role. --- playbooks/groups/statscache.yml | 2 +- .../statscache/frontend/files/statscache.wsgi | 8 ++ roles/statscache/frontend/tasks/main.yml | 74 +++++++++++++++++++ .../frontend/templates/statscache.cfg | 2 + .../frontend/templates/statscache.conf | 17 +++++ .../frontend/templates/statscache.py | 37 ++++++++++ 6 files changed, 139 insertions(+), 1 deletion(-) create mode 100644 roles/statscache/frontend/files/statscache.wsgi create mode 100644 roles/statscache/frontend/tasks/main.yml create mode 100644 roles/statscache/frontend/templates/statscache.cfg create mode 100644 roles/statscache/frontend/templates/statscache.conf create mode 100644 roles/statscache/frontend/templates/statscache.py diff --git a/playbooks/groups/statscache.yml b/playbooks/groups/statscache.yml index e94d1e2d70..452a5e8b6b 100644 --- a/playbooks/groups/statscache.yml +++ b/playbooks/groups/statscache.yml @@ -47,7 +47,7 @@ - apache - role: openvpn/client when: env != "staging" - # TODO -- include statscache/frontend here + - statscache/frontend tasks: - include: "{{ tasks }}/mod_wsgi.yml" diff --git a/roles/statscache/frontend/files/statscache.wsgi b/roles/statscache/frontend/files/statscache.wsgi new file mode 100644 index 0000000000..16bff2b9cc --- /dev/null +++ b/roles/statscache/frontend/files/statscache.wsgi @@ -0,0 +1,8 @@ +# http://stackoverflow.com/questions/8007176/500-error-without-anything-in-the-apache-logs +import logging +import sys +logging.basicConfig(stream=sys.stderr) + +import statscache.app +application = statscache.app.app +#application.debug = True # Nope. Be careful! diff --git a/roles/statscache/frontend/tasks/main.yml b/roles/statscache/frontend/tasks/main.yml new file mode 100644 index 0000000000..b10f64c33a --- /dev/null +++ b/roles/statscache/frontend/tasks/main.yml @@ -0,0 +1,74 @@ +--- +# Configuration for the Fedora Notifications webapp + +- name: install needed packages + yum: pkg={{ item }} state=present + with_items: + - statscache-web + - python-psycopg2 + - libsemanage-python + notify: + - restart apache + tags: + - statscache + - statscache/frontend + +- name: copy statscache app configuration + template: > + src={{ item }} dest=/etc/fedmsg.d/{{ item }} + owner=apache group=apache mode=0600 + with_items: + - statscache.py + notify: + - restart apache + tags: + - statscache + - statscache/frontend + +- name: copy statscache httpd config + template: > + src=statscache.conf dest=/etc/httpd/conf.d/statscache.conf + owner=apache group=apache mode=0644 + notify: + - restart apache + tags: + - statscache + - statscache/frontend + +- name: copy custom wsgi file + copy: src=statscache.wsgi dest=/usr/share/statscache/apache/statscache.wsgi mode=0644 + notify: + - restart apache + tags: + - statscache + - statscache/frontend + +- name: copy app configuration + template: > + src=statscache.cfg dest=/etc/statscache.cfg + owner=root group=apache mode=0640 + notify: + - restart apache + tags: + - statscache + - statscache/frontend + +- name: apply selinux type to static files + file: > + dest=/usr/share/statscache/static + setype=httpd_sys_content_t + state=directory + recurse=yes + tags: + - statscache + - statscache/frontend + - selinux + +- name: ensure selinux lets httpd talk to postgres + seboolean: name={{item}} state=yes persistent=yes + with_items: + - httpd_can_network_connect_db + tags: + - statscache + - statscache/frontend + - selinux diff --git a/roles/statscache/frontend/templates/statscache.cfg b/roles/statscache/frontend/templates/statscache.cfg new file mode 100644 index 0000000000..bf543daa66 --- /dev/null +++ b/roles/statscache/frontend/templates/statscache.cfg @@ -0,0 +1,2 @@ +### Secret key for the Flask application +SECRET_KEY='{{statscache_secret_key}}' diff --git a/roles/statscache/frontend/templates/statscache.conf b/roles/statscache/frontend/templates/statscache.conf new file mode 100644 index 0000000000..5090d392dd --- /dev/null +++ b/roles/statscache/frontend/templates/statscache.conf @@ -0,0 +1,17 @@ +LoadModule wsgi_module modules/mod_wsgi.so + +WSGIPythonEggs /var/cache/statscache/.python-eggs +WSGIDaemonProcess statscache user=apache group=apache maximum-requests=50000 display-name=statscache processes=4 threads=4 inactivity-timeout=300 +WSGISocketPrefix run/wsgi +WSGIRestrictStdout Off +WSGIRestrictSignal Off +WSGIPythonOptimize 1 + +WSGIScriptAlias / /usr/share/statscache/apache/statscache.wsgi + +Alias /static/ /usr/lib/python2.7/site-packages/statscache/static/ + + + Order deny,allow + Allow from all + diff --git a/roles/statscache/frontend/templates/statscache.py b/roles/statscache/frontend/templates/statscache.py new file mode 100644 index 0000000000..0363e2dcf2 --- /dev/null +++ b/roles/statscache/frontend/templates/statscache.py @@ -0,0 +1,37 @@ +import datetime + + +config = { + "statscache.datagrepper.profile": False, + + # Consumer stuff + "statscache.consumer.enabled": False, + + "statscache.sqlalchemy.uri": "postgres://statscache:{{statscache_db_password}}@db01/statscache", + + # stats models will go back at least this far (current value arbitrary) + "statscache.consumer.epoch": datetime.datetime(year=2015, month=8, day=8), + + # stats models are updated at this frequency + "statscache.producer.frequency": datetime.timedelta(seconds=1), + + # Configuration of web API + "statscache.app.maximum_rows_per_page": 100, + "statscache.app.default_rows_per_page": 100, + + # Turn on logging for statscache + "logging": dict( + loggers=dict( + statscache={ + "level": "DEBUG", + "propagate": False, + "handlers": ["console"], + }, + statscache_plugins={ + "level": "DEBUG", + "propagate": False, + "handlers": ["console"], + }, + ), + ), +}