zfben_rails_rake 0.0.13 → 0.0.14

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/README.rdoc CHANGED
@@ -2,18 +2,20 @@
2
2
 
3
3
  This is plugin to add some useful tasks to rails.
4
4
 
5
- rake git:clear # clear files in .gitignore
6
- rake git:commit[comment] # git commit with your comment
7
- rake git:pull # git pull
8
- rake git:push[comment] # git push with your comment
9
- rake git:copy # copy .gitignore to rails root path
10
-
11
- rake unicorn:copy[processes,port] # copy unicorn.rb to root path
12
- rake unicorn:restart[env,config] # restart server
13
- rake unicorn:start[env,config] # start server
14
- rake unicorn:stop # stop server
15
-
16
- rake log:analytics # analytics log file
5
+ rake git:clear # Clear files in .gitignore
6
+ rake git:commit[comment] # Git commit with your comment
7
+ rake git:pull # Git pull
8
+ rake git:push[comment] # Git push with your comment
9
+
10
+ rake unicorn:restart # Hot restart unicorn server
11
+ rake unicorn:start # Start unicorn server
12
+ rake unicorn:stop # Stop unicorn server
13
+
14
+ rake mongodb:backup # mongodump
15
+ rake mongodb:clear # Clear mongo folder
16
+ rake mongodb:restore # mongorestore
17
+ rake mongodb:start # Start Mongodb
18
+ rake mongodb:stop # Stop Mongodb
17
19
 
18
20
  == Getting Started
19
21
 
data/bin/zfben ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ if File.exists?('Rakefile')
3
+ system "rake #{ARGV.join(' ')} -E \"require 'zfben_rails_rake'\""
4
+ else
5
+ print "Sorry, Not found Rakefile.\n"
6
+ end
@@ -0,0 +1,19 @@
1
+ require 'rainbow'
2
+ require 'fileutils'
3
+ require 'yaml'
4
+
5
+ def sys cmd
6
+ STDOUT.print (cmd + "\n").color(:green)
7
+ err '' unless system cmd
8
+ end
9
+
10
+ def err msg
11
+ STDOUT.print (msg + "\n").color(:red)
12
+ exit!
13
+ end
14
+
15
+ if defined?(Rails) && !Rails.root.nil?
16
+ ROOT = File.realpath(Rails.root).to_s
17
+ else
18
+ ROOT = File.realpath('.').to_s
19
+ end
@@ -1,34 +1,30 @@
1
- namespace :git do
2
- desc 'git pull'
3
- task :pull do
4
- sys 'git pull'
5
- end
1
+ if File.exists?(ROOT + '/.git')
2
+ namespace :git do
3
+ desc 'Git pull'
4
+ task :pull do
5
+ sys 'git pull'
6
+ end
6
7
 
7
- desc 'git commit with your comment'
8
- task :commit, [:comment] do |task, args|
9
- args = args.to_hash
10
- sys "git add ."
11
- comment = args.has_key?(:comment) ? args[:comment] : `git status`
12
- sys "git commit -m '#{comment}' -a"
13
- end
14
-
15
- desc 'git push with your comment'
16
- task :push, [:comment] => [:commit] do |task, comment|
17
- sys 'git push'
18
- end
19
-
20
- desc 'copy .gitignore to rails root path'
21
- task :copy do
22
- sys 'cp ' << File.join(ZfbenRailsRakePath, 'static', '.gitignore') << ' ' << Rails.root.to_s
23
- end
24
-
25
- desc 'clear files in .gitignore'
26
- task :clear do
27
- path = File.join(Rails.root, '.gitignore')
28
- unless File.exists? path
29
- err '.gitignore is not exists! Please run `rake git:copy` first'
30
- else
31
- sys 'git clean -dfX'
8
+ desc 'Git commit with your comment'
9
+ task :commit, [:comment] do |task, args|
10
+ args = args.to_hash
11
+ sys "git add ."
12
+ comment = args.has_key?(:comment) ? args[:comment] : `git status`
13
+ sys "git commit -m '#{comment}' -a"
14
+ end
15
+
16
+ desc 'Git push with your comment'
17
+ task :push, [:comment] => [:commit] do |task, comment|
18
+ sys 'git push'
19
+ end
20
+
21
+ desc 'Clear files in .gitignore'
22
+ task :clear do
23
+ unless File.exists? ROOT + '/.gitignore'
24
+ err '.gitignore is not exists!'
25
+ else
26
+ sys 'git clean -dfX'
27
+ end
32
28
  end
