lsync 2.1.0 → 2.3.1
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/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
data/lib/lsync/server.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
# Copyright (c) 2007, 2011 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
1
20
|
|
2
21
|
require 'lsync/event_handler'
|
3
22
|
require 'lsync/shells/ssh'
|
@@ -6,19 +25,24 @@ module LSync
|
|
6
25
|
class Server
|
7
26
|
include EventHandler
|
8
27
|
|
9
|
-
def initialize(host)
|
28
|
+
def initialize(host, options = {})
|
29
|
+
@options = options
|
30
|
+
|
10
31
|
@host = host
|
11
32
|
@root = "/"
|
12
|
-
|
13
|
-
@platform =
|
14
|
-
|
33
|
+
|
34
|
+
@platform = nil
|
35
|
+
|
15
36
|
@shell = Shells::SSH.new
|
16
|
-
|
37
|
+
|
17
38
|
@enabled = true
|
18
|
-
|
19
|
-
@
|
39
|
+
|
40
|
+
@roles = Set.new
|
20
41
|
end
|
21
42
|
|
43
|
+
# The roles that dictate how the server fits into the overall infratstructure.
|
44
|
+
attr :roles, true
|
45
|
+
|
22
46
|
# The host name (e.g. DNS entry) for the given server
|
23
47
|
attr :host, true
|
24
48
|
|
@@ -35,20 +59,24 @@ module LSync
|
|
35
59
|
def full_path(directory = "./")
|
36
60
|
p = File.expand_path(directory.to_s, @root)
|
37
61
|
|
38
|
-
return Pathname.new(p).cleanpath.normalize_trailing_slash
|
62
|
+
return Pathname.new(p).cleanpath.normalize_trailing_slash
|
39
63
|
end
|
40
64
|
|
41
65
|
# Give a general connection string (e.g +"host:/directory"+ or +"/directory"+ if local).
|
42
66
|
def connection_string(directory)
|
43
|
-
if
|
67
|
+
if local?
|
44
68
|
return full_path(directory)
|
45
69
|
else
|
46
|
-
return @host + ":" + full_path(directory).
|
70
|
+
return @host + ":" + full_path(directory).to_cmd
|
47
71
|
end
|
48
72
|
end
|
49
73
|
|
74
|
+
def role?(role)
|
75
|
+
@roles.include?(role) || @roles.include?(:all) || role == :any
|
76
|
+
end
|
77
|
+
|
50
78
|
# Checks if the host resolves to the local machine.
|
51
|
-
def
|
79
|
+
def local?
|
52
80
|
return true if @host == "localhost"
|
53
81
|
|
54
82
|
hostname = Socket.gethostname
|
@@ -66,14 +94,5 @@ module LSync
|
|
66
94
|
def to_s
|
67
95
|
"#{@host}:#{full_path}"
|
68
96
|
end
|
69
|
-
|
70
|
-
# Connect to the server using the given #shell and #connection_string.
|
71
|
-
def connect
|
72
|
-
unless @connection
|
73
|
-
@connection, @pid = @shell.connect(self)
|
74
|
-
end
|
75
|
-
|
76
|
-
return @connection
|
77
|
-
end
|
78
97
|
end
|
79
98
|
end
|
data/lib/lsync/shell.rb
CHANGED
@@ -1,10 +1,30 @@
|
|
1
|
+
# Copyright (c) 2007, 2011 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
1
20
|
|
2
21
|
require 'rexec'
|
3
22
|
require 'pathname'
|
4
23
|
|
5
24
|
module LSync
|
6
|
-
|
7
|
-
|
25
|
+
|
26
|
+
CLIENT_CODE = (Pathname.new(__FILE__).dirname + "client.rb").read
|
27
|
+
|
8
28
|
# There was an error establishing a connection with a server.
|
9
29
|
class ConnectionError < StandardError
|
10
30
|
end
|
@@ -22,7 +42,6 @@ module LSync
|
|
22
42
|
@options = options
|
23
43
|
end
|
24
44
|
|
25
|
-
# The command required to start an instance of Ruby.
|
26
45
|
def ruby_command
|
27
46
|
@options[:ruby] || ["ruby"]
|
28
47
|
end
|
@@ -32,33 +51,13 @@ module LSync
|
|
32
51
|
@command + (@options[:arguments] || []) + arguments + [server.host]
|
33
52
|
end
|
34
53
|
|
35
|
-
# Establish a connection to the server using this shell configuration.
|
36
54
|
def connect(server)
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
if message != :ready
|
45
|
-
raise ConnectionError.new("Remote shell connection was not successful: #{message}")
|
46
|
-
end
|
47
|
-
|
48
|
-
return connection, pid
|
49
|
-
end
|
50
|
-
|
51
|
-
protected
|
52
|
-
# Return a connection object representing a connection to the given server.
|
53
|
-
def open_connection(server)
|
54
|
-
command = ruby_command
|
55
|
-
|
56
|
-
unless server.is_local?
|
57
|
-
command = connection_command(server) + command
|
55
|
+
options = {:passthrough => []}
|
56
|
+
if server.local?
|
57
|
+
return RExec::start_server(CLIENT_CODE, ruby_command, options)
|
58
|
+
else
|
59
|
+
return RExec::start_server(CLIENT_CODE, connection_command(server) + ruby_command, options)
|
58
60
|
end
|
59
|
-
|
60
|
-
return RExec::start_server(CLIENT_CODE, command)
|
61
61
|
end
|
62
62
|
end
|
63
|
-
|
64
63
|
end
|
data/lib/lsync/shells/ssh.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
# Copyright (c) 2007, 2011 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
1
20
|
|
2
21
|
require 'lsync/shell'
|
3
22
|
|
data/lib/lsync/tee_logger.rb
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
# Copyright (c) 2007, 2011 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
1
20
|
|
2
21
|
module LSync
|
3
22
|
# A helper to provide easy access to the TeeLogger functionality.
|
data/lib/lsync/version.rb
CHANGED
@@ -1,23 +1,28 @@
|
|
1
|
-
# Copyright (c) 2007 Samuel
|
2
|
-
#
|
3
|
-
# This program is free software: you can redistribute it and/or modify
|
4
|
-
# it under the terms of the GNU General Public License as published by
|
5
|
-
# the Free Software Foundation, either version 3 of the License, or
|
6
|
-
# (at your option) any later version.
|
1
|
+
# Copyright (c) 2007, 2011 Samuel G. D. Williams. <http://www.oriontransfer.co.nz>
|
7
2
|
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
#
|
11
|
-
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
12
9
|
#
|
13
|
-
#
|
14
|
-
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
15
20
|
|
16
21
|
module LSync
|
17
|
-
module VERSION
|
22
|
+
module VERSION
|
18
23
|
MAJOR = 2
|
19
|
-
MINOR =
|
20
|
-
TINY =
|
24
|
+
MINOR = 3
|
25
|
+
TINY = 1
|
21
26
|
|
22
27
|
STRING = [MAJOR, MINOR, TINY].join('.')
|
23
28
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lsync
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 1
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 2
|
8
|
+
- 3
|
7
9
|
- 1
|
8
|
-
|
9
|
-
version: 2.1.0
|
10
|
+
version: 2.3.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Samuel Williams
|
@@ -14,53 +15,55 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-
|
18
|
-
default_executable:
|
18
|
+
date: 2011-08-08 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: fingerprint
|
22
22
|
prerelease: false
|
23
23
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
24
25
|
requirements:
|
25
26
|
- - ">="
|
26
27
|
- !ruby/object:Gem::Version
|
28
|
+
hash: 25
|
27
29
|
segments:
|
28
30
|
- 1
|
29
|
-
-
|
31
|
+
- 2
|
30
32
|
- 3
|
31
|
-
version: 1.
|
33
|
+
version: 1.2.3
|
32
34
|
type: :runtime
|
33
35
|
version_requirements: *id001
|
34
36
|
- !ruby/object:Gem::Dependency
|
35
37
|
name: rexec
|
36
38
|
prerelease: false
|
37
39
|
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
38
41
|
requirements:
|
39
42
|
- - ">="
|
40
43
|
- !ruby/object:Gem::Version
|
44
|
+
hash: 7
|
41
45
|
segments:
|
42
46
|
- 1
|
43
|
-
-
|
44
|
-
-
|
45
|
-
version: 1.
|
47
|
+
- 4
|
48
|
+
- 0
|
49
|
+
version: 1.4.0
|
46
50
|
type: :runtime
|
47
51
|
version_requirements: *id002
|
48
52
|
description:
|
49
53
|
email: samuel.williams@oriontransfer.co.nz
|
50
|
-
executables:
|
51
|
-
|
54
|
+
executables:
|
55
|
+
- lsync-mount
|
56
|
+
- lsync-prune
|
57
|
+
- lsync-rotate
|
52
58
|
extensions: []
|
53
59
|
|
54
60
|
extra_rdoc_files: []
|
55
61
|
|
56
62
|
files:
|
57
|
-
-
|
58
|
-
-
|
59
|
-
-
|
60
|
-
- lib/lsync/
|
61
|
-
- lib/lsync/actions/generic/rotate
|
62
|
-
- lib/lsync/actions/linux/disk
|
63
|
-
- lib/lsync/actions/linux/terminal
|
63
|
+
- bin/lsync-mount
|
64
|
+
- bin/lsync-prune
|
65
|
+
- bin/lsync-rotate
|
66
|
+
- lib/lsync/client.rb
|
64
67
|
- lib/lsync/controller.rb
|
65
68
|
- lib/lsync/directory.rb
|
66
69
|
- lib/lsync/error.rb
|
@@ -72,13 +75,11 @@ files:
|
|
72
75
|
- lib/lsync/script.rb
|
73
76
|
- lib/lsync/server.rb
|
74
77
|
- lib/lsync/shell.rb
|
75
|
-
- lib/lsync/shell_client.rb
|
76
78
|
- lib/lsync/shells/ssh.rb
|
77
79
|
- lib/lsync/tee_logger.rb
|
78
80
|
- lib/lsync/version.rb
|
79
81
|
- lib/lsync.rb
|
80
82
|
- README.md
|
81
|
-
has_rdoc: yard
|
82
83
|
homepage: http://www.oriontransfer.co.nz/gems/lsync
|
83
84
|
licenses: []
|
84
85
|
|
@@ -88,23 +89,27 @@ rdoc_options: []
|
|
88
89
|
require_paths:
|
89
90
|
- lib
|
90
91
|
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
91
93
|
requirements:
|
92
94
|
- - ">="
|
93
95
|
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
94
97
|
segments:
|
95
98
|
- 0
|
96
99
|
version: "0"
|
97
100
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
101
|
+
none: false
|
98
102
|
requirements:
|
99
103
|
- - ">="
|
100
104
|
- !ruby/object:Gem::Version
|
105
|
+
hash: 3
|
101
106
|
segments:
|
102
107
|
- 0
|
103
108
|
version: "0"
|
104
109
|
requirements: []
|
105
110
|
|
106
111
|
rubyforge_project:
|
107
|
-
rubygems_version: 1.
|
112
|
+
rubygems_version: 1.8.7
|
108
113
|
signing_key:
|
109
114
|
specification_version: 3
|
110
115
|
summary: LSync is a tool for scripted synchronization and backups.
|
data/lib/lsync/action.rb
DELETED
@@ -1,105 +0,0 @@
|
|
1
|
-
|
2
|
-
require 'pathname'
|
3
|
-
require 'lsync/run'
|
4
|
-
require 'lsync/error'
|
5
|
-
|
6
|
-
module LSync
|
7
|
-
|
8
|
-
class AbortBackupException < StandardError
|
9
|
-
end
|
10
|
-
|
11
|
-
# A runnable action, such as a shell command or action script.
|
12
|
-
#
|
13
|
-
# If the first argument is a symbol, then this will map to one of the standard
|
14
|
-
# actions in the `lsync/actions` subdirectory. These actions are sometimes implemented
|
15
|
-
# on a per-platform basis.
|
16
|
-
class Action
|
17
|
-
def initialize(function)
|
18
|
-
@function = function
|
19
|
-
|
20
|
-
case @function[0]
|
21
|
-
when Symbol
|
22
|
-
@script_name = @function[0].to_s
|
23
|
-
@arguments = @function[1,@function.size]
|
24
|
-
else
|
25
|
-
@script_name = nil
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# Return a string representation of the action for logging.
|
30
|
-
def to_s
|
31
|
-
@function.to_cmd
|
32
|
-
end
|
33
|
-
|
34
|
-
# Run the action on the given server, typically in the root directory specified.
|
35
|
-
def run_on_server(server, logger)
|
36
|
-
# logger.info "Running #{@function.to_cmd} on #{server}"
|
37
|
-
|
38
|
-
if server.is_local?
|
39
|
-
run_locally(server, logger)
|
40
|
-
else
|
41
|
-
run_remotely(server, logger)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
private
|
46
|
-
# Run the script locally by invoking it directly.
|
47
|
-
def run_locally(server, logger)
|
48
|
-
command = nil
|
49
|
-
|
50
|
-
if @script_name
|
51
|
-
uname = `uname`.chomp.downcase
|
52
|
-
|
53
|
-
local_path = Action.script_path(uname, @script_name)
|
54
|
-
command = [local_path] + @arguments
|
55
|
-
else
|
56
|
-
command = @function
|
57
|
-
end
|
58
|
-
|
59
|
-
result = nil
|
60
|
-
Dir.chdir(server.root) do
|
61
|
-
result = LSync.run_command(command, logger)
|
62
|
-
end
|
63
|
-
|
64
|
-
if result != 0
|
65
|
-
raise ShellScriptError.new(command, result)
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
# Run the script remotely by sending the data across the network and executing it.
|
70
|
-
def run_remotely(server, logger)
|
71
|
-
conn = server.connect
|
72
|
-
conn.send_object([:set_working_dir, server.root])
|
73
|
-
|
74
|
-
if @script_name
|
75
|
-
uname = `uname`.chomp.downcase
|
76
|
-
|
77
|
-
local_path = Action.script_path(uname, @script_name)
|
78
|
-
|
79
|
-
logger.info("Sending run_script #{@script_name}...")
|
80
|
-
conn.send_object([:run_script, @script_name, Pathname.new(local_path).read, @arguments])
|
81
|
-
else
|
82
|
-
logger.info("Sending run_command #{@function}...")
|
83
|
-
conn.send_object([:run_command, @function])
|
84
|
-
end
|
85
|
-
|
86
|
-
conn.run do |message|
|
87
|
-
break if message == :done
|
88
|
-
|
89
|
-
logger.send(*message)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# Figure out the path of the script, which may depend on the given platform.
|
94
|
-
def self.script_path(platform, name)
|
95
|
-
exact_script_path(platform, name) || exact_script_path("generic", name)
|
96
|
-
end
|
97
|
-
|
98
|
-
# Return the exact path of a builtin action script.
|
99
|
-
def self.exact_script_path(platform, name)
|
100
|
-
path = (Pathname.new(__FILE__).dirname + "actions" + platform + name).expand_path
|
101
|
-
path.exist? ? path : nil
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
end
|