lsync 2.1.0 → 2.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/lsync-mount +88 -0
- data/{lib/lsync/actions/generic/prune → bin/lsync-prune} +20 -0
- data/{lib/lsync/actions/generic/rotate → bin/lsync-rotate} +27 -3
- data/lib/lsync.rb +17 -12
- data/lib/lsync/client.rb +56 -0
- data/lib/lsync/controller.rb +117 -9
- data/lib/lsync/directory.rb +28 -1
- data/lib/lsync/error.rb +19 -0
- data/lib/lsync/event_handler.rb +28 -1
- data/lib/lsync/event_timer.rb +19 -0
- data/lib/lsync/method.rb +21 -5
- data/lib/lsync/methods/rsync.rb +56 -36
- data/lib/lsync/run.rb +59 -23
- data/lib/lsync/script.rb +52 -23
- data/lib/lsync/server.rb +39 -20
- data/lib/lsync/shell.rb +27 -28
- data/lib/lsync/shells/ssh.rb +19 -0
- data/lib/lsync/tee_logger.rb +19 -0
- data/lib/lsync/version.rb +20 -15
- metadata +27 -22
- data/lib/lsync/action.rb +0 -105
- data/lib/lsync/actions/darwin/disk +0 -19
- data/lib/lsync/actions/darwin/terminal +0 -8
- data/lib/lsync/actions/linux/disk +0 -28
- data/lib/lsync/actions/linux/terminal +0 -8
- data/lib/lsync/shell_client.rb +0 -88
@@ -1,19 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
DISKUTIL = "diskutil"
|
4
|
-
action = ARGV[0]
|
5
|
-
disk_name = ARGV[1]
|
6
|
-
|
7
|
-
def get_disk_id(name)
|
8
|
-
begin
|
9
|
-
`diskutil list`.match(/#{name}\s*\*?[0-9]+\.[0-9]+ .B\s+(disk[0-9]s[0-9])$/)[1]
|
10
|
-
rescue
|
11
|
-
exit 5
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
if (action == 'mountpoint')
|
16
|
-
puts File.join('', 'Volumes', disk_name, ARGV[2..-1])
|
17
|
-
else
|
18
|
-
system DISKUTIL, action, get_disk_id(disk_name)
|
19
|
-
end
|
@@ -1,28 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
Commands = {
|
4
|
-
"mount" => "mount",
|
5
|
-
"unmount" => "umount"
|
6
|
-
}
|
7
|
-
|
8
|
-
DevicePaths = [
|
9
|
-
"/dev/disk/by-label",
|
10
|
-
"/dev/disk/by-uuid",
|
11
|
-
"/dev"
|
12
|
-
]
|
13
|
-
|
14
|
-
action = ARGV[0]
|
15
|
-
disk_name = ARGV[1]
|
16
|
-
|
17
|
-
mountpoint = File.join('', 'mnt', disk_name)
|
18
|
-
|
19
|
-
if (action == 'mountpoint')
|
20
|
-
puts File.join(mountpoint, ARGV[2..-1])
|
21
|
-
else
|
22
|
-
puts "#{action.capitalize}ing #{mountpoint}..."
|
23
|
-
system Commands[action], mountpoint
|
24
|
-
|
25
|
-
if $?.exitstatus != 0 or $?.exitstatus != 3383
|
26
|
-
exit 5
|
27
|
-
end
|
28
|
-
end
|
data/lib/lsync/shell_client.rb
DELETED
@@ -1,88 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'logger'
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
require "open3"
|
6
|
-
|
7
|
-
LSYNC_TMP_DIRECTORY = "/tmp/lsync-#{Process.pid}"
|
8
|
-
FileUtils.mkdir_p(LSYNC_TMP_DIRECTORY)
|
9
|
-
FileUtils.chmod 0700, LSYNC_TMP_DIRECTORY
|
10
|
-
$logger = Logger.new "/tmp/remote-client.log"
|
11
|
-
|
12
|
-
$logger.info "Starting remote shell @ #{Time.now.to_s}"
|
13
|
-
|
14
|
-
def script_path(named)
|
15
|
-
File.join(LSYNC_TMP_DIRECTORY, "#{named}")
|
16
|
-
end
|
17
|
-
|
18
|
-
module RemoteMethods
|
19
|
-
# Run a command in the local environment.
|
20
|
-
def self.run_command(cmd)
|
21
|
-
$logger.info("Running #{cmd.inspect}...")
|
22
|
-
$connection.send_object([:info, "Running #{cmd.inspect}..."])
|
23
|
-
|
24
|
-
cin, cout, cerr = Open3.popen3(*cmd)
|
25
|
-
cin.close
|
26
|
-
|
27
|
-
pipes = [cout, cerr]
|
28
|
-
|
29
|
-
while pipes.size > 0
|
30
|
-
ready = IO.select(pipes)
|
31
|
-
|
32
|
-
ready[0].each do |pipe|
|
33
|
-
# Delete the pipe when it has become closed
|
34
|
-
if pipe.closed? || pipe.eof?
|
35
|
-
pipes.delete(pipe)
|
36
|
-
next
|
37
|
-
end
|
38
|
-
|
39
|
-
line = pipe.readline.chomp
|
40
|
-
mode = (pipe == cout ? :info : :error)
|
41
|
-
|
42
|
-
$logger.send(mode, line)
|
43
|
-
$connection.send_object([mode, line])
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
$logger.info "Done running command."
|
48
|
-
$connection.send_object(:done)
|
49
|
-
end
|
50
|
-
|
51
|
-
# Run a script (given the code) in the local environment.
|
52
|
-
def self.run_script(name, code, arguments)
|
53
|
-
path = script_path(name)
|
54
|
-
|
55
|
-
File.open(path, "w") do |f|
|
56
|
-
f.write(code)
|
57
|
-
end
|
58
|
-
|
59
|
-
FileUtils.chmod 0755, path
|
60
|
-
|
61
|
-
run_command([path] + arguments)
|
62
|
-
end
|
63
|
-
|
64
|
-
# Recursively make a directory (typically the server.root + directory)
|
65
|
-
def self.mkdir_p(path)
|
66
|
-
FileUtils.mkdir_p(path)
|
67
|
-
end
|
68
|
-
|
69
|
-
# Set the working directory (typically the server.root)
|
70
|
-
def self.set_working_dir(path)
|
71
|
-
Dir.chdir(path)
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
begin
|
76
|
-
$connection.send_object(:ready)
|
77
|
-
|
78
|
-
$connection.run do |message|
|
79
|
-
method = message.shift
|
80
|
-
$logger.info("Calling #{method}...")
|
81
|
-
result = RemoteMethods.send(method, *message)
|
82
|
-
end
|
83
|
-
rescue
|
84
|
-
$logger.error("Exception caught: #{$!}")
|
85
|
-
exit(1)
|
86
|
-
ensure
|
87
|
-
FileUtils.rm_rf(LSYNC_TMP_DIRECTORY)
|
88
|
-
end
|