peony 0.1.9 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/peony +2 -2
- data/lib/peony/actions.rb +66 -20
- data/lib/peony/{utils.rb → configure.rb} +13 -40
- data/lib/peony/default.rb +9 -2
- data/lib/peony/rake.rb +1 -1
- data/lib/peony/scope.rb +82 -0
- data/lib/peony/settings.rb +24 -23
- data/lib/peony/shell/basic.rb +19 -17
- data/lib/peony/shell.rb +3 -4
- data/lib/peony/version.rb +1 -1
- data/lib/peony.rb +6 -3
- data/recipes/db/mongo.rake +26 -26
- data/recipes/db/mysql.rake +46 -28
- data/recipes/db/pg.rake +20 -17
- data/recipes/db/redis.rake +22 -20
- data/recipes/elasticsearch.rake +14 -12
- data/recipes/httpd.rake +20 -18
- data/recipes/nginx/www.rake +8 -6
- data/recipes/nginx.rake +25 -23
- data/recipes/php.rake +10 -5
- data/spec/peony_spec.rb +3 -0
- data/spec/scope_spec.rb +48 -0
- data/spec/settings_in_rake_spec.rb +61 -1
- data/spec/settings_spec.rb +2 -2
- data/spec/spec_helper.rb +1 -3
- data/templates/elasticsearch/config.yml.erb +48 -34
- data/templates/elasticsearch/logging.yml.erb +3 -1
- data/templates/httpd/extra/httpd-autoindex.conf.erb +2 -2
- data/templates/httpd/extra/httpd-dav.conf.erb +4 -4
- data/templates/httpd/extra/httpd-mpm.conf.erb +1 -1
- data/templates/httpd/extra/httpd-multilang-errordoc.conf.erb +2 -2
- data/templates/httpd/httpd.conf.erb +8 -8
- data/templates/mongo/master.conf.erb +8 -8
- data/templates/mongo/slave.conf.erb +9 -9
- data/templates/mysql/my.cnf.erb +48 -34
- data/templates/nginx/sites-enabled/php.conf.erb +7 -7
- data/templates/nginx/sites-enabled/static.conf.erb +4 -4
- data/templates/nginx/www.conf.erb +77 -77
- data/templates/redis.conf.erb +13 -13
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75ca157cacb14e3f93c07490a459ff987702e7ae
|
4
|
+
data.tar.gz: 536925e87d651896aa033bf630680186ca7cf172
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb13520d6d2cc97c72fac43cf7cef282bd8384dfc77df789f1ab4200b3c8514b3998f595bbb3efa2c95dc4257cd0629fc7e910afe32d83697f3adc5e22d01411
|
7
|
+
data.tar.gz: e93e4fa4c5e4e6dbc02baef82e6cb5a5a1a5bc1f52bc390f11ccd5a7d4670e5f5eb8d92960b4da08328bc799788b540c2fc3cac18906d48daad5d3c4a6e8a4d7
|
data/bin/peony
CHANGED
@@ -36,8 +36,8 @@ Rake.application.instance_eval do
|
|
36
36
|
require 'peony/rake'
|
37
37
|
|
38
38
|
load_rakefile
|
39
|
-
|
40
|
-
Dir.glob(File.expand_path('../recipes/**/*.rake', __dir__)) do|fn|
|
39
|
+
|
40
|
+
Dir.glob(File.expand_path('../recipes/**/*.rake', __dir__)).reverse.each do|fn|
|
41
41
|
load fn
|
42
42
|
end
|
43
43
|
|
data/lib/peony/actions.rb
CHANGED
@@ -1,31 +1,77 @@
|
|
1
1
|
module Peony
|
2
2
|
module Actions
|
3
3
|
|
4
|
-
def
|
4
|
+
def destination_stack
|
5
5
|
@destination_stack ||= [File.expand_path(Dir.pwd || '')]
|
6
|
-
|
6
|
+
end
|
7
|
+
|
8
|
+
def destination_root
|
9
|
+
destination_stack.last
|
7
10
|
end
|
8
11
|
|
9
12
|
# Returns the given path relative to the absolute root (ie, root where
|
10
13
|
# the script started).
|
11
14
|
#
|
12
|
-
def
|
15
|
+
def original_destination_root(path, remove_dot = true)
|
13
16
|
path = path.dup
|
14
|
-
if path.gsub!(
|
17
|
+
if path.gsub!(destination_stack[0], '.')
|
15
18
|
remove_dot ? (path[2..-1] || '') : path
|
16
19
|
else
|
17
20
|
path
|
18
21
|
end
|
19
22
|
end
|
20
23
|
|
24
|
+
|
25
|
+
def parse_args
|
26
|
+
ARGV.each do |arg|
|
27
|
+
set $1.strip.to_sym, $2 if arg =~ /([^=]+)=(.+)/
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def template(from, to, override=false, sudo=false)
|
32
|
+
template = find_templates(from).first
|
33
|
+
raise "Can't find tempalte #{from} in directory #{template_paths}." unless template
|
34
|
+
raise "File #{to} have already exists." if !override && File.exists?(to)
|
35
|
+
say "copy #{template} to #{to}", :green
|
36
|
+
|
37
|
+
target = sudo ? "/tmp/peony-#{rand(10000)}" : to
|
38
|
+
open(target, 'w+') do |out|
|
39
|
+
out.write(erb(template))
|
40
|
+
end
|
41
|
+
sudo "mv #{tmp} #{to}" if sudo
|
42
|
+
end
|
43
|
+
|
44
|
+
# ### erb
|
45
|
+
# Evaluates an ERB block in the current scope and returns a string.
|
46
|
+
#
|
47
|
+
# a = 1
|
48
|
+
# b = 2
|
49
|
+
#
|
50
|
+
# # Assuming foo.erb is <%= a %> and <%= b %>
|
51
|
+
# puts erb('foo.erb')
|
52
|
+
#
|
53
|
+
# #=> "1 and 2"
|
54
|
+
#
|
55
|
+
# Returns the output string of the ERB template.
|
56
|
+
def erb(file, b=binding)
|
57
|
+
require 'erb'
|
58
|
+
ERB.new(File.read(file), nil, '-').result(b)
|
59
|
+
end
|
60
|
+
|
61
|
+
|
21
62
|
def mkdir_p(*dirs)
|
22
|
-
dirs.each do|dir|
|
63
|
+
dirs.each do |dir|
|
23
64
|
say "mkdir #{dir}", :yellow, true
|
24
65
|
FileUtils.mkdir_p(dir) if !FileTest.exists?(dir)
|
25
66
|
fail "#{dir} must be a directory!" unless FileTest.directory?(dir)
|
26
67
|
end
|
27
68
|
end
|
28
69
|
|
70
|
+
def touch(*files)
|
71
|
+
say "touch #{files}", :yellow, true
|
72
|
+
FileUtils.touch(files)
|
73
|
+
end
|
74
|
+
|
29
75
|
def sudo(cmd)
|
30
76
|
run "sudo #{cmd}"
|
31
77
|
end
|
@@ -88,11 +134,11 @@ module Peony
|
|
88
134
|
dry_run = ENV['dry-run']
|
89
135
|
|
90
136
|
say_status :inside, dir, verbose
|
91
|
-
self.
|
92
|
-
|
137
|
+
self.padding.up if verbose
|
138
|
+
destination_stack.push File.expand_path(dir, destination_root)
|
93
139
|
|
94
140
|
# If the directory doesnt exist and we're not pretending
|
95
|
-
if !File.exist?(destination_root) && !
|
141
|
+
if !File.exist?(destination_root) && !dry_run
|
96
142
|
FileUtils.mkdir_p(destination_root)
|
97
143
|
end
|
98
144
|
|
@@ -103,17 +149,17 @@ module Peony
|
|
103
149
|
FileUtils.cd(destination_root) { block.arity == 1 ? yield(destination_root) : yield }
|
104
150
|
end
|
105
151
|
|
106
|
-
|
107
|
-
self.
|
152
|
+
destination_stack.pop
|
153
|
+
self.padding.down if verbose
|
108
154
|
end
|
109
155
|
|
110
156
|
|
111
157
|
# Goes to the root and execute the given block.
|
112
158
|
#
|
113
159
|
def in_root
|
114
|
-
inside(
|
160
|
+
inside(destination_stack.first) { yield }
|
115
161
|
end
|
116
|
-
|
162
|
+
|
117
163
|
# Loads an external file and execute it in the instance binding.
|
118
164
|
#
|
119
165
|
# ==== Parameters
|
@@ -128,22 +174,22 @@ module Peony
|
|
128
174
|
#
|
129
175
|
def apply(path, config={})
|
130
176
|
verbose = config.fetch(:verbose, true)
|
131
|
-
is_uri
|
132
|
-
path
|
177
|
+
is_uri = path =~ /^https?\:\/\//
|
178
|
+
path = find_recipes(path).first unless is_uri
|
133
179
|
|
134
180
|
say_status :apply, path, verbose
|
135
|
-
self.
|
181
|
+
self.padding.up if verbose
|
136
182
|
|
137
183
|
if is_uri
|
138
|
-
contents = open(path, 'Accept' => 'application/x-peony-template') {|io| io.read }
|
184
|
+
contents = open(path, 'Accept' => 'application/x-peony-template') { |io| io.read }
|
139
185
|
else
|
140
|
-
contents = open(path) {|io| io.read }
|
186
|
+
contents = open(path) { |io| io.read }
|
141
187
|
end
|
142
188
|
|
143
189
|
instance_eval(contents, path)
|
144
|
-
self.
|
190
|
+
self.padding.down if verbose
|
145
191
|
end
|
146
|
-
|
192
|
+
|
147
193
|
# Executes a command returning the contents of the command.
|
148
194
|
#
|
149
195
|
# ==== Parameters
|
@@ -158,7 +204,7 @@ module Peony
|
|
158
204
|
# end
|
159
205
|
#
|
160
206
|
def run(command, config={})
|
161
|
-
destination =
|
207
|
+
destination = original_destination_root(destination_root, false)
|
162
208
|
desc = "#{command} from #{destination.inspect}"
|
163
209
|
|
164
210
|
if config[:with]
|
@@ -1,38 +1,5 @@
|
|
1
1
|
module Peony
|
2
|
-
module
|
3
|
-
|
4
|
-
def parse_args
|
5
|
-
ARGV.each do|arg|
|
6
|
-
set $1.strip.to_sym, $2 if arg =~ /([^=]+)=(.+)/
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def template(from, to, override=false)
|
11
|
-
template = find_templates(from).first
|
12
|
-
raise "Can't find tempalte #{from} in directory #{search_paths}." unless template
|
13
|
-
raise "File #{to} have already exists." if !override && File.exists?(to)
|
14
|
-
say "copy #{template} to #{to}", :green
|
15
|
-
open(to, "w+") do|out|
|
16
|
-
out.write(erb(template))
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# ### erb
|
21
|
-
# Evaluates an ERB block in the current scope and returns a string.
|
22
|
-
#
|
23
|
-
# a = 1
|
24
|
-
# b = 2
|
25
|
-
#
|
26
|
-
# # Assuming foo.erb is <%= a %> and <%= b %>
|
27
|
-
# puts erb('foo.erb')
|
28
|
-
#
|
29
|
-
# #=> "1 and 2"
|
30
|
-
#
|
31
|
-
# Returns the output string of the ERB template.
|
32
|
-
def erb(file, b=binding)
|
33
|
-
require 'erb'
|
34
|
-
ERB.new(File.read(file), nil, '-').result(b)
|
35
|
-
end
|
2
|
+
module Configure
|
36
3
|
|
37
4
|
# ### set
|
38
5
|
# Sets settings.
|
@@ -42,7 +9,7 @@ module Peony
|
|
42
9
|
#
|
43
10
|
# set :domain, 'kickflip.me'
|
44
11
|
def set(key, *args, &block)
|
45
|
-
settings.send :"#{key}=", *args, block
|
12
|
+
settings.send :"#{key}=", *args, &block
|
46
13
|
end
|
47
14
|
|
48
15
|
# ### set_default
|
@@ -59,7 +26,7 @@ module Peony
|
|
59
26
|
# set_default :term_mode, :pretty
|
60
27
|
# settings.term_mode.should == :system
|
61
28
|
def set_default(key, *args, &block)
|
62
|
-
set(key, *args, block) unless settings.send(:
|
29
|
+
set(key, *args, block) unless settings.send(:local?, key.to_sym)
|
63
30
|
end
|
64
31
|
|
65
32
|
# ### settings
|
@@ -73,6 +40,12 @@ module Peony
|
|
73
40
|
@settings ||= Settings.new
|
74
41
|
end
|
75
42
|
|
43
|
+
def scope(name)
|
44
|
+
settings.with_scope(name.to_sym) do
|
45
|
+
yield
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
76
49
|
def template_paths
|
77
50
|
["#{Dir.pwd}/templates", File.expand_path('../../templates', __dir__)]
|
78
51
|
end
|
@@ -92,7 +65,7 @@ module Peony
|
|
92
65
|
def find_in_directories(paths, name, file_only)
|
93
66
|
templates = []
|
94
67
|
paths.each do|path|
|
95
|
-
templates += Dir[File.expand_path(name, path)].reject{|filename| file_only && File.directory?(filename)
|
68
|
+
templates += Dir[File.expand_path(name, path)].reject{|filename| file_only && File.directory?(filename)}
|
96
69
|
end
|
97
70
|
templates
|
98
71
|
end
|
@@ -103,9 +76,9 @@ module Peony
|
|
103
76
|
# See #settings for an explanation.
|
104
77
|
#
|
105
78
|
# Returns things.
|
106
|
-
def method_missing(
|
107
|
-
if settings.
|
108
|
-
settings.
|
79
|
+
def method_missing(method, *args, &blk)
|
80
|
+
if settings.respond_to? method, true
|
81
|
+
settings.__send__(method, *args, &blk)
|
109
82
|
else
|
110
83
|
super
|
111
84
|
end
|
data/lib/peony/default.rb
CHANGED
@@ -14,8 +14,15 @@ set_default :group, 'admin'
|
|
14
14
|
namespace :settings do
|
15
15
|
desc 'List all the settings.'
|
16
16
|
task :list do
|
17
|
-
settings.each do|
|
18
|
-
say "
|
17
|
+
settings.scopes.each do|name, scope|
|
18
|
+
say "scope: #{name}", :yellow
|
19
|
+
settings.with(scope) do
|
20
|
+
scope.each do|k, _|
|
21
|
+
with_padding do
|
22
|
+
say "#{k} = #{settings.send(k)}", :green, true
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
19
26
|
end
|
20
27
|
end
|
21
28
|
end
|
data/lib/peony/rake.rb
CHANGED
data/lib/peony/scope.rb
ADDED
@@ -0,0 +1,82 @@
|
|
1
|
+
module Peony
|
2
|
+
class Scope < Hash
|
3
|
+
attr_reader :name
|
4
|
+
|
5
|
+
def initialize(name = nil, parent = nil)
|
6
|
+
@name = name
|
7
|
+
@parent = parent
|
8
|
+
yield name, self if block_given?
|
9
|
+
end
|
10
|
+
|
11
|
+
alias_method :local?, :has_key?
|
12
|
+
|
13
|
+
def [](key)
|
14
|
+
super || (@parent && @parent[key])
|
15
|
+
end
|
16
|
+
|
17
|
+
## also change the method key?, include?, member?
|
18
|
+
#
|
19
|
+
def has_key?(key)
|
20
|
+
local?(key) || (!@parent.nil? && @parent.key?(key))
|
21
|
+
end
|
22
|
+
|
23
|
+
def []=(key, value)
|
24
|
+
if !local?(key) && @parent && @parent.has_key?(key)
|
25
|
+
@parent.set key, value
|
26
|
+
else
|
27
|
+
store(key, value)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def remove(key, recursively = false)
|
32
|
+
delete(key)
|
33
|
+
if recursively && @parent
|
34
|
+
@parent.remove(key, recursively)
|
35
|
+
end
|
36
|
+
self
|
37
|
+
end
|
38
|
+
|
39
|
+
def respond_to_missing?(method, _ = true)
|
40
|
+
self.include?(method) || method.to_s =~ /[a-z]\w*[?=!]?$/
|
41
|
+
end
|
42
|
+
|
43
|
+
alias_method :set, :[]=
|
44
|
+
alias_method :local, :store
|
45
|
+
|
46
|
+
alias_method :include?, :has_key?
|
47
|
+
alias_method :key?, :has_key?
|
48
|
+
alias_method :member?, :has_key?
|
49
|
+
|
50
|
+
|
51
|
+
def method_missing(method, *args, &block)
|
52
|
+
return evaluate(self.[](method), &block) if has_key?(method)
|
53
|
+
match = method.to_s.match(/(.*?)([?=!]?)$/)
|
54
|
+
case match[2]
|
55
|
+
when '='
|
56
|
+
#self[match[1].to_sym] = args.first || block
|
57
|
+
local(match[1].to_sym, args.first || block)
|
58
|
+
when '?'
|
59
|
+
!!self[match[1].to_sym]
|
60
|
+
when '!'
|
61
|
+
evaluate(fetch(match[1].to_sym), &block) #just fetch local key
|
62
|
+
else
|
63
|
+
evaluate(self[match[1]], &block) #support string key
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def evaluate(value)
|
68
|
+
ret = value.is_a?(Proc) ? value.call : value
|
69
|
+
ret.nil? && block_given? ? yield : ret
|
70
|
+
end
|
71
|
+
|
72
|
+
def new_scope(name)
|
73
|
+
clazz = self.class
|
74
|
+
self.send(name) || Scope.new(name, self) do|_name, _scope|
|
75
|
+
clazz.send :define_method, _name do
|
76
|
+
_scope
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
end
|
data/lib/peony/settings.rb
CHANGED
@@ -1,31 +1,32 @@
|
|
1
1
|
module Peony
|
2
|
-
class Settings
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
evaluate self[method]
|
17
|
-
else
|
18
|
-
block.call unless block.nil?
|
19
|
-
end
|
2
|
+
class Settings
|
3
|
+
attr_reader :current_scope, :root_scope
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@current_scope = @root_scope = Scope.new(:root)
|
7
|
+
end
|
8
|
+
|
9
|
+
def with_scope(name)
|
10
|
+
original_scope = current_scope
|
11
|
+
begin
|
12
|
+
@current_scope = original_scope.new_scope(name)
|
13
|
+
yield
|
14
|
+
ensure
|
15
|
+
@current_scope = original_scope
|
20
16
|
end
|
21
17
|
end
|
22
18
|
|
23
|
-
def
|
24
|
-
if
|
25
|
-
|
19
|
+
def method_missing(method, *args, &block)
|
20
|
+
if current_scope.respond_to?(method, false)
|
21
|
+
current_scope.__send__(method, *args, &block)
|
26
22
|
else
|
27
|
-
|
23
|
+
super
|
28
24
|
end
|
29
25
|
end
|
26
|
+
|
27
|
+
def respond_to_missing?(method, include_all = true)
|
28
|
+
current_scope.respond_to?(method, include_all)
|
29
|
+
end
|
30
|
+
|
30
31
|
end
|
31
|
-
end
|
32
|
+
end
|
data/lib/peony/shell/basic.rb
CHANGED
@@ -10,7 +10,7 @@ module Peony
|
|
10
10
|
# Initialize base, mute and padding to nil.
|
11
11
|
#
|
12
12
|
def initialize #:nodoc:
|
13
|
-
@base, @mute, @padding, @always_force = nil, false,
|
13
|
+
@base, @mute, @padding, @always_force = nil, false, Padding.new, false
|
14
14
|
end
|
15
15
|
|
16
16
|
# Mute everything that's inside given block
|
@@ -28,20 +28,6 @@ module Peony
|
|
28
28
|
@mute
|
29
29
|
end
|
30
30
|
|
31
|
-
# Sets the output padding, not allowing less than zero values.
|
32
|
-
#
|
33
|
-
def padding_to(value)
|
34
|
-
@padding = [0, value].max
|
35
|
-
end
|
36
|
-
|
37
|
-
def padding_up
|
38
|
-
@padding += 1
|
39
|
-
end
|
40
|
-
|
41
|
-
def padding_down
|
42
|
-
@padding += 1
|
43
|
-
end
|
44
|
-
|
45
31
|
# Asks something to the user and receives a response.
|
46
32
|
#
|
47
33
|
# If asked to limit the correct responses, you can pass in an
|
@@ -99,7 +85,7 @@ module Peony
|
|
99
85
|
#
|
100
86
|
def say_status(status, message, log_status = true)
|
101
87
|
return if quiet? || log_status == false
|
102
|
-
spaces = ' ' * (padding + 1)
|
88
|
+
spaces = ' ' * (padding.value + 1)
|
103
89
|
color = log_status.is_a?(Symbol) ? log_status : :green
|
104
90
|
|
105
91
|
status = status.to_s.rjust(12)
|
@@ -299,7 +285,7 @@ module Peony
|
|
299
285
|
protected
|
300
286
|
|
301
287
|
def prepare_message(message, *color)
|
302
|
-
spaces = ' ' * padding
|
288
|
+
spaces = ' ' * padding.value
|
303
289
|
spaces + set_color(message.to_s, *color)
|
304
290
|
end
|
305
291
|
|
@@ -425,5 +411,21 @@ module Peony
|
|
425
411
|
correct_answer
|
426
412
|
end
|
427
413
|
end
|
414
|
+
|
415
|
+
class Padding
|
416
|
+
attr_accessor :value
|
417
|
+
|
418
|
+
def initialize
|
419
|
+
@value = 0
|
420
|
+
end
|
421
|
+
|
422
|
+
def up
|
423
|
+
@value += 1
|
424
|
+
end
|
425
|
+
|
426
|
+
def down
|
427
|
+
@value -= 1
|
428
|
+
end
|
429
|
+
end
|
428
430
|
end
|
429
431
|
end
|
data/lib/peony/shell.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
module Peony
|
2
2
|
module Shell
|
3
3
|
SHELL_DELEGATED_METHODS = [:ask, :error, :set_color, :yes?, :no?, :say, :say_status, :print_in_columns,
|
4
|
-
:print_table, :print_wrapped, :file_collision, :terminal_width, :padding
|
5
|
-
:padding_to, :padding_up, :padding_down]
|
4
|
+
:print_table, :print_wrapped, :file_collision, :terminal_width, :padding]
|
6
5
|
|
7
6
|
# The following classes's code was copied from Thor, available under MIT-LICENSE
|
8
7
|
# Copyright (c) 2008 Yehuda Katz, Eric Hodel, et al.
|
@@ -34,10 +33,10 @@ module Peony
|
|
34
33
|
|
35
34
|
# Yields the given block with padding.
|
36
35
|
def with_padding
|
37
|
-
|
36
|
+
self.padding.up
|
38
37
|
yield
|
39
38
|
ensure
|
40
|
-
|
39
|
+
self.padding.down
|
41
40
|
end
|
42
41
|
|
43
42
|
end
|
data/lib/peony/version.rb
CHANGED
data/lib/peony.rb
CHANGED
@@ -5,11 +5,14 @@ module Peony
|
|
5
5
|
PREFIX = File.dirname(__FILE__)
|
6
6
|
ROOT = File.expand_path('../../', __FILE__)
|
7
7
|
|
8
|
-
autoload :
|
8
|
+
autoload :Scope, 'peony/scope'
|
9
|
+
autoload :Settings, 'peony/settings'
|
10
|
+
autoload :Configure, 'peony/configure'
|
11
|
+
|
9
12
|
autoload :Shell, 'peony/shell'
|
10
|
-
autoload :Actions, 'peony/actions'
|
11
13
|
autoload :LineEditor, 'peony/line_editor'
|
12
|
-
autoload :
|
14
|
+
autoload :Actions, 'peony/actions'
|
15
|
+
|
13
16
|
|
14
17
|
Error = Class.new(Exception)
|
15
18
|
|
data/recipes/db/mongo.rake
CHANGED
@@ -1,30 +1,30 @@
|
|
1
|
-
|
1
|
+
scope :mongo do
|
2
|
+
set_default :mongod, '/usr/local/bin/mongod'
|
3
|
+
set_default :master_name, 'master'
|
4
|
+
set_default :slave_name, 'slave'
|
2
5
|
|
3
|
-
set_default :
|
4
|
-
set_default :
|
6
|
+
set_default :master_dir, ->{ "#{data_dir}/mongo/#{mongo.master_name}" }
|
7
|
+
set_default :slave_dir, ->{ "#{data_dir}/mongo/#{mongo.slave_name}" }
|
8
|
+
set_default :etc_dir, ->{ "#{etc_dir}/mongo" }
|
9
|
+
set_default :log_dir, ->{ "#{log_dir}/mongo" }
|
10
|
+
set_default :run_dir, ->{ "#{run_dir}/mongo" }
|
5
11
|
|
6
|
-
set_default :
|
7
|
-
set_default :
|
8
|
-
set_default :
|
9
|
-
set_default :mongo_log_dir, ->{ "#{log_dir}/mongo" }
|
10
|
-
set_default :mongo_run_dir, ->{ "#{run_dir}/mongo" }
|
12
|
+
set_default :fork, true
|
13
|
+
set_default :jsonp, true
|
14
|
+
set_default :rest, true
|
11
15
|
|
16
|
+
set_default :master_port, 27017
|
17
|
+
set_default :slave_port, 27018
|
18
|
+
set_default :slave_source, ->{ "127.0.0.1:#{mongo.master_port}" }
|
12
19
|
|
13
|
-
set_default :
|
14
|
-
set_default :
|
15
|
-
set_default :mongo_rest , true
|
20
|
+
set_default :master_conf, ->{ "#{mongo.etc_dir}/#{mongo.master_name}.conf" }
|
21
|
+
set_default :slave_conf, ->{ "#{mongo.etc_dir}/#{mongo.slave_name}.conf" }
|
16
22
|
|
17
|
-
set_default :
|
18
|
-
set_default :
|
19
|
-
set_default :
|
20
|
-
|
21
|
-
|
22
|
-
set_default :mongo_slave_conf, ->{ "#{mongo_etc_dir}/#{mongo_slave_name}.conf" }
|
23
|
-
|
24
|
-
set_default :mongo_master_start, ->{ "#{mongod} --config #{mongo_master_conf}" }
|
25
|
-
set_default :mongo_slave_start, ->{ "#{mongod} --config #{mongo_slave_conf}" }
|
26
|
-
set_default :mongo_master_stop, ->{ "kill -2 `cat #{mongo_run_dir}/#{mongo_master_name}.pid`" }
|
27
|
-
set_default :mongo_slave_stop, ->{ "kill -2 `cat #{mongo_run_dir}/#{mongo_slave_name}.pid`" }
|
23
|
+
set_default :master_start, ->{ "#{mongo.mongod} --config #{mongo.master_conf}" }
|
24
|
+
set_default :slave_start, ->{ "#{mongo.mongod} --config #{mongo.slave_conf}" }
|
25
|
+
set_default :master_stop, ->{ "kill -2 `cat #{mongo.run_dir}/#{mongo.master_name}.pid`" }
|
26
|
+
set_default :slave_stop, ->{ "kill -2 `cat #{mongo.run_dir}/#{mongo.slave_name}.pid`" }
|
27
|
+
end
|
28
28
|
|
29
29
|
|
30
30
|
namespace :db do
|
@@ -32,9 +32,9 @@ namespace :db do
|
|
32
32
|
|
33
33
|
desc 'Create the directory for mongodb, and copy mongo config file to etc directory.'
|
34
34
|
task :init do
|
35
|
-
mkdir_p(
|
36
|
-
template('mongo/master.conf.erb',
|
37
|
-
template('mongo/slave.conf.erb',
|
35
|
+
mkdir_p(mongo.master_dir, mongo.slave_dir, mongo.etc_dir, mongo.log_dir, mongo.run_dir)
|
36
|
+
template('mongo/master.conf.erb', mongo.master_conf, true)
|
37
|
+
template('mongo/slave.conf.erb', mongo.slave_conf, true)
|
38
38
|
end
|
39
39
|
|
40
40
|
[:master, :slave].each do|ns|
|
@@ -42,7 +42,7 @@ namespace :db do
|
|
42
42
|
[:start, :stop].each do|t|
|
43
43
|
desc "#{t} mongodb #{ns}"
|
44
44
|
task t do
|
45
|
-
run
|
45
|
+
run mongo.send("#{ns}_#{t}")
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|