mana 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.gitignore +18 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE +22 -0
  4. data/README.md +29 -0
  5. data/Rakefile +2 -0
  6. data/cookbooks/monit/attributes/default.rb +13 -0
  7. data/cookbooks/monit/files/ubuntu/monit.default +11 -0
  8. data/cookbooks/monit/libraries/monitrc.rb +21 -0
  9. data/cookbooks/monit/recipes/default.rb +34 -0
  10. data/cookbooks/monit/recipes/ssh.rb +3 -0
  11. data/cookbooks/monit/templates/default/monitrc.erb +31 -0
  12. data/cookbooks/monit/templates/default/ssh.monit.conf.erb +7 -0
  13. data/cookbooks/nginx/attributes/default.rb +3 -0
  14. data/cookbooks/nginx/definitions/nginx_site.rb +15 -0
  15. data/cookbooks/nginx/recipes/default.rb +44 -0
  16. data/cookbooks/nginx/templates/default/default.conf.erb +11 -0
  17. data/cookbooks/nginx/templates/default/nginx.conf.erb +32 -0
  18. data/cookbooks/nginx/templates/default/nginx.monit.conf.erb +8 -0
  19. data/cookbooks/nginx/templates/default/nxdissite.erb +29 -0
  20. data/cookbooks/nginx/templates/default/nxensite.erb +38 -0
  21. data/cookbooks/postgresql/attributes/default.rb +5 -0
  22. data/cookbooks/postgresql/recipes/client.rb +5 -0
  23. data/cookbooks/postgresql/recipes/default.rb +2 -0
  24. data/cookbooks/postgresql/recipes/server.rb +25 -0
  25. data/cookbooks/postgresql/templates/default/pg_hba.conf.erb +4 -0
  26. data/cookbooks/postgresql/templates/default/postgresql.conf.erb +505 -0
  27. data/cookbooks/postgresql/templates/default/postgresql.monit.conf.erb +11 -0
  28. data/cookbooks/railsapp/attributes/default.rb +22 -0
  29. data/cookbooks/railsapp/recipes/default.rb +65 -0
  30. data/cookbooks/railsapp/templates/default/master.monit.conf.erb +8 -0
  31. data/cookbooks/railsapp/templates/default/site.conf.erb +62 -0
  32. data/cookbooks/railsapp/templates/default/unicorn-init.sh.erb +64 -0
  33. data/cookbooks/railsapp/templates/default/unicorn.rb.erb +37 -0
  34. data/cookbooks/railsapp/templates/default/worker.monit.conf.erb +8 -0
  35. data/lib/mana.rb +5 -0
  36. data/lib/mana/capistrano.rb +93 -0
  37. data/lib/mana/railtie.rb +7 -0
  38. data/lib/mana/version.rb +3 -0
  39. data/lib/tasks/mana.rake +9 -0
  40. data/mana.gemspec +21 -0
  41. data/templates/Vagrantfile +4 -0
  42. data/templates/config/deploy.rb +24 -0
  43. data/templates/config/deploy/vagrant.rb +7 -0
  44. metadata +136 -0
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mana.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Ilia Ablamonov
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Mana
2
+
3
+ Configuration management with Chef & Capistrano
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'mana'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install mana
18
+
19
+ ## Usage
20
+
21
+ rake mana:install
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ default[:monit][:notify_email] = "notify@example.com"
2
+
3
+ default[:monit][:poll_period] = 60
4
+ default[:monit][:poll_start_delay] = nil
5
+
6
+ default[:monit][:mail_format][:subject] = "$SERVICE $EVENT"
7
+ default[:monit][:mail_format][:from] = "monit@example.com"
8
+ default[:monit][:mail_format][:message] = <<-EOS
9
+ Monit $ACTION $SERVICE at $DATE on $HOST: $DESCRIPTION.
10
+ Yours sincerely,
11
+ monit
12
+ EOS
13
+
@@ -0,0 +1,11 @@
1
+ # Defaults for monit initscript
2
+ # sourced by /etc/init.d/monit
3
+ # installed at /etc/default/monit by chef
4
+
5
+ # You must set this variable to for monit to start
6
+ startup=1
7
+
8
+ # To change the intervals which monit should run,
9
+ # edit the configuration file /etc/monit/monitrc
10
+ # It can no longer be configured here.
11
+
@@ -0,0 +1,21 @@
1
+ class Chef
2
+ class Recipe
3
+ # name The name of the service. Looks for a template named NAME.conf
4
+ # variables Hash of variables to pass to the template
5
+ # reload Reload monit so it notices the new service. :delayed (default) or :immediately.
6
+ def monitrc(name, variables={}, reload = :delayed, &block)
7
+ log "Making monitrc for: #{name}"
8
+ template "/etc/monit/conf.d/#{name}.conf" do
9
+ owner "root"
10
+ group "root"
11
+ mode 0644
12
+ source "#{name}.monit.conf.erb"
13
+ variables variables
14
+ notifies :restart, resources(:service => "monit"), reload
15
+ action :create
16
+
17
+ instance_exec &block if block
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,34 @@
1
+ package "monit" do
2
+ action :install
3
+ end
4
+
5
+ if platform?("ubuntu")
6
+ cookbook_file "/etc/default/monit" do
7
+ source "monit.default"
8
+ owner "root"
9
+ group "root"
10
+ mode 0644
11
+ end
12
+ end
13
+
14
+ service "monit" do
15
+ action :start
16
+ enabled true
17
+ supports [:start, :restart, :stop]
18
+ end
19
+
20
+ template "/etc/monit/monitrc" do
21
+ owner "root"
22
+ group "root"
23
+ mode 0700
24
+ source 'monitrc.erb'
25
+ notifies :restart, resources(:service => "monit"), :immediate
26
+ end
27
+
28
+ directory "/etc/monit/conf.d/" do
29
+ owner 'root'
30
+ group 'root'
31
+ mode 0755
32
+ action :create
33
+ recursive true
34
+ end
@@ -0,0 +1,3 @@
1
+ include_recipe "monit"
2
+
3
+ monitrc "ssh"
@@ -0,0 +1,31 @@
1
+ set daemon <%= @node[:monit][:poll_period] %>
2
+ <% if @node[:monit][:poll_start_delay] %>
3
+ with start delay <%= @node[:monit][:poll_start_delay] %>
4
+ <% end %>
5
+
6
+ set logfile /var/log/monit.log
7
+
8
+ set mailserver localhost
9
+
10
+ #set mailserver smtp.gmail.com port 587
11
+ # username "someuser@gmail.com" password "password"
12
+ # using tlsv1
13
+ # with timeout 30 seconds
14
+
15
+ set eventqueue
16
+ basedir /var/monit # set the base directory where events will be stored
17
+ # slots 1000 # optionaly limit the queue size
18
+
19
+ set mail-format {
20
+ from: <%= @node[:monit][:mail_format][:from] %>
21
+ subject: <%= @node[:monit][:mail_format][:subject] %>
22
+ message: <%= @node[:monit][:mail_format][:message] %>
23
+ }
24
+
25
+ set alert <%= @node[:monit][:notify_email] %> NOT ON { action, instance, pid, ppid }
26
+
27
+ set httpd port 3737
28
+ allow 0.0.0.0/0
29
+
30
+ include /etc/monit/conf.d/*.conf
31
+
@@ -0,0 +1,7 @@
1
+ # managed by chef, changes will be overwritten
2
+ CHECK PROCESS sshd WITH PIDFILE /var/run/sshd.pid
3
+ START PROGRAM "/usr/sbin/service ssh start"
4
+ STOP PROGRAM "/usr/sbin/service ssh stop"
5
+ # under load a check may fail intermittently, so give it a few tries before restarting
6
+ IF FAILED PORT 22 PROTOCOL ssh 4 TIMES WITHIN 6 CYCLES THEN RESTART
7
+
@@ -0,0 +1,3 @@
1
+ default[:nginx][:dir] = "/etc/nginx"
2
+ default[:nginx][:log_dir] = "/var/log/nginx"
3
+ default[:nginx][:user] = "www-data"
@@ -0,0 +1,15 @@
1
+ define :nginx_site, :enable => true do
2
+ if params[:enable]
3
+ execute "nxensite #{params[:name]}" do
4
+ command "/usr/sbin/nxensite #{params[:name]}"
5
+ notifies :reload, resources(:service => "nginx")
6
+ not_if do ::File.symlink?("#{node[:nginx][:dir]}/sites-enabled/#{params[:name]}") end
7
+ end
8
+ else
9
+ execute "nxdissite #{params[:name]}" do
10
+ command "/usr/sbin/nxdissite #{params[:name]}"
11
+ notifies :reload, resources(:service => "nginx")
12
+ only_if do ::File.symlink?("#{node[:nginx][:dir]}/sites-enabled/#{params[:name]}") end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,44 @@
1
+ package "nginx"
2
+
3
+ service "nginx" do
4
+ supports :status => true, :restart => true, :reload => true
5
+ action :enable
6
+ end
7
+
8
+ directory node[:nginx][:log_dir] do
9
+ mode 0755
10
+ owner node[:nginx][:user]
11
+ action :create
12
+ end
13
+
14
+ %w{nxensite nxdissite}.each do |nxscript|
15
+ template "/usr/sbin/#{nxscript}" do
16
+ source "#{nxscript}.erb"
17
+ mode 0755
18
+ owner "root"
19
+ group "root"
20
+ end
21
+ end
22
+
23
+ template "nginx.conf" do
24
+ path "#{node[:nginx][:dir]}/nginx.conf"
25
+ source "nginx.conf.erb"
26
+ owner "root"
27
+ group "root"
28
+ mode 0644
29
+ notifies :reload, "service[nginx]"
30
+ end
31
+
32
+ template "#{node[:nginx][:dir]}/sites-available/default" do
33
+ source "default.conf.erb"
34
+ owner "root"
35
+ group "root"
36
+ mode 0644
37
+ notifies :reload, "service[nginx]"
38
+ end
39
+
40
+ service "nginx" do
41
+ action :start
42
+ end
43
+
44
+ monitrc "nginx"
@@ -0,0 +1,11 @@
1
+ server {
2
+ listen 80;
3
+ server_name <%= node[:hostname] %>;
4
+
5
+ access_log <%= node[:nginx][:log_dir] %>/localhost.access.log;
6
+
7
+ location / {
8
+ root /var/www/nginx-default;
9
+ index index.html index.htm;
10
+ }
11
+ }
@@ -0,0 +1,32 @@
1
+ user www-data;
2
+ worker_processes 2;
3
+
4
+ error_log <%= node[:nginx][:log_dir] %>/error.log;
5
+
6
+ events {
7
+ worker_connections 1024;
8
+ }
9
+
10
+ http {
11
+ include mime.types;
12
+ default_type application/octet-stream;
13
+
14
+ access_log <%= node[:nginx][:log_dir] %>/access.log;
15
+
16
+ sendfile on;
17
+ tcp_nopush on;
18
+ tcp_nodelay on;
19
+
20
+ keepalive_timeout 65;
21
+
22
+ gzip on;
23
+ gzip_http_version 1.0;
24
+ gzip_comp_level 2;
25
+ gzip_proxied any;
26
+ gzip_types text/plain text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript application/javascript application/json;
27
+
28
+ server_names_hash_bucket_size 64;
29
+
30
+ include /etc/nginx/conf.d/*.conf;
31
+ include /etc/nginx/sites-enabled/*;
32
+ }
@@ -0,0 +1,8 @@
1
+ # managed by chef, changes will be overwritten
2
+ check process nginx with pidfile /var/run/nginx.pid
3
+ start program "/etc/init.d/nginx start"
4
+ stop program "/etc/init.d/nginx stop"
5
+ if failed host localhost port 80 then restart
6
+ if cpu is greater than 40% for 2 cycles then alert
7
+ if cpu > 60% for 5 cycles then restart
8
+ if 10 restarts within 10 cycles then timeout
@@ -0,0 +1,29 @@
1
+ #!/bin/sh -e
2
+
3
+ SYSCONFDIR='<%= node[:nginx][:dir] %>'
4
+
5
+ if [ -z $1 ]; then
6
+ echo "Which site would you like to disable?"
7
+ echo -n "Your choices are: "
8
+ ls $SYSCONFDIR/sites-enabled/* | \
9
+ sed -e "s,$SYSCONFDIR/sites-enabled/,,g" | xargs echo
10
+ echo -n "Site name? "
11
+ read SITENAME
12
+ else
13
+ SITENAME=$1
14
+ fi
15
+
16
+ if [ $SITENAME = "default" ]; then
17
+ PRIORITY="000"
18
+ fi
19
+
20
+ if ! [ -e $SYSCONFDIR/sites-enabled/$SITENAME -o \
21
+ -e $SYSCONFDIR/sites-enabled/"$PRIORITY"-"$SITENAME" ]; then
22
+ echo "This site is already disabled, or does not exist!"
23
+ exit 1
24
+ fi
25
+
26
+ if ! rm $SYSCONFDIR/sites-enabled/$SITENAME 2>/dev/null; then
27
+ rm -f $SYSCONFDIR/sites-enabled/"$PRIORITY"-"$SITENAME"
28
+ fi
29
+ echo "Site $SITENAME disabled; reload nginx to disable."
@@ -0,0 +1,38 @@
1
+ #!/bin/sh -e
2
+
3
+ SYSCONFDIR='<%= node[:nginx][:dir] %>'
4
+
5
+ if [ -z $1 ]; then
6
+ echo "Which site would you like to enable?"
7
+ echo -n "Your choices are: "
8
+ ls $SYSCONFDIR/sites-available/* | \
9
+ sed -e "s,$SYSCONFDIR/sites-available/,,g" | xargs echo
10
+ echo -n "Site name? "
11
+ read SITENAME
12
+ else
13
+ SITENAME=$1
14
+ fi
15
+
16
+ if [ $SITENAME = "default" ]; then
17
+ PRIORITY="000"
18
+ fi
19
+
20
+ if [ -e $SYSCONFDIR/sites-enabled/$SITENAME -o \
21
+ -e $SYSCONFDIR/sites-enabled/"$PRIORITY"-"$SITENAME" ]; then
22
+ echo "This site is already enabled!"
23
+ exit 0
24
+ fi
25
+
26
+ if ! [ -e $SYSCONFDIR/sites-available/$SITENAME ]; then
27
+ echo "This site does not exist!"
28
+ exit 1
29
+ fi
30
+
31
+ if [ $SITENAME = "default" ]; then
32
+ ln -sf $SYSCONFDIR/sites-available/$SITENAME \
33
+ $SYSCONFDIR/sites-enabled/"$PRIORITY"-"$SITENAME"
34
+ else
35
+ ln -sf $SYSCONFDIR/sites-available/$SITENAME $SYSCONFDIR/sites-enabled/$SITENAME
36
+ fi
37
+
38
+ echo "Site $SITENAME installed; reload nginx to enable."
@@ -0,0 +1,5 @@
1
+ default[:postgresql][:version] = "9.1"
2
+ default[:postgresql][:ssl] = true
3
+ default[:postgresql][:listen_all] = false
4
+
5
+ set[:postgresql][:dir] = "/etc/postgresql/#{node[:postgresql][:version]}/main"
@@ -0,0 +1,5 @@
1
+ %w{postgresql-client libpq-dev make}.each do |pg_pack|
2
+ package pg_pack do
3
+ action :install
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ include_recipe "postgresql::client"
2
+ include_recipe "postgresql::server"
@@ -0,0 +1,25 @@
1
+ package "postgresql"
2
+
3
+ service "postgresql" do
4
+ service_name "postgresql"
5
+ supports :restart => true, :status => true, :reload => true
6
+ action :nothing
7
+ end
8
+
9
+ template "#{node[:postgresql][:dir]}/postgresql.conf" do
10
+ source "postgresql.conf.erb"
11
+ owner "postgres"
12
+ group "postgres"
13
+ mode 0600
14
+ notifies :restart, resources(:service => "postgresql")
15
+ end
16
+
17
+ template "#{node[:postgresql][:dir]}/pg_hba.conf" do
18
+ source "pg_hba.conf.erb"
19
+ owner "postgres"
20
+ group "postgres"
21
+ mode 0600
22
+ notifies :reload, resources(:service => "postgresql"), :immediately
23
+ end
24
+
25
+ monitrc "postgresql"