gap 0.0.3

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.
data/.gemtest ADDED
File without changes
data/History.txt ADDED
@@ -0,0 +1,4 @@
1
+ === 0.0.1 2012-01-11
2
+
3
+ * 1 major enhancement:
4
+ * Initial release
data/Manifest.txt ADDED
@@ -0,0 +1,21 @@
1
+ History.txt
2
+ Manifest.txt
3
+ PostInstall.txt
4
+ README.rdoc
5
+ Rakefile
6
+ lib/gap.rb
7
+ script/console
8
+ script/destroy
9
+ script/generate
10
+ test/test_gap.rb
11
+ test/test_helper.rb
12
+ bin/gap
13
+ lib/gap/cli.rb
14
+ lib/gap/defalut_recipe.rb
15
+ lib/gap/god_erb.rb
16
+ lib/gap/patch.rb
17
+ lib/gap/tasks.rb
18
+ lib/gap/tmpl.erb
19
+ lib/gap/recipes/hg.rb
20
+ lib/gap/recipes/sys.rb
21
+ lib/gap/recipes/ruby.rb
data/PostInstall.txt ADDED
@@ -0,0 +1,7 @@
1
+
2
+ For more information on gap, see http://gap.rubyforge.org
3
+
4
+ NOTE: Change this information in PostInstall.txt
5
+ You can also delete it if you don't want it.
6
+
7
+
data/README.rdoc ADDED
@@ -0,0 +1,48 @@
1
+ = gap
2
+
3
+ * http://github.com/#{github_username}/#{project_name}
4
+
5
+ == DESCRIPTION:
6
+
7
+ FIX (describe your package)
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * FIX (list of features or problems)
12
+
13
+ == SYNOPSIS:
14
+
15
+ FIX (code sample of usage)
16
+
17
+ == REQUIREMENTS:
18
+
19
+ * FIX (list of requirements)
20
+
21
+ == INSTALL:
22
+
23
+ * FIX (sudo gem install, anything else)
24
+
25
+ == LICENSE:
26
+
27
+ (The MIT License)
28
+
29
+ Copyright (c) 2012 FIXME full name
30
+
31
+ Permission is hereby granted, free of charge, to any person obtaining
32
+ a copy of this software and associated documentation files (the
33
+ 'Software'), to deal in the Software without restriction, including
34
+ without limitation the rights to use, copy, modify, merge, publish,
35
+ distribute, sublicense, and/or sell copies of the Software, and to
36
+ permit persons to whom the Software is furnished to do so, subject to
37
+ the following conditions:
38
+
39
+ The above copyright notice and this permission notice shall be
40
+ included in all copies or substantial portions of the Software.
41
+
42
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
43
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
44
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
45
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
46
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
47
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
48
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require 'rubygems'
2
+ gem 'hoe', '>= 2.1.0'
3
+ require 'hoe'
4
+ require 'fileutils'
5
+ require './lib/gap'
6
+
7
+ Hoe.plugin :newgem
8
+ # Hoe.plugin :website
9
+ # Hoe.plugin :cucumberfeatures
10
+
11
+ # Generate all the Rake tasks
12
+ # Run 'rake -T' to see list of generated tasks (from gem root directory)
13
+ $hoe = Hoe.spec 'gap' do
14
+ #self.developer 'FIXME full name', 'FIXME email'
15
+ self.developer 'Takashi Yaguchi', 'takashimu14@gmail.com'
16
+ self.post_install_message = 'PostInstall.txt' # TODO remove if post-install message not required
17
+ self.rubyforge_name = self.name # TODO this is default value
18
+ # self.extra_deps = [['activesupport','>= 2.0.2']]
19
+
20
+ end
21
+
22
+ require 'newgem/tasks'
23
+ Dir['tasks/**/*.rake'].each { |t| load t }
24
+
25
+ # TODO - want other tests/tasks run by default? Add them to the list
26
+ # remove_task :default
27
+ # task :default => [:spec, :features]
data/bin/gap ADDED
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'gap/cli'
4
+ Gap::CLI.execute
5
+
6
+ #require 'rubygems' unless ENV['NO_RUBYGEMS']
7
+ #require 'rubigen'
8
+ #
9
+ #if %w(-v --version).include? ARGV.first
10
+ # require File.dirname(__FILE__) + "/../lib/newgem"
11
+ # puts "#{File.basename($0)} #{Newgem::VERSION}"
12
+ # exit(0)
13
+ #end
14
+ #
15
+ #require 'rubigen/scripts/generate'
16
+ #
17
+ #require "pp"
18
+ #RubiGen::Base.use_application_sources! :rubygems
19
+ #RubiGen::Base.prepend_sources(*[
20
+ # RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__), "..", "app_generators")),
21
+ # RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__), "..", "newgem_generators")),
22
+ # RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__), "..", "newgem_theme_generators")),
23
+ # RubiGen::PathSource.new(:app, File.join(File.dirname(__FILE__), "..", "rubygems_generators"))
24
+ #])
25
+ ##
26
+ ## pp RubiGen::Base.sources
27
+ #
28
+ #if ARGV.delete "--simple"
29
+ # RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'newgem_simple')
30
+ #else
31
+ # RubiGen::Scripts::Generate.new.run(ARGV, :generator => 'newgem', :backtrace => true)
32
+ #end
data/lib/gap/cli.rb ADDED
@@ -0,0 +1,11 @@
1
+ require 'capistrano/cli'
2
+ require 'gap/patch'
3
+
4
+ module Gap
5
+ class CLI
6
+ def self.execute
7
+ Capistrano::CLI.execute
8
+ end
9
+ end
10
+ end
11
+
@@ -0,0 +1,14 @@
1
+ #load File.expand_path './recipes/hg.rb', File.dirname(__FILE__)
2
+ #load File.expand_path './recipes/sys.rb', File.dirname(__FILE__)
3
+ load 'gap/recipes/hg.rb'
4
+ load 'gap/recipes/sys.rb'
5
+
6
+ set :stages, %w(dev alpha beta pro)
7
+ set :default_stage, "dev"
8
+ set :scm, "mercurial"
9
+ set :env, ARGV[0]
10
+ set :branch, env
11
+
12
+ set :deploy_to, "/var/apps/#{env}/#{fetch :application}"
13
+ #set :pid_file, "#{deploy_to}/pid/#{env}.pid"
14
+ set :use_sudo, true
@@ -0,0 +1,23 @@
1
+ require 'erb'
2
+ module Gap
3
+ class GodErb
4
+ def initialize(tmpl,app,part,commands)
5
+ @app = app
6
+ @part = part
7
+ @commands = commands
8
+ view = File.open(tmpl)
9
+ @erb = ERB.new(view.read)
10
+ end
11
+
12
+ def render
13
+ # ファイル出力
14
+ output = "./god_#{@app}_#{@part}.rb"
15
+ txt = @erb.result(binding)
16
+ fw = File.open(output, 'w')
17
+ fw.puts(txt)
18
+ fw.close
19
+
20
+ output
21
+ end
22
+ end
23
+ end
data/lib/gap/patch.rb ADDED
@@ -0,0 +1,61 @@
1
+ require 'yaml'
2
+ require 'gap/god_erb'
3
+ require 'gap/tasks'
4
+
5
+
6
+ module Capistrano
7
+ class CLI
8
+ module Execute
9
+ def execute!
10
+ config = instantiate_configuration(options)
11
+ config.debug = options[:debug]
12
+ config.dry_run = options[:dry_run]
13
+ config.preserve_roles = options[:preserve_roles]
14
+ config.logger.level = options[:verbose]
15
+
16
+ set_pre_vars(config)
17
+ load_recipes(config)
18
+
19
+ load_gap_yml(config)
20
+ load_gap_default_recipe(config)
21
+
22
+ config.trigger(:load)
23
+ execute_requested_actions(config)
24
+ config.trigger(:exit)
25
+
26
+ config
27
+ rescue Exception => error
28
+ handle_error(error)
29
+ end
30
+
31
+ def load_gap_default_recipe config
32
+
33
+ config.load { load File.expand_path './defalut_recipe.rb', File.dirname(__FILE__)}
34
+ end
35
+
36
+
37
+ def load_gap_yml config
38
+ #コマンドラインオプションにする
39
+ gap_config = YAML.load_file("config/gap.yml")
40
+ config.send(:extend,Gap::Tasks)
41
+ config.load do
42
+
43
+ gap_config.each do |env,value|
44
+
45
+ if env == "global"
46
+ value["set"].each { |attr, val| set attr, val}
47
+ else
48
+ task(env) do
49
+ define_bulk_tasks value
50
+ define_config_tasks value
51
+ end
52
+ end
53
+
54
+ end
55
+
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,27 @@
1
+ namespace :hg do
2
+ task :fetch do
3
+ pull
4
+ update
5
+ end
6
+
7
+ task :pull do
8
+ run "cd #{deploy_to} && hg pull -b #{branch}"
9
+ end
10
+
11
+ task :update do
12
+ run "cd #{deploy_to} && hg update #{branch} -C"
13
+ glog
14
+ end
15
+
16
+ task :id do
17
+ run "cd #{deploy_to} && hg id"
18
+ end
19
+
20
+ task :glog do
21
+ run "cd #{deploy_to} && hg glog | head -n 40"
22
+ end
23
+
24
+ task :commit do
25
+ run "cd #{deploy_to} && hg commit -A -m 'auto commit'"
26
+ end
27
+ end
@@ -0,0 +1,18 @@
1
+ namespace :ruby do
2
+ task :bundle_install do
3
+ run "source /etc/bashrc && cd #{deploy_to} && sudo bundle install"
4
+ end
5
+
6
+ task :migrate do
7
+ run "source /etc/bashrc && cd #{deploy_to} && RAILS_ENV=#{env} bundle exec rake db:migrate"
8
+ end
9
+
10
+ task :log do
11
+ run "tail -f #{deploy_to}/log/production.log" do |channel, stream, data|
12
+ puts # for an extra line break before the host name
13
+ puts "#{channel[:host]}: #{data}"
14
+ break if stream == :err
15
+ end
16
+ end
17
+
18
+ end
@@ -0,0 +1,5 @@
1
+ namespace :sys do
2
+ task :ps do
3
+ run "ps alx | grep unicorn_zebra_beta.rb"
4
+ end
5
+ end
data/lib/gap/tasks.rb ADDED
@@ -0,0 +1,65 @@
1
+ module Gap
2
+ module Tasks
3
+ def define_bulk_tasks value
4
+ #gap dev start,restart,god
5
+ %w(start reload).each do |com|
6
+ task(com) do
7
+ value["task"].each do |app, commands|
8
+ send(app)
9
+ send(com) if commands[com]
10
+ end
11
+ end
12
+ end
13
+
14
+ task(:stop) do
15
+ value["task"].reverse.each do |app, commands|
16
+ send(app)
17
+ send(commands["stop"])
18
+ end
19
+ end
20
+
21
+ task(:restart) do
22
+ stop
23
+ start
24
+ end
25
+
26
+ task(:god) do
27
+ value["task"].each do |app,commands|
28
+ send(app)
29
+ send(:god)
30
+ end
31
+ end
32
+
33
+ def define_config_tasks value
34
+ value["role"].each { |attr, val| role attr.to_sym, val }
35
+ #value["set"].each { |attr, val| set attr, val }
36
+ value["task"].each do |app, commands|
37
+
38
+ if value["god"]
39
+ task(app) do
40
+ task(:god) do
41
+ god_config_path = File.join( deploy_to, "config/god_#{application}_#{app}.rb")
42
+ god_config = Gap::GodErb.new("./gap/tmpl.erb",application, app, commands)
43
+ upload( god_config.render, god_config_path, :via => :scp)
44
+ sudo "rvm-shell '1.9.2@god' -c 'god load #{god_config_path}'"
45
+ end
46
+
47
+ commands.each do |name, command|
48
+ task(name) do
49
+ sudo "rvm-shell '1.9.2@god' -c 'god #{name} #{app}_#{application}'"
50
+ end
51
+ end
52
+ end
53
+ else
54
+
55
+ task(app) do
56
+ commands.each { |name, command|
57
+ task(name) { run command }}
58
+ end
59
+
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
65
+ end
data/lib/gap/tmpl.erb ADDED
@@ -0,0 +1,71 @@
1
+ God.watch do |w|
2
+ w.name = "<%= "#{@part}_#{@app}" %>"
3
+ w.group = "<%= "#{@app}"%>"
4
+ w.interval = 15.minutes# default
5
+ w.start = "<%= "#{@commands["start"]}"%>"
6
+ w.stop = "<%= "#{@commands["stop"]}"%>"
7
+ w.restart = "<%= "#{@commands["restart"]}"%>"
8
+ <% if @commands["pid_file"] %>
9
+ w.pid_file = "<%= "#{@commands["pid_file"]}" %>"
10
+ <% end %>
11
+
12
+ # clean pid files before start if necessary
13
+ w.behavior(:clean_pid_file)
14
+
15
+ # determine the state on startup
16
+ w.transition(:init, { true => :up, false => :start }) do |on|
17
+ on.condition(:process_running) do |c|
18
+ c.running = true
19
+ end
20
+ end
21
+
22
+ # determine when process has finished starting
23
+ w.transition([:start, :restart], :up) do |on|
24
+ on.condition(:process_running) do |c|
25
+ c.running = true
26
+ end
27
+
28
+ # failsafe
29
+ on.condition(:tries) do |c|
30
+ c.times = 5
31
+ c.transition = :start
32
+ c.notify = {:contacts => 'Lv2'}
33
+ end
34
+ end
35
+
36
+ # start if process is not running
37
+ w.transition(:up, :start) do |on|
38
+ on.condition(:process_running) do |c|
39
+ c.running = false
40
+ c.notify = {:contacts => ['Lv2','Lv3']} #Lv3
41
+ end
42
+ end
43
+
44
+ # restart if memory or cpu is too high
45
+ w.transition(:up, :restart) do |on|
46
+ on.condition(:memory_usage) do |c|
47
+ c.above = 1.gigabytes
48
+ # c.times = [3, 5]
49
+ c.notify = {:contacts => 'Lv2'} #'Lv3'
50
+ end
51
+
52
+ on.condition(:cpu_usage) do |c|
53
+ c.above = 90.percent
54
+ # c.times = [3, 5]
55
+ c.notify = {:contacts => 'Lv2'} #'Lv3'
56
+ end
57
+ end
58
+
59
+ # lifecycle
60
+ w.lifecycle do |on|
61
+ on.condition(:flapping) do |c|
62
+ c.to_state = [:start, :restart]
63
+ c.times = 5
64
+ c.within = 5.minute
65
+ c.transition = :unmonitored
66
+ c.retry_in = 10.minutes
67
+ c.retry_times = 5
68
+ c.retry_within = 2.hours
69
+ end
70
+ end
71
+ end
data/lib/gap.rb ADDED
@@ -0,0 +1,6 @@
1
+ $:.unshift(File.dirname(__FILE__)) unless
2
+ $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
3
+
4
+ module Gap
5
+ VERSION = '0.0.3'
6
+ end
data/script/console ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # File: script/console
3
+ irb = RUBY_PLATFORM =~ /(:?mswin|mingw)/ ? 'irb.bat' : 'irb'
4
+
5
+ libs = " -r irb/completion"
6
+ # Perhaps use a console_lib to store any extra methods I may want available in the cosole
7
+ # libs << " -r #{File.dirname(__FILE__) + '/../lib/console_lib/console_logger.rb'}"
8
+ libs << " -r #{File.dirname(__FILE__) + '/../lib/gap.rb'}"
9
+ puts "Loading gap gem"
10
+ exec "#{irb} #{libs} --simple-prompt"
data/script/destroy ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/destroy'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Destroy.new.run(ARGV)
data/script/generate ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
3
+
4
+ begin
5
+ require 'rubigen'
6
+ rescue LoadError
7
+ require 'rubygems'
8
+ require 'rubigen'
9
+ end
10
+ require 'rubigen/scripts/generate'
11
+
12
+ ARGV.shift if ['--help', '-h'].include?(ARGV[0])
13
+ RubiGen::Base.use_component_sources! [:rubygems, :newgem, :newgem_theme, :test_unit]
14
+ RubiGen::Scripts::Generate.new.run(ARGV)
data/test/test_gap.rb ADDED
@@ -0,0 +1,11 @@
1
+ require File.dirname(__FILE__) + '/test_helper.rb'
2
+
3
+ class TestGap < Test::Unit::TestCase
4
+
5
+ def setup
6
+ end
7
+
8
+ def test_truth
9
+ assert true
10
+ end
11
+ end
@@ -0,0 +1,3 @@
1
+ require 'stringio'
2
+ require 'test/unit'
3
+ require File.dirname(__FILE__) + '/../lib/gap'
metadata ADDED
@@ -0,0 +1,112 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gap
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.3
6
+ platform: ruby
7
+ authors:
8
+ - Takashi Yaguchi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2012-01-20 00:00:00 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rdoc
17
+ prerelease: false
18
+ requirement: &id001 !ruby/object:Gem::Requirement
19
+ none: false
20
+ requirements:
21
+ - - ~>
22
+ - !ruby/object:Gem::Version
23
+ version: "3.10"
24
+ type: :development
25
+ version_requirements: *id001
26
+ - !ruby/object:Gem::Dependency
27
+ name: newgem
28
+ prerelease: false
29
+ requirement: &id002 !ruby/object:Gem::Requirement
30
+ none: false
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: 1.5.3
35
+ type: :development
36
+ version_requirements: *id002
37
+ - !ruby/object:Gem::Dependency
38
+ name: hoe
39
+ prerelease: false
40
+ requirement: &id003 !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: "2.12"
46
+ type: :development
47
+ version_requirements: *id003
48
+ description: FIX (describe your package)
49
+ email:
50
+ - takashimu14@gmail.com
51
+ executables:
52
+ - gap
53
+ extensions: []
54
+
55
+ extra_rdoc_files:
56
+ - History.txt
57
+ - Manifest.txt
58
+ - PostInstall.txt
59
+ files:
60
+ - History.txt
61
+ - Manifest.txt
62
+ - PostInstall.txt
63
+ - README.rdoc
64
+ - Rakefile
65
+ - lib/gap.rb
66
+ - script/console
67
+ - script/destroy
68
+ - script/generate
69
+ - test/test_gap.rb
70
+ - test/test_helper.rb
71
+ - bin/gap
72
+ - lib/gap/cli.rb
73
+ - lib/gap/defalut_recipe.rb
74
+ - lib/gap/god_erb.rb
75
+ - lib/gap/patch.rb
76
+ - lib/gap/tasks.rb
77
+ - lib/gap/tmpl.erb
78
+ - lib/gap/recipes/hg.rb
79
+ - lib/gap/recipes/sys.rb
80
+ - lib/gap/recipes/ruby.rb
81
+ - .gemtest
82
+ homepage: http://github.com/#{github_username}/#{project_name}
83
+ licenses: []
84
+
85
+ post_install_message: PostInstall.txt
86
+ rdoc_options:
87
+ - --main
88
+ - README.rdoc
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: "0"
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: "0"
103
+ requirements: []
104
+
105
+ rubyforge_project: gap
106
+ rubygems_version: 1.8.15
107
+ signing_key:
108
+ specification_version: 3
109
+ summary: FIX (describe your package)
110
+ test_files:
111
+ - test/test_gap.rb
112
+ - test/test_helper.rb