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