33
29
  end
34
30
  end
@@ -0,0 +1,36 @@
1
+ if File.exist?(ROOT + '/config/mongoid.yml')
2
+ config = YAML.load(File.read(ROOT + '/config/mongoid.yml'))
3
+ namespace :mongodb do
4
+ backup = "mongodump --host #{config['production']['host']} --port #{config['production']['port']}"
5
+ desc backup
6
+ task :backup do
7
+ sys backup
8
+ end
9
+
10
+ restore = "mongorestore --host #{config['production']['host']} --port #{config['production']['port']}"
11
+ desc restore
12
+ task :restore do
13
+ sys restore
14
+ end
15
+
16
+ desc 'Start Mongodb'
17
+ task :start do
18
+ sys "mkdir #{ROOT}/mongo" unless File.exists?(ROOT + '/mongo')
19
+ sys "mongod --nohttpinterface --nojournal --port #{config['production']['port']} --bind_ip #{config['production']['host']} --dbpath #{path}/mongo --fork --logpath #{path}/log/mongodb.log"
20
+ end
21
+
22
+ desc 'Stop Mongodb'
23
+ task :stop do
24
+ path = ROOT + '/mongo/mongod.lock'
25
+ if File.exists?(path)
26
+ sys "kill `cat #{path}`"
27
+ sys 'rm ' + path
28
+ end
29
+ end
30
+
31
+ desc 'Clear mongo folder'
32
+ task :clear do
33
+ sys 'rm -r mongo/*'
34
+ end
35
+ end
36
+ end
@@ -1,32 +1,27 @@
1
- namespace :unicorn do
2
- desc 'start server'
3
- task :start, [:env, :config] do |task, args|
4
- args = { :env => 'production', :config => 'unicorn.rb' }.merge args.to_hash
5
- cmd = 'unicorn_rails'
6
- cmd << ' -c ' << args[:config] if File.exists?(File.join(Rails.root, args[:config]))
7
- cmd << ' -E ' << args[:env]
8
- sys cmd << ' -D'
9
- end
10
-
11
- desc 'stop server'
12
- task :stop do
13
- sys 'kill -QUIT `cat tmp/unicorn.pid`' if File.exists? File.join(Rails.root, 'tmp', 'unicorn.pid')
14
- sleep 1
15
- sys 'rm -r tmp/*'
16
- end
17
-
18
- desc 'restart server'
19
- task :restart, [:env, :config] => [:stop, :start]
20
-
21
- desc 'copy unicorn.rb to root path'
22
- task :copy, [:processes] do |task, args|
23
- path = File.join(Rails.root, 'unicorn.rb')
24
- if File.exists? path
25
- err 'unicorn.rb is exists! Please remove it and run again.'
26
- else
27
- args = { :processes => 1 }.merge args.to_hash
28
- p file = "# Added by zfben_rails_rake\nworker_processes #{args[:processes]}\nlisten File.realpath(File.dirname(__FILE__)) << '/tmp/unicorn.sock', :tcp_nopush => true, :tcp_nodelay => true\npid 'tmp/unicorn.pid'\npreload_app true\n# End zfben_rails_rake"
29
- File.open(path, 'w'){ |f| f.write file }
1
+ if File.exists? ROOT + '/unicorn.rb'
2
+ namespace :unicorn do
3
+ desc 'Start unicorn server'
4
+ task :start do
5
+ if File.exists? ROOT + '/config.ru'
6
+ cmd = 'unicorn'
7
+ else
8
+ cmd = 'unicorn_rails'
9
+ end
10
+ sys cmd << ' -c unicorn.rb -E production -D'
11
+ end
12
+
13
+ desc 'Stop unicorn server'
14
+ task :stop do
15
+ if File.exists? ROOT + '/tmp/unicorn.pid'
16
+ sys 'kill -QUIT `cat tmp/unicorn.pid`'
17
+ sleep 1
18
+ end
19
+ sys 'rm -r tmp/*'
20
+ end
21
+
22
+ desc 'Hot restart unicorn server'
23
+ task :restart do
24
+ sys 'kill -HUP `cat tmp/unicorn.pid`'
30
25
  end
