h2ocube_rails_tasks 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README.rdoc +43 -0
- data/Rakefile +2 -0
- data/h2ocube_rails_tasks.gemspec +22 -0
- data/lib/h2ocube_rails_tasks/helper.rb +14 -0
- data/lib/h2ocube_rails_tasks/tasks/git.rb +30 -0
- data/lib/h2ocube_rails_tasks/tasks/mongodb.rb +46 -0
- data/lib/h2ocube_rails_tasks/tasks/resque.rb +55 -0
- data/lib/h2ocube_rails_tasks/tasks/unicorn.rb +31 -0
- data/lib/h2ocube_rails_tasks.rb +10 -0
- metadata +72 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
== SUMMARY
|
2
|
+
|
3
|
+
This is plugin to add some useful tasks to rails.
|
4
|
+
|
5
|
+
# has .git folder
|
6
|
+
rake git:clear # Clear files in .gitignore
|
7
|
+
rake git:commit[comment] # Git commit with your comment
|
8
|
+
rake git:pull # Git pull
|
9
|
+
rake git:push[comment] # Git push with your comment
|
10
|
+
|
11
|
+
# has unicorn.rb
|
12
|
+
rake unicorn:restart # Hot restart unicorn server
|
13
|
+
rake unicorn:start # Start unicorn server
|
14
|
+
rake unicorn:stop # Stop unicorn server
|
15
|
+
|
16
|
+
# has config/mongoid.yml
|
17
|
+
rake mongodb:start # Start Mongodb
|
18
|
+
rake mongodb:stop # Stop Mongodb
|
19
|
+
rake mongodb:dump # mongodump
|
20
|
+
rake mongodb:clear # Clear mongo folder
|
21
|
+
rake mongodb:restore # mongorestore
|
22
|
+
rake mongodb:repair # Repair Mongodb
|
23
|
+
|
24
|
+
# has initializers/resque.rb
|
25
|
+
rake resque:clear # Clear Resque data
|
26
|
+
rake resque:debug # Start Resque for debug
|
27
|
+
rake resque:start # Start Resque daemon worker
|
28
|
+
rake resque:stop # Stop Resque worker
|
29
|
+
rake resque:web # Start Resque web interface
|
30
|
+
|
31
|
+
== Getting Started
|
32
|
+
|
33
|
+
1. adding gem to Gemfile
|
34
|
+
|
35
|
+
gem 'h2ocube_rails_tasks'
|
36
|
+
|
37
|
+
2. update bundle
|
38
|
+
|
39
|
+
bundle install
|
40
|
+
|
41
|
+
3. try `rake -T`, and enjoy it :)
|
42
|
+
|
43
|
+
take -T
|
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = 'h2ocube_rails_tasks'
|
6
|
+
s.version = '0.0.1'
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ['Ben']
|
9
|
+
s.email = ['ben@h2ocube.com']
|
10
|
+
s.homepage = 'https://github.com/h2ocube/h2ocube_rails_tasks'
|
11
|
+
s.summary = %q{}
|
12
|
+
s.description = %q{}
|
13
|
+
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
17
|
+
s.require_paths = ["lib"]
|
18
|
+
|
19
|
+
s.required_ruby_version = '>= 1.9'
|
20
|
+
|
21
|
+
s.add_dependency 'rainbow'
|
22
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rainbow'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
def zfben_rails_rake_system cmd
|
6
|
+
cmd = cmd
|
7
|
+
STDOUT.print (cmd + "\n").color(:green)
|
8
|
+
zfben_rails_rake_err unless system cmd
|
9
|
+
end
|
10
|
+
|
11
|
+
def zfben_rails_rake_err msg = 'Failed!'
|
12
|
+
STDERR.print (msg + "\n").color(:red)
|
13
|
+
exit!
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
if File.exists? Rails.root.join('.git')
|
2
|
+
namespace :git do
|
3
|
+
desc 'Git pull'
|
4
|
+
task :pull do
|
5
|
+
zfben_rails_rake_system 'git pull'
|
6
|
+
end
|
7
|
+
|
8
|
+
desc 'Git commit with your comment'
|
9
|
+
task :commit, [:comment] do |task, args|
|
10
|
+
args = args.to_hash
|
11
|
+
zfben_rails_rake_system 'git add .'
|
12
|
+
comment = args.has_key?(:comment) ? args[:comment] : `git status`
|
13
|
+
zfben_rails_rake_system "git commit -m '#{comment}' -a"
|
14
|
+
end
|
15
|
+
|
16
|
+
desc 'Git push with your comment'
|
17
|
+
task :push, [:comment] => [:commit] do |task, comment|
|
18
|
+
zfben_rails_rake_system 'git push'
|
19
|
+
end
|
20
|
+
|
21
|
+
desc 'Clear files in .gitignore'
|
22
|
+
task :clear do
|
23
|
+
unless File.exists? Rails.root.join('.gitignore')
|
24
|
+
zfben_rails_rake_err '.gitignore is not exists!'
|
25
|
+
else
|
26
|
+
zfben_rails_rake_system 'git clean -dfX'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
if File.exist? Rails.root.join('config/mongoid.yml')
|
2
|
+
namespace :mongodb do
|
3
|
+
config = YAML.load(File.read(Rails.root.join('config/mongoid.yml')))[Rails.env.to_s]['sessions']['default']
|
4
|
+
db = config['database']
|
5
|
+
host = config['hosts'][0].split(':')[0]
|
6
|
+
port = config['hosts'][0].split(':')[1]
|
7
|
+
|
8
|
+
desc 'Start Mongodb'
|
9
|
+
task :start do
|
10
|
+
zfben_rails_rake_system "mkdir #{Rails.root}/mongo" unless File.exists?(Rails.root.join('mongo'))
|
11
|
+
zfben_rails_rake_system "mkdir #{Rails.root}/log" unless File.exists?(Rails.root.join('log'))
|
12
|
+
zfben_rails_rake_system "mongod --nohttpinterface --nojournal --port #{port} --bind_ip #{host} --dbpath #{Rails.root}/mongo --fork --logpath #{Rails.root}/log/mongodb.log"
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Stop Mongodb'
|
16
|
+
task :stop do
|
17
|
+
path = Rails.root.join('mongo/mongod.lock').to_s
|
18
|
+
if File.exists?(path)
|
19
|
+
zfben_rails_rake_system "kill `cat #{path}`"
|
20
|
+
zfben_rails_rake_system 'rm ' + path
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Clear mongo folder'
|
25
|
+
task :clear do
|
26
|
+
zfben_rails_rake_system 'rm -r mongo/*'
|
27
|
+
end
|
28
|
+
|
29
|
+
backup = "mongodump --host #{host} --port #{port} --db #{db}"
|
30
|
+
desc backup
|
31
|
+
task :dump do
|
32
|
+
zfben_rails_rake_system backup
|
33
|
+
end
|
34
|
+
|
35
|
+
restore = "mongorestore --host #{host} --port #{port}"
|
36
|
+
desc restore
|
37
|
+
task :restore do
|
38
|
+
zfben_rails_rake_system restore
|
39
|
+
end
|
40
|
+
|
41
|
+
desc 'Repair Mongodb'
|
42
|
+
task :repair do
|
43
|
+
"mongod --nohttpinterface --nojournal --port #{port} --bind_ip #{host} --dbpath #{Rails.root}/mongo --repair"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
if File.exists? Rails.root.join('config/initializers/resque.rb')
|
2
|
+
namespace :resque do
|
3
|
+
require Rails.root.join('config/initializers/resque.rb')
|
4
|
+
require 'resque/tasks'
|
5
|
+
if defined?(Resque::Scheduler)
|
6
|
+
require 'resque_scheduler/tasks'
|
7
|
+
end
|
8
|
+
|
9
|
+
task :setup => :environment
|
10
|
+
|
11
|
+
task :_work => ['resque:preload', 'resque:setup'] do
|
12
|
+
work = Resque::Worker.new('*')
|
13
|
+
Process.daemon(true)
|
14
|
+
File.open(Rails.root.join('tmp/resque.pid'), 'w') { |f| f << work.pid }
|
15
|
+
work.work(5)
|
16
|
+
end
|
17
|
+
|
18
|
+
if defined?(Resque::Scheduler)
|
19
|
+
task :_scheduler => 'resque:setup' do
|
20
|
+
Process.daemon(true)
|
21
|
+
File.open(Rails.root.join('tmp/scheduler.pid'), 'w') { |f| f << Process.pid.to_s }
|
22
|
+
Resque::Scheduler.run
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
desc 'Start Resque daemon worker'
|
27
|
+
task :start => 'resque:stop' do
|
28
|
+
zfben_rails_rake_system "bash -c 'RAILS_ENV=production rake resque:_work'"
|
29
|
+
if defined?(Resque::Scheduler)
|
30
|
+
zfben_rails_rake_system "bash -c 'RAILS_ENV=production rake resque:_scheduler'"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
desc 'Stop Resque worker'
|
35
|
+
task :stop do
|
36
|
+
['resque', 'scheduler'].each do |name|
|
37
|
+
path = Rails.root.join('tmp/' + name + '.pid')
|
38
|
+
if File.exists?(path)
|
39
|
+
zfben_rails_rake_system "kill `cat #{path}`;rm #{path}"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
desc 'Clear Resque data'
|
45
|
+
task :clear do
|
46
|
+
Resque.redis.keys('*').each{ |k| Resque.redis.del k }
|
47
|
+
end
|
48
|
+
|
49
|
+
desc 'Start Resque web interface'
|
50
|
+
task :web do
|
51
|
+
require 'resque/server'
|
52
|
+
Resque::Server.run!
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
if File.exists? Rails.root.join('unicorn.rb')
|
2
|
+
namespace :unicorn do
|
3
|
+
desc 'Start unicorn server'
|
4
|
+
task :start => :stop do
|
5
|
+
if File.exists? Rails.root.join('config.ru')
|
6
|
+
cmd = 'unicorn'
|
7
|
+
else
|
8
|
+
cmd = 'unicorn_rails'
|
9
|
+
end
|
10
|
+
cmd << ' -c unicorn.rb -E production -D'
|
11
|
+
zfben_rails_rake_system 'mkdir tmp' unless File.exists? Rails.root.join('tmp')
|
12
|
+
zfben_rails_rake_system cmd
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Stop unicorn server'
|
16
|
+
task :stop do
|
17
|
+
if File.exists? Rails.root.join('tmp/unicorn.pid')
|
18
|
+
zfben_rails_rake_system 'kill -QUIT `cat tmp/unicorn.pid`'
|
19
|
+
sleep 1
|
20
|
+
zfben_rails_rake_system 'rm tmp/unicorn.pid' if File.exists? Rails.root.join('tmp/unicorn.pid')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
desc 'Hot restart unicorn server'
|
25
|
+
task :restart do
|
26
|
+
if File.exists? Rails.root.join('tmp/unicorn.pid')
|
27
|
+
zfben_rails_rake_system 'kill -USR2 `cat tmp/unicorn.pid`'
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module ZfbenRailsRake
|
2
|
+
class Railtie < Rails::Railtie
|
3
|
+
railtie_name :h2ocube_rails_tasks
|
4
|
+
rake_tasks do
|
5
|
+
path = File.dirname(__FILE__) << '/h2ocube_rails_tasks'
|
6
|
+
require path + '/helper.rb'
|
7
|
+
Dir[path + '/tasks/*.rb'].each{ |f| require f }
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
metadata
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: h2ocube_rails_tasks
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ben
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-30 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rainbow
|
16
|
+
requirement: !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: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: ''
|
31
|
+
email:
|
32
|
+
- ben@h2ocube.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- Gemfile
|
39
|
+
- README.rdoc
|
40
|
+
- Rakefile
|
41
|
+
- h2ocube_rails_tasks.gemspec
|
42
|
+
- lib/h2ocube_rails_tasks.rb
|
43
|
+
- lib/h2ocube_rails_tasks/helper.rb
|
44
|
+
- lib/h2ocube_rails_tasks/tasks/git.rb
|
45
|
+
- lib/h2ocube_rails_tasks/tasks/mongodb.rb
|
46
|
+
- lib/h2ocube_rails_tasks/tasks/resque.rb
|
47
|
+
- lib/h2ocube_rails_tasks/tasks/unicorn.rb
|
48
|
+
homepage: https://github.com/h2ocube/h2ocube_rails_tasks
|
49
|
+
licenses: []
|
50
|
+
post_install_message:
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ! '>='
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '1.9'
|
60
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ! '>='
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '0'
|
66
|
+
requirements: []
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.8.24
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: ''
|
72
|
+
test_files: []
|