ro_rmt 0.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.
- checksums.yaml +7 -0
- data/README.md +91 -0
- data/conf/ro_rmt.rb +203 -0
- data/conf/rsync/exclude_patterns +4 -0
- data/conf/rsync/include_patterns +10 -0
- data/lib/ro_cell/rmt.rb +254 -0
- data/lib/ro_cell/rmt/dir.rb +55 -0
- data/lib/ro_cell/rmt/file.rb +96 -0
- data/lib/ro_cell/rmt/opts.rb +21 -0
- data/lib/ro_cell/rmt/se_mgr.rb +51 -0
- data/lib/ro_cell/tmp/ro.log +49 -0
- data/lib/ro_cmd/ci.rb +32 -0
- data/lib/ro_cmd/rmt_base.rb +132 -0
- data/lib/ro_cmd/rmt_rspec.rb +26 -0
- data/lib/ro_helper/dp.rb +20 -0
- data/lib/ro_helper/rmt/basic.rb +441 -0
- data/lib/ro_helper/rmt/compress.rb +31 -0
- data/lib/ro_helper/rmt/determinations.rb +25 -0
- data/lib/ro_helper/rmt/dir.rb +11 -0
- data/lib/ro_helper/rmt/file.rb +13 -0
- data/lib/ro_helper/rmt/file_dir.rb +60 -0
- data/lib/ro_helper/rmt/process.rb +46 -0
- data/lib/ro_helper/rmt/rb.rb +131 -0
- data/lib/ro_helper/rmt/scp.rb +117 -0
- data/lib/ro_helper/rmt/se_attrs.rb +28 -0
- data/lib/ro_rmt.rb +9 -0
- data/lib/ro_rmt_ro_cmds_bin.rb +4 -0
- data/lib/ro_rspec_helper/rmt_rspec_helper.rb +82 -0
- data/lib/ro_script/kill_port.rb +49 -0
- data/lib/ro_script/pgrep.rb +44 -0
- data/lib/ro_script/pkill.rb +51 -0
- data/lib/ro_script/try.rb +0 -0
- data/lib/tts/nginx.conf.erb +148 -0
- data/spec/fixtures/ro_bin_helper/Gemfile +2 -0
- data/spec/fixtures/ro_bin_helper/gem1/lib/ro_cmd/cmd1.rb +0 -0
- data/spec/fixtures/ro_bin_helper/gem1/lib/ro_cmd/cmd2.rb +0 -0
- data/spec/fixtures/ro_bin_helper/gem2/lib/ro_cmd/cmd1.rb +0 -0
- data/spec/fixtures/ro_bin_helper/gem2/lib/ro_cmd/cmd2.rb +0 -0
- data/spec/fixtures/scp/log/scp_rspec_err.log +216 -0
- data/spec/fixtures/scp/tmp/ro.log +110 -0
- data/spec/fixtures/scp/tmp/ro_cell__pl__sv__st_event.log +7 -0
- data/spec/fixtures/scp/tmp/roroco/at/localhost/home/roroco/try/try_ro_rmt.rb +1 -0
- data/spec/fixtures/se_mgr/log/se_mgr_rspec_err.log +207 -0
- data/spec/fixtures/se_mgr/tmp/ro.log +1194 -0
- data/spec/fixtures/se_mgr/tmp/ro_cell__pl__sv__st_event.log +7 -0
- data/spec/helpers/articles_helper_spec.rb +15 -0
- data/spec/lib/ro_cell/rmt/dir_spec.rb +22 -0
- data/spec/lib/ro_cell/rmt/file_spec.rb +32 -0
- data/spec/lib/ro_cell/rmt/se_mgr_spec.rb +33 -0
- data/spec/lib/ro_cell/rmt_spec.rb +113 -0
- data/spec/lib/ro_dp/cap_spec.rb +34 -0
- data/spec/lib/ro_dp/rbenv_spec.rb +10 -0
- data/spec/lib/ro_dp/system_spec.rb +31 -0
- data/spec/lib/ro_helper/rmt/basic_spec.rb +41 -0
- data/spec/lib/ro_helper/rmt/cf_spec.rb +17 -0
- data/spec/lib/ro_helper/rmt/determinations_spec.rb +11 -0
- data/spec/lib/ro_helper/rmt/dir_spec.rb +15 -0
- data/spec/lib/ro_helper/rmt/file_dir_helper_spec.rb +11 -0
- data/spec/lib/ro_helper/rmt/file_spec.rb +23 -0
- data/spec/lib/ro_helper/rmt/process_spec.rb +29 -0
- data/spec/lib/ro_helper/rmt/rb_spec.rb +13 -0
- data/spec/lib/ro_helper/rmt/scp_spec.rb +21 -0
- data/spec/lib/ro_script/pgrep_spec.rb +18 -0
- data/spec/lib/ro_sv_try/1.rb +0 -0
- data/spec/lib/ro_sv_try/2.rb +0 -0
- data/spec/lib/ro_sv_try/3.rb +0 -0
- data/spec/lib/ro_sv_try/tmp/rspec_guard_result +9 -0
- data/spec/rails_helper.rb +1 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/wio_spork.rb +10 -0
- metadata +177 -0
@@ -0,0 +1,31 @@
|
|
1
|
+
module RoHelper
|
2
|
+
module Rmt
|
3
|
+
module Compress
|
4
|
+
def uncompress(compressed_file, out_dir, *args, &blk)
|
5
|
+
if zip?(compressed_file)
|
6
|
+
unzip(compressed_file, out_dir)
|
7
|
+
end
|
8
|
+
|
9
|
+
if tar?(compressed_file)
|
10
|
+
tar_xf(compressed_file, out_dir)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def zip?(file, *args, &blk)
|
15
|
+
file.match(%r{\.zip$})
|
16
|
+
end
|
17
|
+
|
18
|
+
def tar?(file, *args, &blk)
|
19
|
+
file.match(%r{\.tar\.gz$})
|
20
|
+
end
|
21
|
+
|
22
|
+
def unzip(zip_file, out_dir, *args, &blk)
|
23
|
+
bash "unzip #{zip_file} -d #{out_dir}"
|
24
|
+
end
|
25
|
+
|
26
|
+
def tar_xf(tar_file, out_dir, *args, &blk)
|
27
|
+
bash "tar xf #{tar_file} -C #{out_dir}"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module RoHelper
|
2
|
+
module Rmt
|
3
|
+
module Determinations
|
4
|
+
def lc?(*args, &blk)
|
5
|
+
host?('lchost') or host?("localhost")
|
6
|
+
end
|
7
|
+
|
8
|
+
def host?(hostname, *args, &blk)
|
9
|
+
host == hostname
|
10
|
+
end
|
11
|
+
|
12
|
+
def rmt?(*args, &blk)
|
13
|
+
rmt?('rmthost')
|
14
|
+
end
|
15
|
+
|
16
|
+
def x?(*args, &blk)
|
17
|
+
x?('xhost')
|
18
|
+
end
|
19
|
+
|
20
|
+
def rt?(*args, &blk)
|
21
|
+
user == 'root'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require File.expand_path("../../../../conf/ro_rmt", __FILE__)
|
2
|
+
require 'ro_cell/rmt/file'
|
3
|
+
require 'ro_cell/rmt/dir'
|
4
|
+
require_relative 'file_dir'
|
5
|
+
require_relative 'scp'
|
6
|
+
|
7
|
+
module RoHelper
|
8
|
+
module Rmt
|
9
|
+
module File
|
10
|
+
include FileDir
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'ro_helper/misc'
|
2
|
+
require 'ro_cell/rmt/file'
|
3
|
+
require 'ro_cell/rmt/dir'
|
4
|
+
require 'ro_core_ext/module'
|
5
|
+
|
6
|
+
module RoHelper
|
7
|
+
module Rmt
|
8
|
+
module FileDir
|
9
|
+
class << self
|
10
|
+
def included(base)
|
11
|
+
base.send(:include, RoHelper::Misc)
|
12
|
+
|
13
|
+
base.class_eval do
|
14
|
+
meth_name = cst_basename
|
15
|
+
ins_name = meth_name
|
16
|
+
kls_name = "RoCell::Rmt::#{cst_kls_name}"
|
17
|
+
|
18
|
+
begin
|
19
|
+
kls = eval(kls_name)
|
20
|
+
rescue NameError => e
|
21
|
+
kls = nil
|
22
|
+
end
|
23
|
+
|
24
|
+
if kls
|
25
|
+
def_meth(meth_name) do |path, *args, &blk|
|
26
|
+
begin
|
27
|
+
last_frame = ro_trace.last_frame_not(file: %r{\/rmt\/})
|
28
|
+
meth_name = last_frame.meth
|
29
|
+
file = last_frame.file
|
30
|
+
|
31
|
+
Out.out "##{meth_name} ---- in #{file}"
|
32
|
+
kls.new(path, {se: RoCell::Rmt::SeMgr.cur_se}, *args, &blk)
|
33
|
+
rescue Exception => e
|
34
|
+
raise e
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
ms = kls.ins_meths_defined_in_self
|
39
|
+
|
40
|
+
# set breakpoint on RmtFile#meth_name or RmtDir#meth_name to dbg
|
41
|
+
|
42
|
+
# def file_write and write_file
|
43
|
+
ms.each do |meth_name|
|
44
|
+
new_meth_name = "#{ins_name}_#{meth_name}"
|
45
|
+
reverse_meth_name = "#{meth_name}_#{ins_name}".gsub(%r{(.+)\?(.+)}, '\1\2?')
|
46
|
+
def_meth(new_meth_name) do |path, *args, &blk|
|
47
|
+
send(:"#{ins_name}", path).send(:"#{meth_name}", *args, &blk)
|
48
|
+
end
|
49
|
+
|
50
|
+
def_meth(reverse_meth_name) do |*args, &blk|
|
51
|
+
send(:"#{new_meth_name}", *args, &blk)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module RoHelper
|
2
|
+
module Rmt
|
3
|
+
module Process
|
4
|
+
def kill(pid, *args, &blk)
|
5
|
+
begin
|
6
|
+
if lc?
|
7
|
+
::Bash.kill(pid)
|
8
|
+
else
|
9
|
+
sudo "kill -s KILL #{pid}"
|
10
|
+
end
|
11
|
+
rescue SSHKit::Runner::ExecuteError => e
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def running?(kw, *args, &blk)
|
16
|
+
pgrep.any? do |l|
|
17
|
+
l.match(kw)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def get_result(*args, &blk)
|
22
|
+
YAML.load(read_file("/tmp/rb_eval_result.yml"))
|
23
|
+
end
|
24
|
+
|
25
|
+
def pgrep(*args, &blk)
|
26
|
+
eval_script RoRmt.lib("ro_script/pgrep.rb")
|
27
|
+
get_result
|
28
|
+
end
|
29
|
+
|
30
|
+
def kill_port(port, *args, &blk)
|
31
|
+
script_file = RoRmt.lib("ro_script/kill_port")
|
32
|
+
eval_script(script_file, port)
|
33
|
+
end
|
34
|
+
|
35
|
+
def service(*args, &blk)
|
36
|
+
sudo "service #{args.join(" ")}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def pkill(*args, &blk)
|
40
|
+
re_str = "\"#{args.join(" ")}\""
|
41
|
+
eval_script RoRmtPlus.lib("ro_script/pkill.rb"), re_str
|
42
|
+
get_result
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'ro_core_ext/kernel'
|
2
|
+
module ::RoHelper
|
3
|
+
module Rmt
|
4
|
+
module Rb
|
5
|
+
def create_lc_script(_script, *args, &blk)
|
6
|
+
script = _script.del_blank.gsub(%r{\"}, "'")
|
7
|
+
ctn = <<-CONTENT
|
8
|
+
#!/usr/bin/env ruby
|
9
|
+
|
10
|
+
require 'fileutils'
|
11
|
+
require 'yaml'
|
12
|
+
require 'open3'
|
13
|
+
|
14
|
+
def bash(*args, &blk)
|
15
|
+
cmd = args.join(' ')
|
16
|
+
out, err, status = Open3.capture3(cmd)
|
17
|
+
unless status.success?
|
18
|
+
raise err
|
19
|
+
end
|
20
|
+
out
|
21
|
+
end
|
22
|
+
|
23
|
+
result = lambda do
|
24
|
+
begin
|
25
|
+
#{script}
|
26
|
+
rescue Exception => e
|
27
|
+
e
|
28
|
+
end
|
29
|
+
end.call
|
30
|
+
|
31
|
+
File.write('#{eval_result_file}', YAML.dump(result))
|
32
|
+
CONTENT
|
33
|
+
|
34
|
+
script2 = %Q(#{ctn})
|
35
|
+
fin_script = ::RoCell::Formatter.format(script2)
|
36
|
+
RoFile.write(script_path, fin_script)
|
37
|
+
end
|
38
|
+
|
39
|
+
def script_path(*args, &blk)
|
40
|
+
RoFile.join "/tmp/rb_eval/scripts", *args, &blk
|
41
|
+
end
|
42
|
+
|
43
|
+
def eval_result_file(*args, &blk)
|
44
|
+
"/tmp/rb_eval/result.yml"
|
45
|
+
end
|
46
|
+
|
47
|
+
def rb(*args, &blk)
|
48
|
+
eval(*args, &blk)
|
49
|
+
end
|
50
|
+
|
51
|
+
def rb2(*args, &blk)
|
52
|
+
rb_exe(*args, &blk)
|
53
|
+
end
|
54
|
+
|
55
|
+
def rb_exe(script, *args, &blk)
|
56
|
+
bash("ruby -e '#{script}'")
|
57
|
+
end
|
58
|
+
|
59
|
+
def rb3(*args, &blk)
|
60
|
+
rb_capture(*args, &blk)
|
61
|
+
end
|
62
|
+
|
63
|
+
def rb_capture(script, *args, &blk)
|
64
|
+
bash_shutup("ruby -e \"#{script}\"").try_to_boolean
|
65
|
+
end
|
66
|
+
|
67
|
+
def eval(script, *args, &blk)
|
68
|
+
script = script.gsub(%r{\n$}, "")
|
69
|
+
fin_script = %Q(#{script})
|
70
|
+
r = bash_shutup "ruby -e \"require 'fileutils'; require 'yaml'; puts(YAML.dump(#{fin_script}))\""
|
71
|
+
YAML.load(r)
|
72
|
+
end
|
73
|
+
|
74
|
+
def up_eval_script(f, *args, &blk)
|
75
|
+
lc, rmt = get_lc_rmt_script_path(f)
|
76
|
+
up(lc)
|
77
|
+
eval_script(f, *args, &blk)
|
78
|
+
end
|
79
|
+
|
80
|
+
# if you can not eval script since script is too complex, up script and run it with this meth, mk writing more easier. Attention, if script exist in rmt, #eval_script will run this script without uploading
|
81
|
+
# @example see lib/ro_script/pkill.rb
|
82
|
+
# attention: don't use puts on ruby path if you wanna get a correct value from sv, sshkit will capture full stdout, and it will effect your val
|
83
|
+
|
84
|
+
# @param [String] _path lc script path
|
85
|
+
|
86
|
+
def eval_script(_path, *args, &blk)
|
87
|
+
lc, rmt = get_lc_rmt_script_path(_path)
|
88
|
+
|
89
|
+
begin
|
90
|
+
_eval_script(rmt, *args, &blk)
|
91
|
+
rescue ::RoErr::RmtErr => e
|
92
|
+
msg = e.to_s
|
93
|
+
if msg.match(%r{No such file or directory})
|
94
|
+
up(lc, rmt)
|
95
|
+
elsif msg.match(%r{cannot load such file})
|
96
|
+
bash "gem 'ro_thor', git: 'https://github.com/roroco/ro_thor'"
|
97
|
+
else
|
98
|
+
raise e
|
99
|
+
end
|
100
|
+
|
101
|
+
_eval_script(rmt, *args, &blk)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
def get_lc_rmt_script_path(_path)
|
106
|
+
lc = _path.suffix(".rb")
|
107
|
+
|
108
|
+
unless test(?f, lc)
|
109
|
+
lc = Pj.cur_lib("ro_script", lc)
|
110
|
+
end
|
111
|
+
|
112
|
+
rmt = lc.gsub(Pj.home, home)
|
113
|
+
return lc, rmt
|
114
|
+
end
|
115
|
+
|
116
|
+
def _eval_script(rmt, *args, &blk)
|
117
|
+
begin
|
118
|
+
bash("ruby #{rmt} #{args.join(" ")}")
|
119
|
+
rescue ::RoErr::RmtErr => e
|
120
|
+
if e.to_s.match("cannot load such file -- ro_thor")
|
121
|
+
Out.warn e
|
122
|
+
bash "sudo gem install 'ro_thor'"
|
123
|
+
_eval_script(rmt, *args, &blk)
|
124
|
+
else
|
125
|
+
raise e
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require 'ro_helper/misc'
|
2
|
+
require_relative 'se_attrs'
|
3
|
+
require 'net/scp'
|
4
|
+
|
5
|
+
module RoHelper
|
6
|
+
module Rmt
|
7
|
+
module Scp
|
8
|
+
include ::RoHelper::Misc
|
9
|
+
include SeAttrs
|
10
|
+
|
11
|
+
def se(*args, &blk)
|
12
|
+
if defined? super
|
13
|
+
return super
|
14
|
+
end
|
15
|
+
|
16
|
+
not_implement
|
17
|
+
end
|
18
|
+
|
19
|
+
def tmply_down(path, *args, &blk)
|
20
|
+
to_tmp_path = down_to_tmp(path)
|
21
|
+
r = yield(to_tmp_path)
|
22
|
+
up_tmp(path)
|
23
|
+
r
|
24
|
+
end
|
25
|
+
|
26
|
+
def scp(*args, &blk)
|
27
|
+
se.scp(*args, &blk)
|
28
|
+
end
|
29
|
+
|
30
|
+
def out(*args, &blk)
|
31
|
+
ro_trace.tap do |c|
|
32
|
+
last_meth_name = c.last_meth
|
33
|
+
call_line = c.last.not(file: __FILE__).location
|
34
|
+
Out.status("#{last_meth_name}", "#{args.join(" ")} ---- #{call_line}")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def down(*args, &blk)
|
39
|
+
out
|
40
|
+
_down(*args, &blk)
|
41
|
+
end
|
42
|
+
|
43
|
+
def down2(url, output_name = nil, *args, &blk)
|
44
|
+
output_name ||= RoFile.basename(url)
|
45
|
+
path = "~/Downloads/#{output_name}"
|
46
|
+
unless exist?(path)
|
47
|
+
dir = RoFile.parent(path)
|
48
|
+
bash("mkdir -p #{dir}; cd #{dir}; aria2c #{url} --out #{RoFile.basename(path)}")
|
49
|
+
if block_given?
|
50
|
+
yield path
|
51
|
+
end
|
52
|
+
end
|
53
|
+
path
|
54
|
+
end
|
55
|
+
|
56
|
+
def _down(from, to=nil, *args, &blk)
|
57
|
+
to ||= from
|
58
|
+
RoFile.mkparent(to)
|
59
|
+
Out.status("down", "\nfrom #{from}\nto #{to}")
|
60
|
+
Out.out
|
61
|
+
|
62
|
+
# don't use if rmt_path_is_dir?, it will waste time, use #download_dir to download a dir
|
63
|
+
scp.download!(from, to, *args, &blk)
|
64
|
+
to
|
65
|
+
end
|
66
|
+
|
67
|
+
def down_dir(*args, &blk)
|
68
|
+
not_implement
|
69
|
+
end
|
70
|
+
|
71
|
+
def up(f, *args, &blk)
|
72
|
+
out(f)
|
73
|
+
_up(f, *args, &blk)
|
74
|
+
end
|
75
|
+
|
76
|
+
def _up(from, to=nil, *args, &blk)
|
77
|
+
to ||= from
|
78
|
+
|
79
|
+
from = from.gsub(%r{^~}, Pj.home)
|
80
|
+
to = format_path(to)
|
81
|
+
|
82
|
+
begin
|
83
|
+
rsync(from, to: to)
|
84
|
+
rescue ::RoErr::BashErr => e
|
85
|
+
if e.match("Permission denied")
|
86
|
+
tmp_to = RoFile.join("/tmp", to.gsub(%r{/}, "-"))
|
87
|
+
rsync(from, to: tmp_to)
|
88
|
+
bash "sudo mv #{tmp_to} #{to}"
|
89
|
+
else
|
90
|
+
raise e
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
to
|
95
|
+
end
|
96
|
+
|
97
|
+
def down_to_tmp(from_rmt_path, *args, &blk)
|
98
|
+
out
|
99
|
+
to_lc_path = lc_tmp(from_rmt_path)
|
100
|
+
_down(from_rmt_path, to_lc_path)
|
101
|
+
end
|
102
|
+
|
103
|
+
def lc_tmp(path=nil)
|
104
|
+
RoRmt.cur_tmp("#{user}/at/#{host}", path)
|
105
|
+
end
|
106
|
+
|
107
|
+
def up_tmp(to_rmt_path, *args, &blk)
|
108
|
+
out
|
109
|
+
from_lc_path = lc_tmp(to_rmt_path)
|
110
|
+
_up(from_lc_path, to_rmt_path)
|
111
|
+
rmt_path = to_rmt_path
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
|
116
|
+
end
|
117
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'ro_helper/misc'
|
2
|
+
module ::RoHelper
|
3
|
+
module Rmt
|
4
|
+
module SeAttrs
|
5
|
+
include ::RoHelper::Misc
|
6
|
+
|
7
|
+
# attr_accessor :se, :se_backup
|
8
|
+
attr_accessor :se
|
9
|
+
|
10
|
+
def host
|
11
|
+
@host ||= se.transport.host
|
12
|
+
end
|
13
|
+
|
14
|
+
def user
|
15
|
+
@user ||= se.options[:user]
|
16
|
+
end
|
17
|
+
|
18
|
+
def port
|
19
|
+
@port ||= se.transport.port
|
20
|
+
end
|
21
|
+
|
22
|
+
def user_at_host
|
23
|
+
@user_at_host ||= "#{user}@#{host}"
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|