From 8387a5390f444d6a76f03b39eda8d906a267f87e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=A4ber?= Date: Thu, 19 Feb 2015 13:21:57 +0100 Subject: [PATCH 1/9] Replace vagrant shell provisioning with ansible --- Vagrantfile | 57 ++++-------- .../files/apache.conf | 1 - ansible/files/nginx.conf | 39 ++++++++ ansible/files/nginx.vhost.conf | 12 +++ ansible/files/uwsgi.ini | 19 ++++ ansible/site.yml | 88 +++++++++++++++++++ share/isso-dev.conf | 4 +- 7 files changed, 176 insertions(+), 44 deletions(-) rename share/isso-dev.local.apache-conf => ansible/files/apache.conf (99%) create mode 100644 ansible/files/nginx.conf create mode 100644 ansible/files/nginx.vhost.conf create mode 100644 ansible/files/uwsgi.ini create mode 100644 ansible/site.yml diff --git a/Vagrantfile b/Vagrantfile index 22fbb9b..ea19fee 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -4,9 +4,10 @@ # This is the Vagrant config file for setting up an environment for Isso development. # It requires: # -# * Vagrant (http://vagrantup.com) -# * A VM engine, like VirtualBox (http://virtualbox.org) +# * Vagrant (https://vagrantup.com) +# * A VM engine, like VirtualBox (https://virtualbox.org) # * The Vagrant-Hostmanager plugin (https://github.com/smdahlen/vagrant-hostmanager) +# * Ansible (https://www.ansible.com) # # With them installed, cd into this directory and do 'vagrant up'. It's possible Vagrant will # ask for your root password so it can update your /etc/hosts file. Once it's happily churning out @@ -17,47 +18,17 @@ # to get into the VM. Useful info about it: # # * Running Ubuntu 14.04 -# * Isso is running on uWSGI via port 8080 -# * Actual webserver is Apache2, using mod_proxy_uwsgi to talk to uWSGI -# * uWSGI log file is /tmp/uwsgi.log -# * Isso DB file is /tmp/isso/comments.db -# * Isso log file is /tmp/isso/isso.log +# * Isso is running on uWSGI +# * Actual webserver is Nginx to talk to uWSGI over a unix socket +# * uWSGI log file is /var/log/uwsgi/apps/isso.log +# * Isso DB file is /var/isso/comments.db +# * Isso log file is /var/log/isso.log +# +# When the VM is getting rebooted vagrant mounts the shared folder after uWSGI is getting startet. To fix this issue for +# the moment you need to 'vagrant ssh' into the VM and execute 'sudo service uwsgi restart'. # # Enjoy! -$bootstrap = < # vim: syntax=apache ts=4 sw=4 sts=4 sr noet diff --git a/ansible/files/nginx.conf b/ansible/files/nginx.conf new file mode 100644 index 0000000..8243109 --- /dev/null +++ b/ansible/files/nginx.conf @@ -0,0 +1,39 @@ +user root; +worker_processes 4; +worker_rlimit_nofile 8192; + +error_log /var/log/nginx/error.log warn; +pid /run/nginx.pid; + +events { + worker_connections 2014; + multi_accept on; + use epoll; +} + +http { + include /etc/nginx/mime.types; + default_type application/octet-stream; + + log_format main '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for"'; + + log_format timed '$remote_addr - $remote_user [$time_local] "$request" ' + '$status $body_bytes_sent "$http_referer" ' + '"$http_user_agent" "$http_x_forwarded_for" ' + '$request_time $upstream_response_time $upstream_addr ' + ' $upstream_status $upstream_cache_status $pipe'; + + access_log /var/log/nginx/access.log timed; + + sendfile on; + tcp_nopush on; + + keepalive_timeout 30; + + gzip on; + + include /etc/nginx/conf.d/*.conf; + include /etc/nginx/sites-enabled/*; +} diff --git a/ansible/files/nginx.vhost.conf b/ansible/files/nginx.vhost.conf new file mode 100644 index 0000000..eb68148 --- /dev/null +++ b/ansible/files/nginx.vhost.conf @@ -0,0 +1,12 @@ +server { + client_max_body_size 20M; + listen 80 default_server; + server_name isso-dev.local; + + root /vagrant/isso/demo; + + location / { + uwsgi_pass unix:///run/uwsgi/app/isso/socket; + include uwsgi_params; + } +} \ No newline at end of file diff --git a/ansible/files/uwsgi.ini b/ansible/files/uwsgi.ini new file mode 100644 index 0000000..d286e1c --- /dev/null +++ b/ansible/files/uwsgi.ini @@ -0,0 +1,19 @@ +[uwsgi] +plugins = python + +venv = /home/vagrant/virtualenv +chdir = /vagrant + +uid = root +gid = root + +master = true +processes = 4 +cache2 = name=hash,items=10240,blocksize=32 +spooler = /var/isso/spool +module = isso.run +env = ISSO_SETTINGS=/vagrant/share/isso-dev.conf +env = PYTHON_EGG_CACHE=/tmp + +daemonize = /var/log/uwsgi/uwsgi.log +py-autoreload = 1 diff --git a/ansible/site.yml b/ansible/site.yml new file mode 100644 index 0000000..5d98d01 --- /dev/null +++ b/ansible/site.yml @@ -0,0 +1,88 @@ +--- + +- name: Provision development server + hosts: all + sudo: true + tasks: + + - name: Apt | Add nodesource keys + apt_key: url=https://deb.nodesource.com/gpgkey/nodesource.gpg.key state=present + + - name: Apt | Add nodesource sources list deb + apt_repository: repo='deb https://deb.nodesource.com/node {{ ansible_distribution_release }} main' state=present + + - name: Apt | Add nodesource sources list deb src + apt_repository: repo='deb-src https://deb.nodesource.com/node {{ ansible_distribution_release }} main' state=present + + - name: Apt | Install packages + apt: pkg={{ item }} state=latest update_cache=true + with_items: + - build-essential + - curl + - htop + - vim + - git + - python-dev + - python-software-properties + - python-setuptools + - python-virtualenv + - python-pip + - nginx + - uwsgi + - uwsgi-plugin-python + - supervisor + - sqlite3 + - nodejs + + - name: NPM | Install packages + npm: name={{ item }} global=yes + with_items: + - bower + - requirejs + - uglify-js + - jade + + - name: Virtualenv | Create + shell: virtualenv "/home/vagrant/virtualenv" creates="/vagrant/virtualenv/bin/activate" + + - name: Virtualenv | Install python egg + shell: /home/vagrant/virtualenv/bin/python /vagrant/setup.py develop + + - name: Make + shell: cd /vagrant; {{ item }} + with_items: + - make init + - make js + + - name: Spool | Create directory + file: path=/var/isso/spool state=directory mode=0777 + + - name: uwsgi | Deploy configuration + copy: src=files/uwsgi.ini dest=/etc/uwsgi/apps-available/isso.ini + + - name: uwsgi | Enable app + file: src=/etc/uwsgi/apps-available/isso.ini dest=/etc/uwsgi/apps-enabled/isso.ini state=link + + - name: uwsgi | Restart service daemon + service: name=uwsgi state=restarted enabled=yes + + - name: uwsgi | Chmod logfile + file: path=/var/log/uwsgi/uwsgi.log state=touch mode="a+r" + + - name: nginx | Deploy nginx.conf + copy: src=files/nginx.conf dest=/etc/nginx/nginx.conf + + - name: nginx | Delete default vhost + action: file path=/etc/nginx/sites-enabled/default state=absent + + - name: nginx | Deploy vhost config + copy: src=files/nginx.vhost.conf dest=/etc/nginx/sites-available/isso.conf + + - name: nginx | Enable vhost + file: src=/etc/nginx/sites-available/isso.conf dest=/etc/nginx/sites-enabled/000-isso state=link + + - name: nginx | Chmod logfile + file: path=/var/log/nginx mode="a+rx" state=directory recurse=true + + - name: nginx | Restart service daemon + service: name=nginx state=restarted enabled=yes diff --git a/share/isso-dev.conf b/share/isso-dev.conf index 9ccee84..ce87ab3 100644 --- a/share/isso-dev.conf +++ b/share/isso-dev.conf @@ -5,11 +5,11 @@ [general] -dbpath = /tmp/isso/comments.db +dbpath = /var/isso/comments.db host = http://isso-dev.local/ max-age = 15m notify = stdout -log-file = /tmp/isso/isso.log +log-file = /var/log/isso.log [moderation] enabled = false From 63c3e1252c4f7c67770f30347c222dd5bac5404e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=A4ber?= Date: Thu, 19 Feb 2015 13:22:04 +0100 Subject: [PATCH 2/9] Update gitignore --- .gitignore | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitignore b/.gitignore index 0d5ca9a..951b20b 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ *.pyc .Python .sass-cache +.vagrant +.idea /bin /include From 894086bda2545fc7d094def6f925b96905920992 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=A4ber?= Date: Thu, 19 Feb 2015 13:23:05 +0100 Subject: [PATCH 3/9] Fix catch socket timeout and error exceptions --- isso/utils/http.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/isso/utils/http.py b/isso/utils/http.py index 7a347c6..fa3cd9e 100644 --- a/isso/utils/http.py +++ b/isso/utils/http.py @@ -39,7 +39,10 @@ class curl(object): except (httplib.HTTPException, socket.error): return None - return self.con.getresponse() + try: + return self.con.getresponse() + except (socket.timeout, socket.error): + return None def __exit__(self, exc_type, exc_value, traceback): self.con.close() From 6deacf9527a7421cdc84471955d87b175d3899a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=A4ber?= Date: Thu, 19 Feb 2015 13:23:32 +0100 Subject: [PATCH 4/9] Update add myself to contributors list --- CONTRIBUTORS.txt | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 9b2d6a9..87004d8 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -43,6 +43,9 @@ In chronological order: * Matías Ducasa * Spanish translation - + +* Daniel Gräber + * Added ansible for provisioning + * [Your name or handle] <[email or website]> * [Brief summary of your changes] From 5a29d2742d14d24dc70f41f525afe3cc7a2aef3d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=A4ber?= Date: Thu, 19 Feb 2015 15:20:54 +0100 Subject: [PATCH 5/9] Remove virtualenv --- ansible/files/uwsgi.ini | 1 - ansible/site.yml | 8 ++------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/ansible/files/uwsgi.ini b/ansible/files/uwsgi.ini index d286e1c..75c4a4e 100644 --- a/ansible/files/uwsgi.ini +++ b/ansible/files/uwsgi.ini @@ -1,7 +1,6 @@ [uwsgi] plugins = python -venv = /home/vagrant/virtualenv chdir = /vagrant uid = root diff --git a/ansible/site.yml b/ansible/site.yml index 5d98d01..4f974ac 100644 --- a/ansible/site.yml +++ b/ansible/site.yml @@ -25,7 +25,6 @@ - python-dev - python-software-properties - python-setuptools - - python-virtualenv - python-pip - nginx - uwsgi @@ -42,11 +41,8 @@ - uglify-js - jade - - name: Virtualenv | Create - shell: virtualenv "/home/vagrant/virtualenv" creates="/vagrant/virtualenv/bin/activate" - - - name: Virtualenv | Install python egg - shell: /home/vagrant/virtualenv/bin/python /vagrant/setup.py develop + - name: Python | Install egg + shell: cd /vagrant; python setup.py develop - name: Make shell: cd /vagrant; {{ item }} From aea85f807f764331bcd8f1310fe993290ebe4230 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=A4ber?= Date: Thu, 19 Feb 2015 16:39:58 +0100 Subject: [PATCH 6/9] Edit uwsgi and nginx use tcp socket --- ansible/files/nginx.vhost.conf | 3 ++- ansible/files/uwsgi.ini | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/ansible/files/nginx.vhost.conf b/ansible/files/nginx.vhost.conf index eb68148..6e520e5 100644 --- a/ansible/files/nginx.vhost.conf +++ b/ansible/files/nginx.vhost.conf @@ -6,7 +6,8 @@ server { root /vagrant/isso/demo; location / { - uwsgi_pass unix:///run/uwsgi/app/isso/socket; + # uwsgi_pass unix:///run/uwsgi/app/isso/socket; + uwsgi_pass 127.0.0.1:8080; include uwsgi_params; } } \ No newline at end of file diff --git a/ansible/files/uwsgi.ini b/ansible/files/uwsgi.ini index 75c4a4e..f06094f 100644 --- a/ansible/files/uwsgi.ini +++ b/ansible/files/uwsgi.ini @@ -6,6 +6,8 @@ chdir = /vagrant uid = root gid = root +socket = :8080 + master = true processes = 4 cache2 = name=hash,items=10240,blocksize=32 From b37487dcef40a66c6e2aa58db45be7cc8f07a3ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=A4ber?= Date: Thu, 19 Feb 2015 16:40:46 +0100 Subject: [PATCH 7/9] Add comments for debugging --- Vagrantfile | 3 +++ ansible/files/uwsgi.ini | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index ea19fee..2693143 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -27,6 +27,9 @@ # When the VM is getting rebooted vagrant mounts the shared folder after uWSGI is getting startet. To fix this issue for # the moment you need to 'vagrant ssh' into the VM and execute 'sudo service uwsgi restart'. # +# For debugging with _pudb_ stop uWSGI service and start it manually +# 'sudo uwsgi --ini /etc/uwsgi/apps-available/isso.ini'. +# # Enjoy! Vagrant.configure(2) do |config| diff --git a/ansible/files/uwsgi.ini b/ansible/files/uwsgi.ini index f06094f..c40d601 100644 --- a/ansible/files/uwsgi.ini +++ b/ansible/files/uwsgi.ini @@ -16,5 +16,9 @@ module = isso.run env = ISSO_SETTINGS=/vagrant/share/isso-dev.conf env = PYTHON_EGG_CACHE=/tmp -daemonize = /var/log/uwsgi/uwsgi.log +# uncomment for debugging +# daemonize = /var/log/uwsgi/uwsgi.log py-autoreload = 1 + +# prevent uWSGI from remapping stdin to /dev/null +honour-stdin = true From 7725cfeefccfede1aff9967f8b734d81e68e6935 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=A4ber?= Date: Thu, 19 Feb 2015 17:59:11 +0100 Subject: [PATCH 8/9] Remove old apache conf --- ansible/files/apache.conf | 13 ------------- 1 file changed, 13 deletions(-) delete mode 100644 ansible/files/apache.conf diff --git a/ansible/files/apache.conf b/ansible/files/apache.conf deleted file mode 100644 index f96d01e..0000000 --- a/ansible/files/apache.conf +++ /dev/null @@ -1,13 +0,0 @@ - - ServerName isso-dev.local - - ServerAdmin webmaster@localhost - DocumentRoot /var/www/isso/ - - ErrorLog ${APACHE_LOG_DIR}/error.log - CustomLog ${APACHE_LOG_DIR}/access.log combined - - ProxyPass / uwsgi://127.0.0.1:8080/ - - -# vim: syntax=apache ts=4 sw=4 sts=4 sr noet From 09ad29aa818d633a32ad8c747551951b71d3969f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Gr=C3=A4ber?= Date: Thu, 19 Feb 2015 19:32:12 +0100 Subject: [PATCH 9/9] Remove .idea from gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index 951b20b..2596d41 100644 --- a/.gitignore +++ b/.gitignore @@ -9,7 +9,6 @@ .Python .sass-cache .vagrant -.idea /bin /include