vos 0.1.3 → 0.1.4
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/Rakefile +1 -1
- data/lib/vos/box/marks.rb +15 -17
- data/lib/vos/box.rb +11 -13
- data/lib/vos/drivers/local.rb +2 -1
- data/lib/vos/drivers/specification.rb +4 -0
- data/lib/vos/drivers/ssh.rb +1 -2
- data/lib/vos/drivers/ssh_vfs_storage.rb +9 -3
- data/lib/vos/helpers/ubuntu.rb +40 -5
- data/readme.md +6 -7
- metadata +4 -18
data/Rakefile
CHANGED
data/lib/vos/box/marks.rb
CHANGED
@@ -1,30 +1,28 @@
|
|
1
1
|
module Vos
|
2
2
|
class Box
|
3
3
|
module Marks
|
4
|
-
def mark key
|
5
|
-
|
6
|
-
|
4
|
+
def mark! key
|
5
|
+
marks_dir.file(key).create
|
6
|
+
@marks_cache = nil
|
7
7
|
end
|
8
8
|
|
9
9
|
def has_mark? key
|
10
|
-
|
11
|
-
entry["#{marks_dir}/#{key}"].exist?
|
10
|
+
marks_cache.include? key.to_s
|
12
11
|
end
|
12
|
+
alias_method :marked?, :has_mark?
|
13
13
|
|
14
|
-
def clear_marks
|
15
|
-
|
14
|
+
def clear_marks!
|
15
|
+
marks_dir.destroy
|
16
|
+
@marks_cache = nil
|
16
17
|
end
|
17
|
-
|
18
|
+
|
19
|
+
def marks_dir
|
20
|
+
dir "/marks"
|
21
|
+
end
|
22
|
+
|
18
23
|
protected
|
19
|
-
def
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
def ensure_mark_requrements!
|
24
|
-
unless @ensure_mark_requrements
|
25
|
-
self.dir(marks_dir).create
|
26
|
-
@ensure_mark_requrements = true
|
27
|
-
end
|
24
|
+
def marks_cache
|
25
|
+
@marks_cache ||= marks_dir.files(bang: false).collect{|file| file.name}
|
28
26
|
end
|
29
27
|
end
|
30
28
|
end
|
data/lib/vos/box.rb
CHANGED
@@ -2,8 +2,6 @@ module Vos
|
|
2
2
|
class Box
|
3
3
|
include Shell, Marks, Vfs
|
4
4
|
|
5
|
-
attr_accessor :options
|
6
|
-
|
7
5
|
def initialize *args
|
8
6
|
first = args.first
|
9
7
|
if args.empty?
|
@@ -18,12 +16,12 @@ module Vos
|
|
18
16
|
options[:host] = first.to_s
|
19
17
|
end
|
20
18
|
|
21
|
-
@driver = options[:host] == 'localhost' ? Drivers::Local.new
|
19
|
+
@driver = options[:host] == 'localhost' ? Drivers::Local.new : Drivers::Ssh.new(options)
|
22
20
|
elsif args.size == 1
|
23
21
|
@driver = first
|
24
22
|
else
|
25
23
|
raise 'invalid arguments'
|
26
|
-
end
|
24
|
+
end
|
27
25
|
end
|
28
26
|
|
29
27
|
|
@@ -43,15 +41,15 @@ module Vos
|
|
43
41
|
#
|
44
42
|
# Micelaneous
|
45
43
|
#
|
46
|
-
def inspect
|
47
|
-
driver.to_s
|
48
|
-
# host = options[:host]
|
49
|
-
# if host == 'localhost'
|
50
|
-
# ''
|
51
|
-
# else
|
52
|
-
# host
|
53
|
-
# end
|
54
|
-
end
|
44
|
+
def inspect; driver.to_s end
|
55
45
|
alias_method :to_s, :inspect
|
46
|
+
|
47
|
+
def host; driver.host end
|
48
|
+
|
49
|
+
def local?; host == 'localhost' end
|
50
|
+
|
51
|
+
class << self
|
52
|
+
def local; @local ||= Box.new end
|
53
|
+
end
|
56
54
|
end
|
57
55
|
end
|
data/lib/vos/drivers/local.rb
CHANGED
data/lib/vos/drivers/ssh.rb
CHANGED
@@ -77,7 +77,6 @@ module Vos
|
|
77
77
|
def bash command
|
78
78
|
# somehow net-ssh doesn't executes ~/.profile, so we need to execute it manually
|
79
79
|
# command = ". ~/.profile && #{command}"
|
80
|
-
|
81
80
|
stdout_and_stderr, stderr, code, signal = hacked_exec! ssh, command, true
|
82
81
|
|
83
82
|
return code, stdout_and_stderr
|
@@ -88,6 +87,7 @@ module Vos
|
|
88
87
|
# Micelaneous
|
89
88
|
#
|
90
89
|
def to_s; options[:host] end
|
90
|
+
def host; options[:host] end
|
91
91
|
|
92
92
|
protected
|
93
93
|
attr_accessor :ssh, :sftp
|
@@ -128,7 +128,6 @@ module Vos
|
|
128
128
|
end
|
129
129
|
|
130
130
|
channel.wait
|
131
|
-
|
132
131
|
[stdout_data, stderr_data, exit_code, exit_signal]
|
133
132
|
end
|
134
133
|
end
|
@@ -11,6 +11,10 @@ module Vos
|
|
11
11
|
attrs[:file] = stat.file?
|
12
12
|
attrs[:dir] = stat.directory?
|
13
13
|
# stat.symlink?
|
14
|
+
|
15
|
+
# attributes special for file system
|
16
|
+
attrs[:updated_at] = stat.mtime
|
17
|
+
|
14
18
|
attrs
|
15
19
|
rescue Net::SFTP::StatusException
|
16
20
|
{}
|
@@ -79,7 +83,7 @@ module Vos
|
|
79
83
|
exec "rm -r #{path}"
|
80
84
|
end
|
81
85
|
|
82
|
-
def
|
86
|
+
def each_entry path, &block
|
83
87
|
sftp.dir.foreach path do |stat|
|
84
88
|
next if stat.name == '.' or stat.name == '..'
|
85
89
|
if stat.directory?
|
@@ -90,14 +94,16 @@ module Vos
|
|
90
94
|
end
|
91
95
|
end
|
92
96
|
|
93
|
-
def efficient_dir_copy from, to
|
97
|
+
def efficient_dir_copy from, to, override
|
98
|
+
return false if override # sftp doesn't support this behaviour
|
99
|
+
|
94
100
|
from.storage.open_fs do |from_fs|
|
95
101
|
to.storage.open_fs do |to_fs|
|
96
102
|
if from_fs.local?
|
97
103
|
sftp.upload! from.path, fix_path(to.path)
|
98
104
|
true
|
99
105
|
elsif to_fs.local?
|
100
|
-
sftp.download! fix_path(
|
106
|
+
sftp.download! fix_path(from.path), to.path, :recursive => true
|
101
107
|
true
|
102
108
|
else
|
103
109
|
false
|
data/lib/vos/helpers/ubuntu.rb
CHANGED
@@ -5,7 +5,7 @@ module Vos
|
|
5
5
|
{:DEBIAN_FRONTEND => 'noninteractive'}
|
6
6
|
end
|
7
7
|
def wrap_cmd env_str, cmd
|
8
|
-
%(
|
8
|
+
%(source #{env_file.path} && #{env_str}#{' && ' unless env_str.empty?}#{cmd})
|
9
9
|
end
|
10
10
|
|
11
11
|
def env_file
|
@@ -34,14 +34,49 @@ module Vos
|
|
34
34
|
end
|
35
35
|
|
36
36
|
module Vfs
|
37
|
+
class Entry
|
38
|
+
def symlink_to entry, options = {}
|
39
|
+
raise "invalid argument!" unless entry.is_a? Entry
|
40
|
+
raise "can't use symlink ('#{self}' and '#{entry}' are on different storages)!" if self.storage != entry.storage
|
41
|
+
raise "symlink target '' not exist!" unless entry.exist?
|
42
|
+
storage.bash "ln -s#{'f' if options[:override]} #{entry.path} #{path}"
|
43
|
+
end
|
44
|
+
|
45
|
+
def symlink_to! entry
|
46
|
+
symlink_to entry, override: true
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
class Dir
|
51
|
+
def rsync_to entry
|
52
|
+
raise "invalid argument!" unless entry.is_a? Entry
|
53
|
+
raise "#{path} must be a Dir" unless dir?
|
54
|
+
raise "#{entry.path} can't be a File!" if entry.file?
|
55
|
+
|
56
|
+
if local? and !entry.local?
|
57
|
+
Box.local.bash("rsync -e 'ssh' -al --delete --stats --progress #{path}/ root@#{entry.storage.host}:#{entry.path}")
|
58
|
+
elsif entry.local? and !local?
|
59
|
+
Box.local.bash("rsync -e 'ssh' -al --delete --stats --progress root@#{storage.host}:#{path}/ #{entry.path}")
|
60
|
+
else
|
61
|
+
raise "invalid usage!"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
37
66
|
class File
|
38
67
|
def append_to_environment_of box, reload = true
|
39
|
-
raise "#{box} must be an Vos::Box" unless
|
68
|
+
raise "#{box} must be an Vos::Box" unless box.is_a? Vos::Box
|
40
69
|
|
41
|
-
|
70
|
+
remote_file = box.dir('/etc/profile_ext').file(name)
|
71
|
+
copy_to! remote_file
|
72
|
+
|
73
|
+
require_clause = <<-BASH
|
42
74
|
|
43
|
-
|
44
|
-
|
75
|
+
# #{name}
|
76
|
+
source #{remote_file.path}
|
77
|
+
BASH
|
78
|
+
|
79
|
+
box.env_file.append require_clause unless box.env_file.content.include? require_clause
|
45
80
|
|
46
81
|
box.reload_env if reload
|
47
82
|
end
|
data/readme.md
CHANGED
@@ -13,16 +13,15 @@ Currently, there are following implementations available:
|
|
13
13
|
$ gem install vos
|
14
14
|
|
15
15
|
## Code samples:
|
16
|
-
gem 'vos'
|
16
|
+
gem 'vos' # Virtual Operating System
|
17
17
|
require 'vos'
|
18
18
|
|
19
|
-
|
20
|
-
server = Vfs::Box.new(host: 'cool_app.com', ssh: {user: 'me', password: 'secret'})
|
19
|
+
server = Box.new('cool_app.com') # it will use id_rsa, or You can add {user: 'me', password: 'secret'}
|
21
20
|
|
22
|
-
server.bash 'ls'
|
23
|
-
server['apps/cool_app'].bash 'rails production'
|
21
|
+
server.bash 'ls' # ls /
|
22
|
+
server['apps/cool_app'].bash 'rails production' # cd /apps/cool_app && rails production
|
24
23
|
|
25
|
-
For more details look also to [Virtual File System][
|
24
|
+
For more details look also to [Virtual File System][vfs] project.
|
26
25
|
Or checkout configuration I use to control my production servers [My Cluster][my_cluster] in conjunction with small
|
27
26
|
configuration tool [Cluster Management][cluster_management].
|
28
27
|
|
@@ -39,6 +38,6 @@ configuration tool [Cluster Management][cluster_management].
|
|
39
38
|
- process management (find/kill/filters/attributes)
|
40
39
|
- other os resources management (disk)
|
41
40
|
|
42
|
-
[
|
41
|
+
[vfs]: http://github.com/alexeypetrushin/vfs
|
43
42
|
[cluster_management]: http://github.com/alexeypetrushin/cluster_management
|
44
43
|
[my_cluster]: http://github.com/alexeypetrushin/my_cluster
|
metadata
CHANGED
@@ -1,12 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
prerelease:
|
5
|
-
|
6
|
-
- 0
|
7
|
-
- 1
|
8
|
-
- 3
|
9
|
-
version: 0.1.3
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.4
|
10
6
|
platform: ruby
|
11
7
|
authors:
|
12
8
|
- Alexey Petrushin
|
@@ -14,7 +10,7 @@ autorequire:
|
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
12
|
|
17
|
-
date: 2011-02-
|
13
|
+
date: 2011-02-16 00:00:00 +03:00
|
18
14
|
default_executable:
|
19
15
|
dependencies:
|
20
16
|
- !ruby/object:Gem::Dependency
|
@@ -25,8 +21,6 @@ dependencies:
|
|
25
21
|
requirements:
|
26
22
|
- - ">="
|
27
23
|
- !ruby/object:Gem::Version
|
28
|
-
segments:
|
29
|
-
- 0
|
30
24
|
version: "0"
|
31
25
|
type: :runtime
|
32
26
|
version_requirements: *id001
|
@@ -38,8 +32,6 @@ dependencies:
|
|
38
32
|
requirements:
|
39
33
|
- - ">="
|
40
34
|
- !ruby/object:Gem::Version
|
41
|
-
segments:
|
42
|
-
- 0
|
43
35
|
version: "0"
|
44
36
|
type: :runtime
|
45
37
|
version_requirements: *id002
|
@@ -51,8 +43,6 @@ dependencies:
|
|
51
43
|
requirements:
|
52
44
|
- - ">="
|
53
45
|
- !ruby/object:Gem::Version
|
54
|
-
segments:
|
55
|
-
- 0
|
56
46
|
version: "0"
|
57
47
|
type: :runtime
|
58
48
|
version_requirements: *id003
|
@@ -102,21 +92,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
102
92
|
requirements:
|
103
93
|
- - ">="
|
104
94
|
- !ruby/object:Gem::Version
|
105
|
-
segments:
|
106
|
-
- 0
|
107
95
|
version: "0"
|
108
96
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
109
97
|
none: false
|
110
98
|
requirements:
|
111
99
|
- - ">="
|
112
100
|
- !ruby/object:Gem::Version
|
113
|
-
segments:
|
114
|
-
- 0
|
115
101
|
version: "0"
|
116
102
|
requirements: []
|
117
103
|
|
118
104
|
rubyforge_project:
|
119
|
-
rubygems_version: 1.
|
105
|
+
rubygems_version: 1.5.1
|
120
106
|
signing_key:
|
121
107
|
specification_version: 3
|
122
108
|
summary: Virtual Operating System
|