Skip to content

Commit

Permalink
Merge pull request #7 from Fluxusio/mailcatch_upstart
Browse files Browse the repository at this point in the history
Mailcatch upstart
  • Loading branch information
yauh committed Mar 23, 2015
2 parents b8e0b48 + acce546 commit b8bbb58
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 40 deletions.
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Role-Mailcatcher
Mailcatcher
========

This role installs [Mailcatcher](http://mailcatcher.me) on your system and starts it upon boot time.
Expand All @@ -17,10 +17,6 @@ Role Variables
mailcatcher_http-ip: 0.0.0.0 # Set the ip address of the http server
mailcatcher_http-port: 1080 # Set the port address of the http server

Dependencies
------------

Depends on joshualund.ruby-1_9_3 (and indirectly joshualund.ruby-common)

License
-------
Expand Down
15 changes: 14 additions & 1 deletion handlers/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,15 @@
---
# handlers file for role-mailcatcher
- name: stop mailcatcher
service: name=mailcatcher state=stopped
sudo: yes
ignore_errors: True

- name: start mailcatcher
service: name=mailcatcher state=started
sudo: yes
ignore_errors: True

- name: restart mailcatcher
service: name=mailcatcher state=restarted
sudo: yes
ignore_errors: True
2 changes: 0 additions & 2 deletions meta/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,4 @@ galaxy_info:
- squeeze
categories:
- development
dependencies:
- joshualund.ruby-1_9_3

8 changes: 8 additions & 0 deletions tasks/create_user.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
- name: Create mailcatcher group
group: name=mailcatcher
sudo: yes

- name: Create Mailcatcher user
user: name=mailcatcher shell=/bin/bash comment="Mailcatcher" group=mailcatcher
sudo: yes
24 changes: 24 additions & 0 deletions tasks/install_mailcatcher.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
- name: Install mailcatcher dependencies
apt: pkg={{ item }} state=present
with_items:
- build-essential
- sqlite3
- libsqlite3-dev
- ruby-dev
- ruby
sudo: yes

- name: Check for mailcatcher
stat:
path=/usr/local/bin/mailcatcher
register: mailcatcher_installed

- name: Install Mailcatcher
command: gem install mailcatcher
sudo: yes
when: not mailcatcher_installed.stat.exists

- name: Create upstart script for mailcatcher
template: src=mailcatcher.j2 dest=/etc/init/mailcatcher.conf mode=0644
notify:
- restart mailcatcher
30 changes: 2 additions & 28 deletions tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,29 +1,3 @@
---
# tasks file for role-mailcatcher
- name: Install required software
apt: pkg={{ item }} state=latest
with_items:
- build-essential
- sqlite3
- libsqlite3-dev
- ruby-dev

- name: Install rubygems
apt: pkg=rubygems state=latest
when: ansible_distribution == 'Ubuntu' and ansible_distribution_release > 'trusty'

- name: Install Mailcatcher
command: gem install mailcatcher

- name: Create startup script for mailcatcher
template: src=mailcatcher.j2 dest=/etc/init.d/mailcatcher mode=0755

- name: Mailcatcher will start upon boot
command: update-rc.d mailcatcher defaults

- name: Make sure Mailcatcher is not running
command: pkill mailcatcher
ignore_errors: yes

- name: Start mailcatcher properly with the start script
command: /etc/init.d/mailcatcher
- include: create_user.yml
- include: install_mailcatcher.yml
21 changes: 17 additions & 4 deletions templates/mailcatcher.j2
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
#!/bin/sh
#/etc/init.d/mailcatcher
#
description "Mailcatcher"

/opt/ruby-1.9.3-p545/bin/mailcatcher --ip={{ mailcatcher_ip }} --smtp-ip={{ mailcatcher_smtp_ip }} --smtp-port={{ mailcatcher_smtp_port }} --http-ip={{ mailcatcher_http_ip }} --http-port={{ mailcatcher_http_port }}
start on runlevel [2345]
stop on runlevel [!2345]
respawn

pre-start script

bash << "EOF"
mkdir -p /var/log/mailcatcher
chown -R mailcatcher /var/log/mailcatcher
EOF

end script

pre-stop exec killall -q -v mailcatcher || :

exec su - mailcatcher -c 'mailcatcher -f -v --ip={{ mailcatcher_ip }} --smtp-ip={{ mailcatcher_smtp_ip }} --smtp-port={{ mailcatcher_smtp_port }} --http-ip={{ mailcatcher_http_ip }} --http-port={{ mailcatcher_http_port }} &>>/var/log/mailcatcher/mailcatcher.log'

0 comments on commit b8bbb58

Please sign in to comment.