31
26
  end
32
27
  end
@@ -1,11 +1,19 @@
1
1
  ZfbenRailsRakePath = File.join File.dirname(__FILE__), 'zfben_rails_rake'
2
2
 
3
- module ZfbenRailsRake
4
- class Railtie < Rails::Railtie
5
- railtie_name :zfben_rails_rake
6
-
7
- rake_tasks do
8
- Dir[File.join(ZfbenRailsRakePath, 'tasks', '*')].each{ |f| load f }
3
+ if defined? Rails
4
+ module ZfbenRailsRake
5
+ class Railtie < Rails::Railtie
6
+ railtie_name :zfben_rails_rake
7
+ rake_tasks do
8
+ require ZfbenRailsRakePath + '/helper.rb'
9
+ Dir[File.join(ZfbenRailsRakePath, 'tasks', '*')].each{ |f| require f }
10
+ end
9
11
  end
10
12
  end
13
+ else
14
+ require ZfbenRailsRakePath + '/helper.rb'
15
+ Dir[File.join(ZfbenRailsRakePath, 'tasks', '*')].each{ |f| require f }
16
+ task :default do
17
+ p 'ok'
18
+ end
11
19
  end
@@ -1,26 +1,30 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
- require "zfben_rails_rake/version"
4
3
 
5
4
  Gem::Specification.new do |s|
6
- s.name = "zfben_rails_rake"
7
- s.version = ZfbenRailsRake::VERSION
5
+ s.name = 'zfben_rails_rake'
6
+ s.version = '0.0.14'
8
7
  s.platform = Gem::Platform::RUBY
9
- s.authors = ["Ben"]
10
- s.email = ["ben@zfben.com"]
11
- s.homepage = "https://github.com/benz303/zfben_rails_rake"
8
+ s.authors = ['Ben']
9
+ s.email = ['ben@zfben.com']
10
+ s.homepage = 'https://github.com/benz303/zfben_rails_rake'
12
11
  s.summary = %q{}
13
12
  s.description = %q{}
14
-
15
- s.rubyforge_project = "zfben_rails_rake"
13
+
14
+ s.post_install_message =%q{********************************************************************************
15
+ Thank you for using zfben_rails_rake!
16
+
17
+ Please follow @zfben on Twitter for announcements, updates, and news.
18
+ https://twitter.com/zfben
19
+ ********************************************************************************
20
+ }
16
21
 
17
22
  s.files = `git ls-files`.split("\n")
18
23
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
24
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
25
  s.require_paths = ["lib"]
21
26
 
27
+ s.required_ruby_version = '>= 1.9'
28
+
22
29
  s.add_dependency 'rainbow'
23
- s.add_dependency 'unicorn'
24
- s.add_dependency 'request-log-analyzer'
25
- s.add_dependency 'net-ssh'
26
30
  end
metadata CHANGED
@@ -1,112 +1,70 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: zfben_rails_rake
3
- version: !ruby/object:Gem::Version
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.14
4
5
  prerelease:
5
- version: 0.0.13
6
6
  platform: ruby
