greenonline_capistrano_recipes 0.0.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4ebe325f323506bf767537c4ae834969983c57ff
4
+ data.tar.gz: dfdbdf9c069a4ce197aef289a5f7b721b989bae6
5
+ SHA512:
6
+ metadata.gz: 97bd4da60088fa9bd9dfb1b8610c4e91e29a4d58c792b49f399c3e4bda560f895c9536339ff15c6426d97fea8b4af8422142787c30936c16bec3753e434b4c66
7
+ data.tar.gz: d29669560a88400d5dad7de080bdb7d2f3ccb34519d4d20772a5d2bd75f4b5ef2c8d6683ce67c197d1dd5fe88a5dd85faaddcd5163759f4458e9811642f2c27e
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ .DS_Store
2
+ *.gem
3
+ *.rbc
4
+ .bundle
5
+ .config
6
+ .yardoc
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
19
+ capistrano.sublime-workspace
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in capistrano_recipies.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Pieter Visser
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
+ # CapistranoRecipes
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'capistrano_recipies'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install capistrano_recipies
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
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 'Add 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 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,9 @@
1
+ {
2
+ "folders":
3
+ [
4
+ {
5
+ "follow_symlinks": true,
6
+ "path": "/Users/pieter/Dev/Gems/capistrano_recipes"
7
+ }
8
+ ]
9
+ }
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'greenonline/capistrano_recipes/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "greenonline_capistrano_recipes"
8
+ spec.version = Greenonline::CapistranoRecipes::VERSION
9
+ spec.authors = ["Pieter Visser"]
10
+ spec.email = ["pieter@greenonline.nl"]
11
+ spec.description = %q{Capistrano Recipes}
12
+ spec.summary = %q{Capistrano Recipes}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1 @@
1
+ require "greenonline/capistrano_recipes/version"
@@ -0,0 +1,5 @@
1
+ module Greenonline
2
+ module CapistranoRecipes
3
+ VERSION = "0.0.13"
4
+ end
5
+ end
@@ -0,0 +1,28 @@
1
+ module Capistrano
2
+ Configuration.instance(true).load do
3
+
4
+ def template(from, to)
5
+ erb_contents = File.read File.expand_path("../templates/#{from}", __FILE__)
6
+ put ERB.new(erb_contents).result(binding), to
7
+ end
8
+
9
+ def set_default(name, *args, &block)
10
+ set(name, *args, &block) unless exists?(name)
11
+ end
12
+
13
+ def surun(command)
14
+ run("su - -c '#{command}'") do |channel, stream, data|
15
+ if data =~ /\bpassword.*:/i
16
+ password = fetch(:root_password, Capistrano::CLI.password_prompt("Root password required!: "))
17
+ channel.send_data("#{password}\n")
18
+ else
19
+ logger.info "[#{stream}] #{data}"
20
+ end
21
+ end
22
+ end
23
+
24
+ set_default(:bundle_flags) { "--deployment --quiet --binstubs" }
25
+ set_default(:bundle_cmd) { "#{current_release}/bin/bundle" }
26
+
27
+ end
28
+ end
@@ -0,0 +1,30 @@
1
+ module Capistrano
2
+ Configuration.instance(true).load do
3
+ set_default(:nginx_server_name, nil)
4
+
5
+ namespace :nginx do
6
+ desc "update latest nginx configuration"
7
+ task :update_config, roles: :web do
8
+ template 'nginx_unicorn.erb', File.join(current_release, '/config/nginx.conf')
9
+ end
10
+ after "deploy:update_code", "nginx:update_config"
11
+
12
+ desc "setup nginx for this application, adding it to sites-enabled"
13
+ task :setup, roles: :web do
14
+ surun "ln -nfs #{File.join(current_path, '/config/nginx.conf')} /etc/nginx/conf.d/#{application.downcase}.conf"
15
+ end
16
+ after "deploy:setup", "nginx:setup"
17
+
18
+ namespace :server do
19
+
20
+ %w(start stop restart reload testconfig).each do |command|
21
+ desc "#{command} nginx"
22
+ task command, roles: :web do
23
+ surun "service nginx #{command}"
24
+ end
25
+ end
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,53 @@
1
+ upstream unicorn {
2
+ # fail_timeout=0 means we always retry an upstream even if it failed
3
+ # to return a good HTTP response (in case the Unicorn master nukes a
4
+ # single worker for timing out).
5
+
6
+ # for UNIX domain socket setups:
7
+ server unix:/tmp/unicorn.<%= application.downcase %>.sock fail_timeout=0;
8
+ }
9
+
10
+ server {
11
+ listen 80;
12
+ <% if nginx_server_name %>
13
+ server_name <%= nginx_server_name %>;
14
+ <% end %>
15
+ root <%= current_path %>/public;
16
+
17
+ location ^~ /assets/ {
18
+ gzip_static on;
19
+ expires max;
20
+ add_header Cache-Control public;
21
+ }
22
+
23
+ if (-f $document_root/maintenance.html) {
24
+ rewrite ^(.*)$ /maintenance.html last;
25
+ break;
26
+ }
27
+
28
+ try_files $uri/index.html $uri @unicorn;
29
+
30
+ location @unicorn {
31
+ # an HTTP header important enough to have its own Wikipedia entry:
32
+ # http://en.wikipedia.org/wiki/X-Forwarded-For
33
+ proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
34
+
35
+ # enable this if you forward HTTPS traffic to unicorn,
36
+ # this helps Rack set the proper URL scheme for doing redirects:
37
+ # proxy_set_header X-Forwarded-Proto $scheme;
38
+
39
+ # pass the Host: header from the client right along so redirects
40
+ # can be set properly within the Rack application
41
+ proxy_set_header Host $http_host;
42
+
43
+ # we don't want nginx trying to do something clever with
44
+ # redirects, we set the Host: header above already.
45
+ proxy_redirect off;
46
+
47
+ proxy_pass http://unicorn;
48
+ }
49
+
50
+ error_page 500 502 503 504 /500.html;
51
+ client_max_body_size 4G;
52
+ keepalive_timeout 10;
53
+ }
@@ -0,0 +1,49 @@
1
+ RAILS_ROOT = ENV['RAILS_ROOT'] || "<%= current_path %>"
2
+
3
+ working_directory "<%= current_path %>"
4
+ pid "<%= unicorn_pid %>"
5
+ stderr_path "<%= unicorn_log %>"
6
+ stdout_path "<%= unicorn_log %>"
7
+
8
+ listen "/tmp/unicorn.<%= application.downcase %>.sock"
9
+ worker_processes <%= unicorn_workers %>
10
+ timeout 30
11
+
12
+ # Load rails+github.git into the master before forking workers
13
+ # for super-fast worker spawn times
14
+ preload_app true
15
+
16
+ before_fork do |server, worker|
17
+ # Disconnect since the database connection will not carry over
18
+ if defined? ActiveRecord::Base
19
+ ActiveRecord::Base.connection.disconnect!
20
+ end
21
+
22
+ ##
23
+ # When sent a USR2, Unicorn will suffix its pidfile with .oldbin and
24
+ # immediately start loading up a new version of itself (loaded with a new
25
+ # version of our app). When this new Unicorn is completely loaded
26
+ # it will begin spawning workers. The first worker spawned will check to
27
+ # see if an .oldbin pidfile exists. If so, this means we've just booted up
28
+ # a new Unicorn and need to tell the old one that it can now die. To do so
29
+ # we send it a QUIT.
30
+ #
31
+ # Using this method we get 0 downtime deploys.
32
+
33
+ old_pid = File.join RAILS_ROOT, '<%= unicorn_pid %>.oldbin'
34
+ if File.exists?(old_pid) && server.pid != old_pid
35
+ begin
36
+ Process.kill("QUIT", File.read(old_pid).to_i)
37
+ rescue Errno::ENOENT, Errno::ESRCH
38
+ # someone else did our job for us
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ after_fork do |server, worker|
45
+ # Start up the database connection again in the worker
46
+ if defined? ActiveRecord::Base
47
+ ActiveRecord::Base.establish_connection
48
+ end
49
+ end
@@ -0,0 +1,86 @@
1
+ #!/bin/sh
2
+ ### BEGIN INIT INFO
3
+ # Provides: unicorn
4
+ # Required-Start: $remote_fs $syslog <%= unicorn_dependencies %>
5
+ # Required-Stop: $remote_fs $syslog
6
+ # Default-Start: 2 3 4 5
7
+ # Default-Stop: 0 1 6
8
+ # Short-Description: Manage unicorn server
9
+ # Description: Start, stop, restart unicorn server for a specific application.
10
+ ### END INIT INFO
11
+ set -e
12
+
13
+ # Feel free to change any of the following variables for your app:
14
+ TIMEOUT=${TIMEOUT-60}
15
+ APP_ROOT=<%= current_path %>
16
+ PID=<%= unicorn_pid %>
17
+ RBENV_ROOT="/usr/local/rbenv"
18
+ PATH="$RBENV_ROOT/bin:$RBENV_ROOT/shims:$PATH"
19
+ CMD="<%= current_path %>/bin/unicorn -D -c <%= unicorn_config %> -E production"
20
+ AS_USER=<%= unicorn_user %>
21
+ set -u
22
+
23
+ OLD_PIN="$PID.oldbin"
24
+
25
+ sig () {
26
+ test -s "$PID" && kill -$1 `cat $PID`
27
+ }
28
+
29
+ oldsig () {
30
+ test -s $OLD_PIN && kill -$1 `cat $OLD_PIN`
31
+ }
32
+
33
+ run () {
34
+ if [ "$(id -un)" = "$AS_USER" ]; then
35
+ eval $1
36
+ else
37
+ su -c "$1" - $AS_USER
38
+ fi
39
+ }
40
+
41
+ case "$1" in
42
+ start)
43
+ sig 0 && echo >&2 "Already running" && exit 0
44
+ run "$CMD"
45
+ ;;
46
+ stop)
47
+ sig QUIT && exit 0
48
+ echo >&2 "Not running"
49
+ ;;
50
+ force-stop)
51
+ sig TERM && exit 0
52
+ echo >&2 "Not running"
53
+ ;;
54
+ restart|reload)
55
+ sig HUP && echo reloaded OK && exit 0
56
+ echo >&2 "Couldn't reload, starting '$CMD' instead"
57
+ run "$CMD"
58
+ ;;
59
+ upgrade)
60
+ if sig USR2 && sleep 2 && sig 0 && oldsig QUIT
61
+ then
62
+ n=$TIMEOUT
63
+ while test -s $OLD_PIN && test $n -ge 0
64
+ do
65
+ printf '.' && sleep 1 && n=$(( $n - 1 ))
66
+ done
67
+ echo
68
+
69
+ if test $n -lt 0 && test -s $OLD_PIN
70
+ then
71
+ echo >&2 "$OLD_PIN still exists after $TIMEOUT seconds"
72
+ exit 1
73
+ fi
74
+ exit 0
75
+ fi
76
+ echo >&2 "Couldn't upgrade, starting '$CMD' instead"
77
+ run "$CMD"
78
+ ;;
79
+ reopen-logs)
80
+ sig USR1
81
+ ;;
82
+ *)
83
+ echo >&2 "Usage: $0 <start|stop|restart|upgrade|force-stop|reopen-logs>"
84
+ exit 1
85
+ ;;
86
+ esac
@@ -0,0 +1,43 @@
1
+ module Capistrano
2
+ Configuration.instance(true).load do
3
+ set_default(:unicorn_user) { user }
4
+ set_default(:unicorn_pid) { "#{current_path}/tmp/pids/unicorn.pid" }
5
+ set_default(:unicorn_config) { "#{current_path}/config/unicorn.rb" }
6
+ set_default(:unicorn_config_write) { "#{current_release}/config/unicorn.rb" }
7
+ set_default(:unicorn_log) { "#{current_path}/log/unicorn.log" }
8
+ set_default(:unicorn_dependencies) { "" }
9
+ set_default(:unicorn_workers) { 2 }
10
+
11
+
12
+ namespace :unicorn do
13
+ desc "update latest unicorn configuration"
14
+ task :update_config, roles: :web do
15
+ template 'unicorn.rb.erb', unicorn_config_write
16
+ end
17
+ after "deploy:update_code", "unicorn:update_config"
18
+
19
+ desc "Setup Unicorn initializer and app configuration"
20
+ task :setup, roles: :app do
21
+ template "unicorn_init.erb", "/tmp/unicorn_init"
22
+ run "chmod +x /tmp/unicorn_init"
23
+ surun "mv /tmp/unicorn_init /etc/init.d/unicorn_#{application.downcase}"
24
+ surun "chkconfig --add unicorn_#{application.downcase}"
25
+ surun "chkconfig unicorn_#{application.downcase} on"
26
+ end
27
+ after "deploy:setup", "unicorn:setup"
28
+
29
+ namespace :server do
30
+ %w(start stop restart upgrade).each do |command|
31
+ desc "#{command} unicorn"
32
+ task command, roles: :web do
33
+ run "service unicorn_#{application.downcase} #{command}"
34
+ end
35
+ end
36
+ after "deploy:restart", "unicorn:server:upgrade"
37
+ after "deploy:stop", "unicorn:server:stop"
38
+ after "deploy:start", "unicorn:server:start"
39
+ end
40
+
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,7 @@
1
+ module Greenonline
2
+ module Recipes
3
+
4
+ puts "bla"
5
+
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: greenonline_capistrano_recipes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.13
5
+ platform: ruby
6
+ authors:
7
+ - Pieter Visser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Capistrano Recipes
42
+ email:
43
+ - pieter@greenonline.nl
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE.txt
51
+ - README.md
52
+ - Rakefile
53
+ - capistrano.sublime-project
54
+ - capistrano_recipes.gemspec
55
+ - lib/capistrano_recipes.rb
56
+ - lib/greenonline/capistrano_recipes/version.rb
57
+ - lib/greenonline/recipes.rb
58
+ - lib/greenonline/recipes/base.rb
59
+ - lib/greenonline/recipes/nginx.rb
60
+ - lib/greenonline/recipes/templates/nginx_unicorn.erb
61
+ - lib/greenonline/recipes/templates/unicorn.rb.erb
62
+ - lib/greenonline/recipes/templates/unicorn_init.erb
63
+ - lib/greenonline/recipes/unicorn.rb
64
+ homepage: ''
65
+ licenses:
66
+ - MIT
67
+ metadata: {}
68
+ post_install_message:
69
+ rdoc_options: []
70
+ require_paths:
71
+ - lib
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ requirements: []
83
+ rubyforge_project:
84
+ rubygems_version: 2.0.3
85
+ signing_key:
86
+ specification_version: 4
87
+ summary: Capistrano Recipes
88
+ test_files: []