From 0b9af34003489e33a561f42a2186a59effd4dc1f Mon Sep 17 00:00:00 2001 From: Alpha Chen Date: Fri, 6 Feb 2015 17:18:10 -0800 Subject: [PATCH] [meta] Set up EC2 for hosting TiddlyWiki --- .ssh/config | 4 ++++ ansible/ec2.yml | 17 +++++++++++++++++ ansible/tiddlywiki/handlers.yml | 3 +++ ansible/tiddlywiki/nginx.conf | 8 ++++++++ ansible/tiddlywiki/tasks.yml | 16 ++++++++++++++++ ansible/tiddlywiki/upstart.conf.j2 | 12 ++++++++++++ 6 files changed, 60 insertions(+) create mode 100644 ansible/ec2.yml create mode 100644 ansible/tiddlywiki/handlers.yml create mode 100644 ansible/tiddlywiki/nginx.conf create mode 100644 ansible/tiddlywiki/tasks.yml create mode 100644 ansible/tiddlywiki/upstart.conf.j2 diff --git a/.ssh/config b/.ssh/config index d2a6fa5..3396b91 100644 --- a/.ssh/config +++ b/.ssh/config @@ -31,5 +31,9 @@ Host home.kejadlen.net Host chime.prgmr.com User kejadlen +Host *.amazonaws.com + User ubuntu + IdentityFile ~/.ssh/aws.pem + Host 127.0.0.1 StrictHostKeyChecking no diff --git a/ansible/ec2.yml b/ansible/ec2.yml new file mode 100644 index 0000000..b0ccd1a --- /dev/null +++ b/ansible/ec2.yml @@ -0,0 +1,17 @@ +- hosts: ec2 + vars: + user: ubuntu + group: ubuntu + tasks: + - apt: update_cache=yes + sudo: true + - apt: name=nginx state=present + sudo: true + - file: path=/etc/nginx/sites-enabled/default state=absent + sudo: true + notify: reload nginx + - include: tiddlywiki/tasks.yml + handlers: + - name: reload nginx + service: name=nginx state=reloaded + - include: tiddlywiki/handlers.yml diff --git a/ansible/tiddlywiki/handlers.yml b/ansible/tiddlywiki/handlers.yml new file mode 100644 index 0000000..eebf992 --- /dev/null +++ b/ansible/tiddlywiki/handlers.yml @@ -0,0 +1,3 @@ +- name: restart tiddlywiki + service: name=tiddlywiki state=restarted + sudo: true diff --git a/ansible/tiddlywiki/nginx.conf b/ansible/tiddlywiki/nginx.conf new file mode 100644 index 0000000..9d5270b --- /dev/null +++ b/ansible/tiddlywiki/nginx.conf @@ -0,0 +1,8 @@ +server { + listen 80; + + location / { + proxy_pass http://localhost:8080; + proxy_set_header X-Forwarded-Host $host; + } +} diff --git a/ansible/tiddlywiki/tasks.yml b/ansible/tiddlywiki/tasks.yml new file mode 100644 index 0000000..4cc07eb --- /dev/null +++ b/ansible/tiddlywiki/tasks.yml @@ -0,0 +1,16 @@ +- include_vars: tiddlywiki/vars.yml.private +- apt: name={{ item }} state=present + sudo: true + with_items: + - nodejs + - nodejs-legacy + - npm +- npm: name=tiddlywiki global=yes state=present + sudo: true +- file: path=~/tiddlywiki state=directory +- copy: src=tiddlywiki/nginx.conf dest=/etc/nginx/conf.d/tiddlywiki.conf + sudo: true + notify: reload nginx +- template: src=tiddlywiki/upstart.conf.j2 dest=/etc/init/tiddlywiki.conf + sudo: true + notify: restart tiddlywiki diff --git a/ansible/tiddlywiki/upstart.conf.j2 b/ansible/tiddlywiki/upstart.conf.j2 new file mode 100644 index 0000000..71bd6ff --- /dev/null +++ b/ansible/tiddlywiki/upstart.conf.j2 @@ -0,0 +1,12 @@ +description "TiddlyWiki" +author "Alpha Chen" + +start on started network-services +stop on stopping network-services + +setuid {{ user }} +setgid {{ group }} + +console log + +exec tiddlywiki /home/{{ user }}/tiddlywiki --server 8080 $:/core/save/all text/plain text/html alpha "{{ password }}"