executive 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in boss.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Roshan Choxi
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
+ # Boss
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'boss'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install boss
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 '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"
data/bin/executive ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rubygems"
4
+ require "boss"
5
+
6
+ command = ARGV.first.downcase
7
+
8
+ case command
9
+ when "start"
10
+ Boss.start
11
+ Process.wait2
12
+
13
+ trap "HUP" do
14
+ Boss.restart
15
+ Process.wait2
16
+ end
17
+ when "deploy"
18
+ Boss.deploy ARGV[1]
19
+ else
20
+ puts "Usage: boss <command> <args>"
21
+ end
22
+
23
+
data/executive.gemspec ADDED
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/executive/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Roshan Choxi"]
6
+ gem.email = ["roshan.choxi@gmail.com"]
7
+ gem.description = %q{a Foreman wrapper with extra utilities.}
8
+ gem.summary = %q{executive allows you to restart Foreman processes and deploy using Heroku conventions.}
9
+ gem.homepage = "http://roshfu.com"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "executive"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Executive::VERSION
17
+
18
+ gem.add_runtime_dependency "colorize"
19
+ gem.add_runtime_dependency "foreman"
20
+ end
@@ -0,0 +1,3 @@
1
+ module Executive
2
+ VERSION = "0.0.1"
3
+ end
data/lib/executive.rb ADDED
@@ -0,0 +1,116 @@
1
+ require "executive/version"
2
+ require 'colorize'
3
+
4
+ module Executive
5
+ class << self
6
+ def start
7
+ @foreman_pid = Process.spawn("foreman start")
8
+ end
9
+
10
+ def restart
11
+ puts "\tRestarting Foreman".blue
12
+ Process.kill "TERM", @foreman_pid
13
+ start
14
+ end
15
+
16
+ def deploy(environment)
17
+ if environment == "development"
18
+ Development.deploy
19
+ elsif environment == "production"
20
+ Production.deploy
21
+ end
22
+ end
23
+ end
24
+
25
+ module Development
26
+ def self.ensure_system_call(command)
27
+ unless system(command)
28
+ puts %Q(>> Error Running: "#{command}").red
29
+ exit
30
+ end
31
+ end
32
+
33
+ def self.deploy
34
+ if File.exists?(".deployed_revision")
35
+ deployed_revision = File.read(".deployed_revision").chomp
36
+ migrations_present = (`git log #{deployed_revision}..HEAD -- db/migrate/` != "")
37
+ seeds_changed = (`git log #{deployed_revision}..HEAD -- db/fixtures/` != "")
38
+ env_changed = (`git log #{deployed_revision}..HEAD -- .env` != "")
39
+ else
40
+ migrations_present = true
41
+ seeds_changed = true
42
+ env_changed = true
43
+ end
44
+
45
+ puts ">> Deploying Development".green
46
+ if migrations_present
47
+ puts ">> Running Migrations".green
48
+ ensure_system_call("foreman run rake db:migrate")
49
+ else
50
+ puts ">> Skipping Migrations".yellow
51
+ end
52
+
53
+ if seeds_changed
54
+ puts ">> Updating DB Seeds".green
55
+ ensure_system_call("foreman run rake db:seed_fu")
56
+ else
57
+ puts ">> Skipping DB Seeding".yellow
58
+ end
59
+
60
+ if env_changed
61
+ puts ">> Restarting Foreman".green
62
+
63
+ begin
64
+ foreman_pid = `ps aux | grep 'executive'`.split("\n").first.split(" ")[1]
65
+ Process.kill "HUP", foreman_pid.to_i
66
+ rescue NoMethodError => e
67
+ puts "Foreman isn't running. Run script/start.".red
68
+ end
69
+ else
70
+ puts ">> Skipping Foreman Restart".yellow
71
+ end
72
+
73
+ File.open(".deployed_revision", "w+") { |f| f << `git rev-parse HEAD` }
74
+ puts ">> Recorded Deployed Revision".green
75
+ end
76
+ end
77
+
78
+ module Production
79
+ def self.ensure_system_call(command)
80
+ unless system(command)
81
+ puts %Q(>> Error Running: "#{command}").red
82
+ exit
83
+ end
84
+ end
85
+
86
+ def self.deploy
87
+ remote = "heroku"
88
+
89
+ puts ">> Deploying Production".green
90
+
91
+ if `git log origin/master..HEAD` != ""
92
+ puts ">> Pushing to Github".green
93
+ ensure_system_call %Q(git push origin master)
94
+ end
95
+
96
+ migrations_present = (`git log heroku/master..HEAD -- db/migrate/` != "")
97
+
98
+ if migrations_present
99
+ puts ">> Turning On Maintenance Mode".green
100
+ ensure_system_call "heroku maintenance:on"
101
+ end
102
+
103
+ puts ">> Deploying to Heroku".green
104
+ ensure_system_call "git push #{remote} master"
105
+
106
+ if migrations_present
107
+ ensure_system_call "heroku run rake db:migrate"
108
+ end
109
+
110
+ if migrations_present
111
+ puts ">> Turning Off Maintenance Mode".green
112
+ ensure_system_call "heroku maintenance:off"
113
+ end
114
+ end
115
+ end
116
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: executive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Roshan Choxi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-13 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: colorize
16
+ requirement: &70214025585320 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *70214025585320
25
+ - !ruby/object:Gem::Dependency
26
+ name: foreman
27
+ requirement: &70214025583760 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *70214025583760
36
+ description: a Foreman wrapper with extra utilities.
37
+ email:
38
+ - roshan.choxi@gmail.com
39
+ executables:
40
+ - executive
41
+ extensions: []
42
+ extra_rdoc_files: []
43
+ files:
44
+ - .gitignore
45
+ - Gemfile
46
+ - LICENSE
47
+ - README.md
48
+ - Rakefile
49
+ - bin/executive
50
+ - executive.gemspec
51
+ - lib/executive.rb
52
+ - lib/executive/version.rb
53
+ homepage: http://roshfu.com
54
+ licenses: []
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ none: false
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
65
+ required_rubygems_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ requirements: []
72
+ rubyforge_project:
73
+ rubygems_version: 1.8.15
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: executive allows you to restart Foreman processes and deploy using Heroku
77
+ conventions.
78
+ test_files: []