7
- authors:
7
+ authors:
8
8
  - Ben
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
-
13
- date: 2011-08-05 00:00:00 +08:00
14
- default_executable:
15
- dependencies:
16
- - !ruby/object:Gem::Dependency
12
+ date: 2011-10-28 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
17
15
  name: rainbow
18
- prerelease: false
19
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &16583680 !ruby/object:Gem::Requirement
20
17
  none: false
21
- requirements:
22
- - - ">="
23
- - !ruby/object:Gem::Version
24
- version: "0"
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
25
22
  type: :runtime
26
- version_requirements: *id001
27
- - !ruby/object:Gem::Dependency
28
- name: unicorn
29
23
  prerelease: false
30
- requirement: &id002 !ruby/object:Gem::Requirement
31
- none: false
32
- requirements:
33
- - - ">="
34
- - !ruby/object:Gem::Version
35
- version: "0"
36
- type: :runtime
37
- version_requirements: *id002
38
- - !ruby/object:Gem::Dependency
39
- name: request-log-analyzer
40
- prerelease: false
41
- requirement: &id003 !ruby/object:Gem::Requirement
42
- none: false
43
- requirements:
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: "0"
47
- type: :runtime
48
- version_requirements: *id003
49
- - !ruby/object:Gem::Dependency
50
- name: net-ssh
51
- prerelease: false
52
- requirement: &id004 !ruby/object:Gem::Requirement
53
- none: false
54
- requirements:
55
- - - ">="
56
- - !ruby/object:Gem::Version
57
- version: "0"
58
- type: :runtime
59
- version_requirements: *id004
60
- description: ""
61
- email:
24
+ version_requirements: *16583680
25
+ description: ''
26
+ email:
62
27
  - ben@zfben.com
63
- executables: []
64
-
28
+ executables:
29
+ - zfben
65
30
  extensions: []
66
-
67
31
  extra_rdoc_files: []
68
-
69
- files:
32
+ files:
70
33
  - .gitignore
71
34
  - Gemfile
72
35
  - README.rdoc
73
36
  - Rakefile
37
+ - bin/zfben
74
38
  - lib/zfben_rails_rake.rb
75
- - lib/zfben_rails_rake/static/.gitignore
39
+ - lib/zfben_rails_rake/helper.rb
76
40
  - lib/zfben_rails_rake/tasks/git.rb
77
- - lib/zfben_rails_rake/tasks/helper.rb
78
- - lib/zfben_rails_rake/tasks/log.rb
79
- - lib/zfben_rails_rake/tasks/remote.rb
41
+ - lib/zfben_rails_rake/tasks/mongodb.rb
80
42
  - lib/zfben_rails_rake/tasks/unicorn.rb
81
- - lib/zfben_rails_rake/version.rb
82
43
  - zfben_rails_rake.gemspec
83
- has_rdoc: true
84
44
  homepage: https://github.com/benz303/zfben_rails_rake
85
45
  licenses: []
86
-
87
- post_install_message:
46
+ post_install_message: ! "********************************************************************************\n
47
+ \ Thank you for using zfben_rails_rake!\n \n Please follow @zfben on Twitter for
48
+ announcements, updates, and news.\n https://twitter.com/zfben\n********************************************************************************\n"
88
49
  rdoc_options: []
89
-
90
- require_paths:
50
+ require_paths:
91
51
  - lib
92
- required_ruby_version: !ruby/object:Gem::Requirement
52
+ required_ruby_version: !ruby/object:Gem::Requirement
93
53
  none: false
94
- requirements:
95
- - - ">="
96
- - !ruby/object:Gem::Version
97
- version: "0"
98
- required_rubygems_version: !ruby/object:Gem::Requirement
54
+ requirements:
55
+ - - ! '>='
56
+ - !ruby/object:Gem::Version
57
+ version: '1.9'
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
59
  none: false
100
- requirements:
101
- - - ">="
102
- - !ruby/object:Gem::Version
103
- version: "0"
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
104
64
  requirements: []
