blazing-upstart 0.1.0

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+ gemspec
3
+
4
+ gem 'rake'
5
+ gem 'rspec'
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013 Daniel Farrell
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,52 @@
1
+ Blazing Upstart
2
+ ===============
3
+
4
+ Upstart recipe for [blazing](http://github.com/effkay/blazing)
5
+
6
+ If you run your applications with [upstart](http://upstart.ubuntu.com/), this lets you
7
+ restart/reload after a deployment.
8
+
9
+ The expectation is that you have a Procfile with your processes in it. You can set certain
10
+ processes to receive a reload instead of a restart. That is very useful if, for example,
11
+ you run your app with [unicorn](http://unicorn.bogomips.org/).
12
+
13
+ Installation
14
+ ------------
15
+
16
+ Add `gem 'blazing-upstart'` to your `Gemfile`
17
+
18
+ Usage
19
+ -----
20
+
21
+ Enable the recipes you want in your blazing configuration file. Options
22
+ can be provided in the recipe call or with the target method. Target
23
+ options have precedence over recipe options.
24
+
25
+ ```ruby
26
+ # Restart the processes
27
+ #
28
+ # recipe :restart_processes, [options]
29
+ #
30
+ # Options:
31
+ #
32
+ # :reload (Set which processes reload instead of restart)
33
+ # :app (Set your app name to something different than the folder name)
34
+ # :procfile (Set if you use a Procfile not named Procfile)
35
+ # :sudo (Set if you use a different sudo command, ie rvmsudo)
36
+ #
37
+ # Example:
38
+
39
+ recipe :restart_processes, :reload => 'web'
40
+ ```
41
+
42
+ Authors
43
+ -------
44
+
45
+ Daniel Farrell ([@danielfarrell][])
46
+
47
+ License
48
+ -------
49
+
50
+ See the [MIT-LICENSE file](https://github.com/danielfarrell/blazing-upstart/blob/master/MIT-LICENSE)
51
+
52
+ [@danielfarrell]: https://github.com/danielfarrell
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "blazing-upstart/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "blazing-upstart"
7
+ s.version = Blazing::Upstart::VERSION
8
+ s.authors = ["Daniel Farrell"]
9
+ s.email = ["danielfarrell76@gmail.com"]
10
+ s.homepage = "https://github.com/danielfarrell/blazing-upstart"
11
+ s.summary = %q{blazing recipe for restarting/reloading app with upstart}
12
+ s.description = %q{blazing recipe for restarting/reloading app with upstart}
13
+
14
+ s.rubyforge_project = "blazing-upstart"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency "blazing", '>= 0.2.9'
21
+ s.add_dependency "activesupport"
22
+ end
@@ -0,0 +1,7 @@
1
+ require "blazing-upstart/version"
2
+ require "blazing-upstart/recipes/restart_processes"
3
+
4
+ module Blazing
5
+ module Upstart
6
+ end
7
+ end
@@ -0,0 +1,49 @@
1
+ require "blazing/recipe"
2
+ require "yaml"
3
+
4
+ class Blazing::Recipe::RestartProcesses < Blazing::Recipe
5
+
6
+ def run(target_options = {})
7
+ super target_options
8
+
9
+ info "restarting processes"
10
+ if complex_restart?
11
+ processes.each do |process|
12
+ system "#{sudo} initctl start #{application}-#{process} || #{sudo} initctl #{restart_command(process)} #{application}-#{process}"
13
+ end
14
+ else
15
+ system "#{sudo} initctl start #{application} || #{sudo} initctl restart #{application}"
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def application
22
+ options[:app] || pwd
23
+ end
24
+
25
+ def procfile
26
+ options[:procfile] || "Procfile"
27
+ end
28
+
29
+ def sudo
30
+ options[:sudo] || "sudo"
31
+ end
32
+
33
+ def complex_restart?
34
+ !options[:reload].nil?
35
+ end
36
+
37
+ def restart_command(process)
38
+ Array(options[:reload]).include?(process) ? "reload" : "restart"
39
+ end
40
+
41
+ def pwd
42
+ Dir.pwd.split('/').last
43
+ end
44
+
45
+ def processes
46
+ YAML.load_file(procfile).keys
47
+ end
48
+
49
+ end
@@ -0,0 +1,5 @@
1
+ module Blazing
2
+ module Upstart
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,30 @@
1
+ require 'blazing-upstart/recipes/restart_processes'
2
+
3
+ describe Blazing::Recipe::RestartProcesses do
4
+
5
+ it 'is a blazing recipe' do
6
+ Blazing::Recipe::RestartProcesses.superclass.should be Blazing::Recipe
7
+ end
8
+
9
+ describe 'run' do
10
+
11
+ before :each do
12
+ @recipe = Blazing::Recipe::RestartProcesses.new(:app => 'testing')
13
+ @recipe.stub(:info)
14
+ end
15
+
16
+ it 'should call upstart for start or restart by default' do
17
+ @recipe.should_receive(:system).with("sudo initctl start testing || sudo initctl restart testing")
18
+ @recipe.run
19
+ end
20
+
21
+ it 'should reload processes passed for reload' do
22
+ procfile = double("procfile", :keys => ['web'])
23
+ YAML.should_receive(:load_file) { procfile }
24
+ @recipe.should_receive(:system).with("sudo initctl start testing-web || sudo initctl reload testing-web")
25
+ @recipe.run :reload => ['web']
26
+ end
27
+
28
+ end
29
+
30
+ end
metadata ADDED
@@ -0,0 +1,88 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blazing-upstart
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Daniel Farrell
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-24 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: blazing
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.2.9
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.2.9
30
+ - !ruby/object:Gem::Dependency
31
+ name: activesupport
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: blazing recipe for restarting/reloading app with upstart
47
+ email:
48
+ - danielfarrell76@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - MIT-LICENSE
56
+ - README.md
57
+ - blazing-upstart.gemspec
58
+ - lib/blazing-upstart.rb
59
+ - lib/blazing-upstart/recipes/restart_processes.rb
60
+ - lib/blazing-upstart/version.rb
61
+ - spec/restart_processes_spec.rb
62
+ homepage: https://github.com/danielfarrell/blazing-upstart
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project: blazing-upstart
82
+ rubygems_version: 1.8.23
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: blazing recipe for restarting/reloading app with upstart
86
+ test_files:
87
+ - spec/restart_processes_spec.rb
88
+ has_rdoc: