lsync 1.2.5 → 2.0.2
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.md +51 -0
- data/lib/lsync.rb +0 -23
- data/lib/lsync/action.rb +97 -92
- data/lib/lsync/actions/darwin/disk +5 -5
- data/lib/lsync/actions/generic/prune +29 -7
- data/lib/lsync/actions/generic/rotate +52 -40
- data/lib/lsync/actions/linux/disk +11 -11
- data/lib/lsync/actions/linux/terminal +2 -0
- data/lib/lsync/directory.rb +49 -35
- data/lib/lsync/error.rb +30 -30
- data/lib/lsync/event_handler.rb +72 -0
- data/lib/lsync/event_timer.rb +80 -0
- data/lib/lsync/method.rb +19 -185
- data/lib/lsync/methods/rsync.rb +132 -0
- data/lib/lsync/run.rb +30 -29
- data/lib/lsync/script.rb +212 -125
- data/lib/lsync/server.rb +77 -92
- data/lib/lsync/shell.rb +58 -97
- data/lib/lsync/shell_client.rb +65 -61
- data/lib/lsync/shells/ssh.rb +47 -0
- data/lib/lsync/tee_logger.rb +44 -31
- data/lib/lsync/version.rb +3 -3
- metadata +25 -58
- data/bin/lsync +0 -142
- data/lib/lsync/extensions.rb +0 -22
- data/lib/lsync/lb.py +0 -1304
- data/lib/lsync/password.rb +0 -35
- data/lib/lsync/plan.rb +0 -249
data/lib/lsync/password.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'termios'
|
3
|
-
|
4
|
-
module Password
|
5
|
-
def self.echo(on=true, masked=false)
|
6
|
-
term = Termios::getattr( $stdin )
|
7
|
-
|
8
|
-
if on
|
9
|
-
term.c_lflag |= ( Termios::ECHO | Termios::ICANON )
|
10
|
-
else # off
|
11
|
-
term.c_lflag &= ~Termios::ECHO
|
12
|
-
term.c_lflag &= ~Termios::ICANON if masked
|
13
|
-
end
|
14
|
-
|
15
|
-
Termios::setattr( $stdin, Termios::TCSANOW, term )
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.get(message="Password: ")
|
19
|
-
begin
|
20
|
-
if $stdin.tty?
|
21
|
-
echo false
|
22
|
-
print message if message
|
23
|
-
end
|
24
|
-
|
25
|
-
pw = $stdin.gets
|
26
|
-
pw.chomp!
|
27
|
-
ensure
|
28
|
-
if $stdin.tty?
|
29
|
-
echo true
|
30
|
-
print "\n"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
data/lib/lsync/plan.rb
DELETED
@@ -1,249 +0,0 @@
|
|
1
|
-
|
2
|
-
# A backup plan is a rule-based engine to process individual scripts.
|
3
|
-
# Failure and success can be delt with over multiple scripts.
|
4
|
-
|
5
|
-
require 'ruleby'
|
6
|
-
|
7
|
-
module Ruleby
|
8
|
-
def self.engine(name, &block)
|
9
|
-
e = Core::Engine.new
|
10
|
-
yield e if block_given?
|
11
|
-
return e
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
module LSync
|
16
|
-
|
17
|
-
BuiltInCommands = {
|
18
|
-
"ping-host" => "ping -c 4 -t 5 -o"
|
19
|
-
}
|
20
|
-
|
21
|
-
module Facts
|
22
|
-
class Initial
|
23
|
-
end
|
24
|
-
|
25
|
-
class StageSucceeded
|
26
|
-
def initialize(stage)
|
27
|
-
@stage = stage
|
28
|
-
puts "Stage Succeeded: #{@stage.name}"
|
29
|
-
end
|
30
|
-
|
31
|
-
attr :stage
|
32
|
-
|
33
|
-
def name
|
34
|
-
@stage.name
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
class StageFailed
|
39
|
-
def initialize(stage)
|
40
|
-
@stage = stage
|
41
|
-
end
|
42
|
-
|
43
|
-
attr :stage
|
44
|
-
|
45
|
-
def name
|
46
|
-
@stage.name
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
class ScriptSucceeded
|
51
|
-
def initialize(stage, script)
|
52
|
-
@stage = stage
|
53
|
-
@script = script
|
54
|
-
end
|
55
|
-
|
56
|
-
attr :stage
|
57
|
-
attr :script
|
58
|
-
end
|
59
|
-
|
60
|
-
class ScriptFailed
|
61
|
-
def initialize(stage, script)
|
62
|
-
@stage = stage
|
63
|
-
@script = script
|
64
|
-
end
|
65
|
-
|
66
|
-
attr :stage
|
67
|
-
attr :script
|
68
|
-
end
|
69
|
-
end
|
70
|
-
|
71
|
-
class PlanRulebook < Ruleby::Rulebook
|
72
|
-
include Facts
|
73
|
-
|
74
|
-
def rules
|
75
|
-
#rule [ScriptSucceeded, :m] do |v|
|
76
|
-
# script = v[:m].script
|
77
|
-
# puts "Backup #{script.dump} successful"
|
78
|
-
#end
|
79
|
-
|
80
|
-
rule [ScriptFailed, :m] do |v|
|
81
|
-
script = v[:m].script
|
82
|
-
puts "*** Script #{script} failed"
|
83
|
-
end
|
84
|
-
|
85
|
-
#rule [StageSucceeded, :m] do |v|
|
86
|
-
# stage = v[:m].stage
|
87
|
-
# puts "Stage #{stage.name.dump} successful"
|
88
|
-
#end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class StageRulebook < Ruleby::Rulebook
|
93
|
-
include Facts
|
94
|
-
|
95
|
-
def initialize(engine, stage)
|
96
|
-
super(engine)
|
97
|
-
@stage = stage
|
98
|
-
end
|
99
|
-
|
100
|
-
def rules
|
101
|
-
# Does this stage have any rules? (i.e. can it run in any case?)
|
102
|
-
if @stage.rules.size > 0
|
103
|
-
puts "Loading rules for stage #{@stage.name.dump}..."
|
104
|
-
@stage.rules.each do |name, r|
|
105
|
-
puts "\t#{name}..."
|
106
|
-
|
107
|
-
r["when"].each do |s|
|
108
|
-
puts "\t\t#{s.dump}"
|
109
|
-
end
|
110
|
-
|
111
|
-
options = r.dup
|
112
|
-
wh = options.delete("when")
|
113
|
-
|
114
|
-
# Build rule
|
115
|
-
rule("#{@stage.name}_#{name}".to_sym, options, *wh) do |v|
|
116
|
-
@stage.run_scripts
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
# Bring names into the right scope (i.e. Facts)
|
123
|
-
def __eval__(x)
|
124
|
-
eval(x)
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
class Stage
|
129
|
-
protected
|
130
|
-
RuleConfigKeys = Set.new(["priority", "when"])
|
131
|
-
|
132
|
-
def process_rules config
|
133
|
-
rules = config.keys_matching(/^rule\.(.*)$/)
|
134
|
-
|
135
|
-
if rules.size > 0
|
136
|
-
# Okay
|
137
|
-
elsif config.key? "when"
|
138
|
-
rules = {
|
139
|
-
"rule.default" => config.delete_if { |k,v| !RuleConfigKeys.include?(k) }
|
140
|
-
}
|
141
|
-
else
|
142
|
-
return {}
|
143
|
-
end
|
144
|
-
|
145
|
-
rules.keys.each do |rule_name|
|
146
|
-
options = {}
|
147
|
-
w = rules[rule_name].delete("when") || []
|
148
|
-
w = [w] if w.is_a? String
|
149
|
-
|
150
|
-
rules[rule_name].each { |k,v| options[k.to_sym] = v }
|
151
|
-
rules[rule_name] = options
|
152
|
-
rules[rule_name]["when"] = w.collect { |s| s.gsub('@', '#') }
|
153
|
-
end
|
154
|
-
|
155
|
-
rules
|
156
|
-
end
|
157
|
-
|
158
|
-
def process_scripts config
|
159
|
-
config["scripts"].collect do |s|
|
160
|
-
s.match(/^([^\s]+)(.*)$/)
|
161
|
-
|
162
|
-
if BuiltInCommands.key? $1
|
163
|
-
BuiltInCommands[$1] + $2
|
164
|
-
else
|
165
|
-
s
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
|
170
|
-
public
|
171
|
-
def initialize(plan, name, config)
|
172
|
-
@plan = plan
|
173
|
-
@name = name
|
174
|
-
|
175
|
-
@scripts = process_scripts(config)
|
176
|
-
@rules = process_rules(config)
|
177
|
-
end
|
178
|
-
|
179
|
-
def run_scripts
|
180
|
-
failed = false
|
181
|
-
|
182
|
-
puts "Running stage #{@name}..."
|
183
|
-
@scripts.each do |script|
|
184
|
-
puts "\tRunning Script #{script}..."
|
185
|
-
|
186
|
-
if system(script)
|
187
|
-
@plan.engine.assert Facts::ScriptSucceeded.new(self, script)
|
188
|
-
else
|
189
|
-
@plan.engine.assert Facts::ScriptFailed.new(self, script)
|
190
|
-
failed = true
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
if failed
|
195
|
-
@plan.engine.assert Facts::StageFailed.new(self)
|
196
|
-
else
|
197
|
-
@plan.engine.assert Facts::StageSucceeded.new(self)
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
attr :name
|
202
|
-
attr :scripts
|
203
|
-
attr :rules
|
204
|
-
end
|
205
|
-
|
206
|
-
class Plan
|
207
|
-
def initialize(config, logger = nil)
|
208
|
-
@logger = logger || Logger.new(STDOUT)
|
209
|
-
|
210
|
-
@config = config.keys_matching(/^scripts\.(.*)$/)
|
211
|
-
@stages = config.keys_matching(/^stage\.(.*)$/) { |c,name| Stage.new(self, name, c) }
|
212
|
-
end
|
213
|
-
|
214
|
-
attr :logger, true
|
215
|
-
attr :config
|
216
|
-
|
217
|
-
def run_backup
|
218
|
-
Ruleby.engine :engine do |e|
|
219
|
-
@engine = e
|
220
|
-
|
221
|
-
puts " Loading Rules ".center(80, "=")
|
222
|
-
|
223
|
-
PlanRulebook.new(e).rules
|
224
|
-
|
225
|
-
@stages.each do |k,s|
|
226
|
-
StageRulebook.new(e, s).rules
|
227
|
-
end
|
228
|
-
|
229
|
-
puts " Processing Rules ".center(80, "=")
|
230
|
-
|
231
|
-
e.assert Facts::Initial.new
|
232
|
-
|
233
|
-
e.match
|
234
|
-
@engine = nil
|
235
|
-
end
|
236
|
-
|
237
|
-
puts " Finished ".center(80, "=")
|
238
|
-
end
|
239
|
-
|
240
|
-
attr :engine
|
241
|
-
attr :config
|
242
|
-
attr :stages
|
243
|
-
|
244
|
-
def self.load_from_file(path)
|
245
|
-
new(YAML::load(File.read(path)))
|
246
|
-
end
|
247
|
-
end
|
248
|
-
|
249
|
-
end
|