105
-
106
- rubyforge_project: zfben_rails_rake
107
- rubygems_version: 1.6.2
65
+ rubyforge_project:
66
+ rubygems_version: 1.8.10
108
67
  signing_key:
109
68
  specification_version: 3
110
- summary: ""
69
+ summary: ''
111
70
  test_files: []
112
-
@@ -1,7 +0,0 @@
1
- *.lock
2
- *.log
3
- *.swp
4
- log/*
5
- tmp/*
6
- public/caches
7
- public/assets
@@ -1,10 +0,0 @@
1
- require 'rainbow'
2
- def sys cmd
3
- STDOUT.print (cmd + "\n").color(:black).background(:white)
4
- system cmd
5
- end
6
-
7
- def err msg
8
- STDOUT.print (msg + "\n").color(:yellow).background(:red)
9
- exit!
10
- end
@@ -1,8 +0,0 @@
1
- namespace :log do
2
- desc 'analytics log file'
3
- task :analytics do
4
- Dir[File.join(Rails.root, 'log', '*.log')].each do |log|
5
- sys 'request-log-analyzer ' + log
6
- end
7
- end
8
- end
@@ -1,94 +0,0 @@
1
- desc 'do remote job'
2
- task :remote, [:job] do |task, args|
3
- args = args.to_hash
4
- err 'No job found' unless args.has_key? :job
5
- job = File.join Rails.root, args[:key] + '.rb'
6
- err args[:job] + '.rb is not exists!' unless File.exists? release
7
-
8
- require 'net/ssh'
9
- @config = {}
10
-
11
- def ssh user_host, *options
12
- user_host = user_host.split '@'
13
- if user_host.length != 2
14
- err 'ssh error, you should set ssh like `username@host`'
15
- else
16
- @config[:ssh] = {
17
- :user => user_host[0],
18
- :host => user_host[1],
19
- :options => options[0]
20
- }
21
- end
22
- end
23
-
24
- def remote_path path
25
- @config[:remote_path] = path
26
- end
27
-
28
- def before_connect &block
29
- if block
30
- @cmd_list = []
31
- block.call
32
- if @cmd_list.length > 0
33
- @config[:before_connect] = @cmd_list
34
- end
35
- end
36
- end
37
-
38
- def after_connect &block
39
- if block
40
- @cmd_list = []
41
- block.call
42
- if @cmd_list.length > 0
43
- @config[:after_connect] = @cmd_list
44
- end
45
- end
46
- end
47
-
48
- def rake task
49
- @cmd_list.push 'rake ' + task
50
- end
51
-
52
- def run cmd
53
- @cmd_list.push 'run ' + cmd
54
- end
55
-
56
- load job
57
-
58
- p @config
59
-
60
- if @config.has_key?(:before_connect)
61
- @config[:before_connect].each do |cmd|
62
- sys cmd
63
- end
64
- end
65
-
66
- Net::SSH.start(@config[:ssh][:host], @config[:ssh][:user]) do |net|
67
- @net = net
68
- def exec cmd
69
- p "#{@config[:ssh][:user]}@#{@config[:ssh][:host]}: " + cmd
70
- cmd = "cd #{@config[:remote_path]};#{cmd}"
71
- channel = @net.open_channel do |ch|
72
- ch.exec cmd do |ch, success|
73
- err "could not execute command: #{cmd}" unless success
74
-
75
- ch.on_data do |c, data|
76
- data.split("\n").each{ |s| p s }
77
- end
78
-
79
- ch.on_extended_data do |c, type, data|
80
- err data
81
- end
82
- end
83
- end
84
- channel.wait
85
- end
86
-
87
- p 'ssh connect success'
88
- if @config.has_key?(:after_connect)
89
- @config[:after_connect].each do |cmd|
90
- exec cmd
91
- end
92
- end
93
- end
94
- end
@@ -1,3 +0,0 @@
1
- module ZfbenRailsRake
2
- VERSION = "0.0.13"
3
- end