ro_rmt 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c4e323048d7804e90462b44a3ff03e95c9586601
|
4
|
+
data.tar.gz: 1a3c961453b18664cd550472e0a3b2f0d61e5b03
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d84687619037d6849baa0bdc39197392814a411d8ad789b55561aee3bb90ba9c0f9683136636aa5ce78f5720578f20fde4a602f084a4cbd7a0bf49671f5e2f79
|
7
|
+
data.tar.gz: 5f5d022ec56f305d6ac6d30e72145cb1ec9f7410df6629ec869ff79c84697b907cd675aeb01109ddedfb172f13fce0a4317723911a80b04c7e9a5935cf31d064
|
data/README.md
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
[![Build Status](https://travis-ci.org/roroco/ro_deploy.svg?branch=master)](https://travis-ci.org/roroco/ro_deploy)
|
2
|
+
|
3
|
+
[![Code Climate](https://codeclimate.com/github/roroco/ro_deploy.png)](https://codeclimate.com/github/roroco/ro_deploy)
|
4
|
+
|
5
|
+
# RoDeploy
|
6
|
+
|
7
|
+
## License
|
8
|
+
[MIT License](http://www.opensource.org/licenses/MIT)
|
9
|
+
|
10
|
+
## Why and who should use this gem
|
11
|
+
please see following bash output
|
12
|
+
this is run `ping google.com` in my pc
|
13
|
+
|
14
|
+
PING google.com (203.208.46.200) 56(84) bytes of data.
|
15
|
+
64 bytes from 0.docs.google.com (203.208.46.200): icmp_seq=1 ttl=55 time=224 ms
|
16
|
+
64 bytes from 0.docs.google.com (203.208.46.200): icmp_seq=2 ttl=55 time=780 ms
|
17
|
+
64 bytes from 0.docs.google.com (203.208.46.200): icmp_seq=3 ttl=55 time=864 ms
|
18
|
+
64 bytes from 0.docs.google.com (203.208.46.200): icmp_seq=4 ttl=55 time=891 ms
|
19
|
+
^C
|
20
|
+
--- google.com ping statistics ---
|
21
|
+
5 packets transmitted, 4 received, 20% packet loss, time 4000ms
|
22
|
+
rtt min/avg/max/mdev = 224.364/690.234/891.314/272.077 ms
|
23
|
+
|
24
|
+
This is run `ping google.com` in my vps
|
25
|
+
|
26
|
+
64 bytes from hg-in-f138.1e100.net (74.125.128.138): icmp_req=1 ttl=50 time=2.74 ms
|
27
|
+
64 bytes from hg-in-f138.1e100.net (74.125.128.138): icmp_req=2 ttl=50 time=3.34 ms
|
28
|
+
64 bytes from hg-in-f138.1e100.net (74.125.128.138): icmp_req=3 ttl=50 time=6.07 ms
|
29
|
+
64 bytes from hg-in-f138.1e100.net (74.125.128.138): icmp_req=4 ttl=50 time=5.43 ms
|
30
|
+
64 bytes from hg-in-f138.1e100.net (74.125.128.138): icmp_req=5 ttl=50 time=2.61 ms
|
31
|
+
|
32
|
+
so if you are in Mainland China like me, this gem will help you save 780/2.74 = 284.67times time than you deploy a rails app to remotehost, wtf!
|
33
|
+
|
34
|
+
## Getting Started
|
35
|
+
|
36
|
+
see [wiki](http://rorocodeath.com/docs/ro_deploy)
|
37
|
+
|
38
|
+
|
39
|
+
## About RoDeploy
|
40
|
+
ro_deploy is base on capistrano and sshkit, i just make it can deploy rails app to root@localhost. so if you wanna more function, please see sshkit and capistrano.
|
41
|
+
|
42
|
+
## I design ro_deploy in three points
|
43
|
+
1. deploy app to root@localhost for debugging
|
44
|
+
2. deploy app to root@remotehost(please set remotehost in you /etc/hosts)
|
45
|
+
3. and complete write ssh commands with ruby, like ro_deploy do, you can inherited ::RoDeployBase to build you own cmd, for details information, please support me a job, I am to find a job.
|
46
|
+
|
47
|
+
## RoadMap
|
48
|
+
- <del> install mysql without prompt</del>
|
49
|
+
- <del> nginx config</del>
|
50
|
+
- <del> retry pid_file_exist?, make sure it can return a true</del>
|
51
|
+
- <del> add initd restart initd service</del>
|
52
|
+
- <del> pass all spec</del>
|
53
|
+
- <del> add initd cmd(add unicorn start stop restart)</del>
|
54
|
+
- <del> add before after hook in ro_commands</del>
|
55
|
+
- <del> customize remote_root</del>
|
56
|
+
- <del> make js and css in public/assets can be read</del>
|
57
|
+
- add config generator.
|
58
|
+
- make a process manager sort by ram/cpu percent
|
59
|
+
- add ::RoCell::Remote spec
|
60
|
+
- pass all spec(nginx unicorn remote rbenv ...)
|
61
|
+
- make a bin? through check all paths in PATHS
|
62
|
+
- add initd.sh on startup
|
63
|
+
- deploy ro_commands_rails
|
64
|
+
- add ro_commands/initd
|
65
|
+
- run `bundle install` in remote, and show detail like capistrano
|
66
|
+
|
67
|
+
### RoZeus
|
68
|
+
- make ro_zeus with drb, which function like zeus
|
69
|
+
- ro_zeus.run_ro
|
70
|
+
- ro_zeus.run_rake
|
71
|
+
- with listen gem, restart ro_zeus when specific files(defined in ro_deploy/config) change or sm actions done, specific files is all rb files in project, sm actions default is bundle install,bundle update.
|
72
|
+
- make remote_action to_run_misc can work with ro_zeus
|
73
|
+
|
74
|
+
### make a damu maker
|
75
|
+
- use videojs
|
76
|
+
- play, pause and jump shortcuts
|
77
|
+
- layout like bilibili
|
78
|
+
- send a damu like bilibili(use canva)
|
79
|
+
- delete exist damu
|
80
|
+
- change damu occur time and lifecycle
|
81
|
+
- autosave damu change like google drive
|
82
|
+
- deploy this
|
83
|
+
- close autosave function in web app
|
84
|
+
|
85
|
+
## misc
|
86
|
+
- get error output when bash crashed like capistrano
|
87
|
+
|
88
|
+
- save stage value to redis
|
89
|
+
|
90
|
+
- judge current env is travis-ci throught add before script `RO_CURRENT_ENV=ci`
|
91
|
+
- write a rake task "ci_init" with ro and change rake defaults
|
data/conf/ro_rmt.rb
ADDED
@@ -0,0 +1,203 @@
|
|
1
|
+
require 'pj_helper'
|
2
|
+
require 'out'
|
3
|
+
require 'bash'
|
4
|
+
require 'ro_core_ext/kernel'
|
5
|
+
|
6
|
+
$LOAD_PATH.unshift File.expand_path("../..", __FILE__)
|
7
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
8
|
+
|
9
|
+
module ::RoRmt
|
10
|
+
extend PjHelper
|
11
|
+
include Bash
|
12
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def rt(*args, &blk)
|
16
|
+
r = File.expand_path("../..", __FILE__)
|
17
|
+
RoFile.join r, *args, &blk
|
18
|
+
end
|
19
|
+
|
20
|
+
# attr_writer :rmt_repo
|
21
|
+
|
22
|
+
# def rmt_repo
|
23
|
+
# @rmt_repo ||= "https://gitcafe.com/rorocodeath/rmt_repo.git"
|
24
|
+
# #@rmt_repo ||= lambda do
|
25
|
+
# # lines = bash_lines "git remote -v"
|
26
|
+
# # ssh_repo_url = nil
|
27
|
+
# # lines.each do |line|
|
28
|
+
# # if line.match(%r{remote\_repo\s+(.*)\s\(fetch\)})
|
29
|
+
# # ssh_repo_url = $1
|
30
|
+
# # end
|
31
|
+
# # end
|
32
|
+
# #
|
33
|
+
# # if ssh_repo_url
|
34
|
+
# # http_repo_url = ssh_repo_url.gsub(%r{git@(github|gitcafe)\:}, "https://gitcafe.com/")
|
35
|
+
# # else
|
36
|
+
# # raise "please set a rmt_repo throught `git remote add rmt_repo git_https_repo_url`"
|
37
|
+
# # end
|
38
|
+
# #end.call
|
39
|
+
# end
|
40
|
+
#
|
41
|
+
# attr_accessor :attrs
|
42
|
+
#
|
43
|
+
# def attrs
|
44
|
+
# @attrs.flatten! if defined?(@attrs) and @attrs.respond_to?(:flatten!)
|
45
|
+
# @attrs.uniq! if defined?(@attrs) and @attrs.respond_to?(:uniq!)
|
46
|
+
# @attrs ||= []
|
47
|
+
# end
|
48
|
+
#
|
49
|
+
# attr_writer :relative_url_rt
|
50
|
+
#
|
51
|
+
# def relative_url_rt
|
52
|
+
# @relative_url_rt ||= "/"
|
53
|
+
# end
|
54
|
+
#
|
55
|
+
# def singleton_method_added(attr)
|
56
|
+
# unless attr.match(%r{out_for_debug|#{__method__}})
|
57
|
+
# attrs << attr
|
58
|
+
# end
|
59
|
+
# end
|
60
|
+
#
|
61
|
+
# def out_for_dbg
|
62
|
+
# attrs.each do |attr|
|
63
|
+
# args = method(attr).parameters
|
64
|
+
# if args.length == 0
|
65
|
+
# Out.out "#{Out.set_padding attr.to_s, 20}#{send(attr)}"
|
66
|
+
# end
|
67
|
+
# end
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# attr_accessor :ruby
|
71
|
+
#
|
72
|
+
# def ruby
|
73
|
+
# @ruby ||= "2.0.0-p353"
|
74
|
+
# end
|
75
|
+
#
|
76
|
+
# attr_accessor :log
|
77
|
+
#
|
78
|
+
# def rmt_log(stage)
|
79
|
+
# @log ||= File.join(rmt_rt, "log/#{stage}.log")
|
80
|
+
# end
|
81
|
+
#
|
82
|
+
# attr_accessor :pj_rt
|
83
|
+
#
|
84
|
+
# def pj_rt(*args, &blk)
|
85
|
+
# _rt = File.expand_path("../../..", __FILE__)
|
86
|
+
# RoFile.join _rt, *args, &blk
|
87
|
+
# end
|
88
|
+
#
|
89
|
+
# alias_method :rt, :pj_rt
|
90
|
+
# attr_accessor :pj_name
|
91
|
+
#
|
92
|
+
# def pj_name
|
93
|
+
# @pj_name ||= lambda do
|
94
|
+
# basename = File.basename(pj_rt).gsub(%r{\.\w+$}, "")
|
95
|
+
# end.call
|
96
|
+
# end
|
97
|
+
#
|
98
|
+
# attr_accessor :rmt_role
|
99
|
+
#
|
100
|
+
# def rmt_role
|
101
|
+
# @rmt_role ||= ["#{::RoRmt.rmt_user}@remotehost"]
|
102
|
+
# end
|
103
|
+
#
|
104
|
+
# attr_writer :rmt_user
|
105
|
+
#
|
106
|
+
# def rmt_user
|
107
|
+
# @rmt_user ||= "rt"
|
108
|
+
# end
|
109
|
+
#
|
110
|
+
# attr_accessor :local_role
|
111
|
+
#
|
112
|
+
# def local_role
|
113
|
+
# @local_role ||= ["#{::RoRmt.rmt_user}@localhost"]
|
114
|
+
# end
|
115
|
+
#
|
116
|
+
# attr_writer :cur_stage
|
117
|
+
#
|
118
|
+
# def cur_stage
|
119
|
+
# @cur_stage ||= "staging"
|
120
|
+
# end
|
121
|
+
#
|
122
|
+
# attr_accessor :cur_role
|
123
|
+
#
|
124
|
+
# def cur_role
|
125
|
+
# @cur_role ||= obj("ro_deploy_cur_role") || local_role
|
126
|
+
# end
|
127
|
+
#
|
128
|
+
# alias_method :role, :cur_role
|
129
|
+
# attr_accessor :deploy_to
|
130
|
+
#
|
131
|
+
# def dp_to
|
132
|
+
# @dp_to ||= "/var/www/#{pj_name}"
|
133
|
+
# end
|
134
|
+
#
|
135
|
+
# attr_accessor :rmt_bin
|
136
|
+
#
|
137
|
+
# def rmt_bin
|
138
|
+
# @rmt_bin ||= File.join(deploy_to, 'shared/bin')
|
139
|
+
# end
|
140
|
+
#
|
141
|
+
# attr_accessor :rmt_rt
|
142
|
+
#
|
143
|
+
# def rmt_rt
|
144
|
+
# rmt_rt ||= File.join(deploy_to, "cur")
|
145
|
+
# end
|
146
|
+
#
|
147
|
+
# attr_accessor :rmt_tmp
|
148
|
+
#
|
149
|
+
# def rmt_tmp
|
150
|
+
# @rmt_tmp ||= File.join(rmt_rt, "tmp")
|
151
|
+
# end
|
152
|
+
#
|
153
|
+
# attr_accessor :unicorn_pid
|
154
|
+
#
|
155
|
+
# def unicorn_pid
|
156
|
+
# @unicorn_std_err_path ||= File.join(rmt_tmp, "pids/unicorn.pid")
|
157
|
+
# end
|
158
|
+
#
|
159
|
+
# attr_accessor :unicorn_stderr_path
|
160
|
+
#
|
161
|
+
# def unicorn_stderr_path
|
162
|
+
# @unicorn_stderr_path ||= File.join(rmt_rt, "log/unicorn.log")
|
163
|
+
# end
|
164
|
+
#
|
165
|
+
# attr_accessor :initd_log
|
166
|
+
#
|
167
|
+
# def initd_log
|
168
|
+
# @initd_log ||= "/tmp/#{pj_name}.log"
|
169
|
+
# end
|
170
|
+
#
|
171
|
+
# attr_accessor :bash_log
|
172
|
+
#
|
173
|
+
# def bash_log
|
174
|
+
# @bash_log ||= "/tmp/#{pj_name}/error.log"
|
175
|
+
# end
|
176
|
+
#
|
177
|
+
# attr_accessor :unicorn_stdout_path
|
178
|
+
#
|
179
|
+
# def unicorn_stdout_path
|
180
|
+
# @unicorn_stdout_path ||= unicorn_stderr_path
|
181
|
+
# end
|
182
|
+
#
|
183
|
+
# attr_accessor :unicorn_listen
|
184
|
+
#
|
185
|
+
# def unicorn_listen
|
186
|
+
# @unicorn_listen ||= "/tmp/unicorn.#{pj_name}.sock"
|
187
|
+
# end
|
188
|
+
#
|
189
|
+
# attr_accessor :rmt_home
|
190
|
+
#
|
191
|
+
# def rmt_home
|
192
|
+
# @rmt_home ||= "/rt"
|
193
|
+
# end
|
194
|
+
#
|
195
|
+
# attr_accessor :rmt_bundle
|
196
|
+
#
|
197
|
+
# def rmt_bundle
|
198
|
+
# @rmt_bundle ||= File.join(home, '.rbenv/shims/bundle')
|
199
|
+
# end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
|
data/lib/ro_cell/rmt.rb
ADDED
@@ -0,0 +1,254 @@
|
|
1
|
+
require File.expand_path("../../../conf/ro_rmt", __FILE__)
|
2
|
+
require 'ro_helper/meta'
|
3
|
+
|
4
|
+
require 'ro_core_exts'
|
5
|
+
|
6
|
+
require 'ro_helper/rmt/basic'
|
7
|
+
require 'ro_helper/rmt/compress'
|
8
|
+
require 'ro_helper/rmt/determinations'
|
9
|
+
require 'ro_helper/rmt/file'
|
10
|
+
require 'ro_helper/rmt/dir'
|
11
|
+
require 'ro_helper/rmt/file_dir'
|
12
|
+
require 'ro_helper/rmt/process'
|
13
|
+
require 'ro_helper/rmt/rb'
|
14
|
+
require 'ro_helper/rmt/scp'
|
15
|
+
require 'ro_helper/rmt/se_attrs'
|
16
|
+
|
17
|
+
require 'ro_cell/openstructs'
|
18
|
+
|
19
|
+
module ::RoCell
|
20
|
+
class Rmt
|
21
|
+
include ::RoHelper::Meta
|
22
|
+
include ::RoHelper::Rmt::Basic
|
23
|
+
include ::RoHelper::Rmt::Compress
|
24
|
+
include ::RoHelper::Rmt::Determinations
|
25
|
+
include ::RoHelper::Rmt::File
|
26
|
+
include ::RoHelper::Rmt::Dir
|
27
|
+
include ::RoHelper::Rmt::FileDir
|
28
|
+
include ::RoHelper::Rmt::Process
|
29
|
+
include ::RoHelper::Rmt::Rb
|
30
|
+
include ::RoHelper::Rmt::Scp
|
31
|
+
include ::RoHelper::Rmt::SeAttrs
|
32
|
+
|
33
|
+
def cat(file, to=nil)
|
34
|
+
if to
|
35
|
+
bash "cat #{file} > #{to}"
|
36
|
+
else
|
37
|
+
r = capture "cat #{file}"
|
38
|
+
Out.out_file(r)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def install(*args)
|
43
|
+
smths, opts = args.ro_opts
|
44
|
+
ignore_apt_get_bugs do
|
45
|
+
if os and os == "fedora"
|
46
|
+
bash "sudo yum install #{smths.hits.join(" ")} -y"
|
47
|
+
else
|
48
|
+
begin
|
49
|
+
if opts[:nointeractive]
|
50
|
+
bash "export DEBIAN_FRONTEND=noninteractive; sudo -E apt-get install #{smths.hits.join(" ")} -y"
|
51
|
+
else
|
52
|
+
bash "sudo -E apt-get install #{smths.hits.join(" ")} -y"
|
53
|
+
end
|
54
|
+
rescue Exception => e
|
55
|
+
if e.to_s.match("[Errno 14] HTTP Error 404 - Not Found")
|
56
|
+
bash "sudo apt-get update"
|
57
|
+
bash "#{http_x_str} DEBIAN_FRONTEND=nointeractive sudo apt-get install #{smths.hits.join(" ")} -y"
|
58
|
+
else
|
59
|
+
raise e
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def ignore_apt_get_bugs(*args, &blk)
|
67
|
+
begin
|
68
|
+
yield
|
69
|
+
rescue ::RoErr::RmtErr => e
|
70
|
+
msg = e.msg
|
71
|
+
unless msg.match("debconf: unable to initialize frontend: Dialog")\
|
72
|
+
or msg.match("W: Duplicate sources.list")\
|
73
|
+
or msg.match("Failed to fetch")
|
74
|
+
# or msg.match("[Errno 14] HTTP Error 404 - Not Found")\
|
75
|
+
raise e
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
|
81
|
+
def install_from_src(bin, url, *args, &blk)
|
82
|
+
opts = args.extract_options!
|
83
|
+
basename = File.basename(url).gsub(%r{\.tar\.gz$}, "")
|
84
|
+
|
85
|
+
unless bin?(bin)
|
86
|
+
wget(url)
|
87
|
+
tar(basename)
|
88
|
+
end
|
89
|
+
|
90
|
+
dir = File.join "~/Downloads", basename
|
91
|
+
if opts[:force]
|
92
|
+
make(dir)
|
93
|
+
else
|
94
|
+
unless bin?(bin)
|
95
|
+
make(dir)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
if bin.match(%r{node})
|
100
|
+
link(File.join(dir, 'node'))
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
def link(bin_path)
|
105
|
+
bin = File.basename(bin_path).gsub(%r{\.\w+$}, "")
|
106
|
+
cmd "sudo ln -sf #{bin_path} /usr/bin/#{bin}"
|
107
|
+
end
|
108
|
+
|
109
|
+
def chmod(mode=nil, *args, &blk)
|
110
|
+
mode ||= 755
|
111
|
+
cmd "sudo chmod #{mode} #{args.join(" ")}"
|
112
|
+
end
|
113
|
+
|
114
|
+
def make(dir)
|
115
|
+
cmd "cd #{dir} && make"
|
116
|
+
end
|
117
|
+
|
118
|
+
def wget(url)
|
119
|
+
mkdir "~/Downloads"
|
120
|
+
|
121
|
+
unless exist_dir?("~/Downloads/#{File.basename(url)}")
|
122
|
+
cmd "cd ~/Downloads && wget #{url}"
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def tar(file_name)
|
127
|
+
dir = file_name
|
128
|
+
tar_file = "#{file_name}.tar.gz"
|
129
|
+
unless dir_exist? File.join("~/Downloads", dir)
|
130
|
+
cmd "cd ~/Downloads && tar xzf #{tar_file}"
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def rm_file(file)
|
135
|
+
cmd "rm -f #{file}"
|
136
|
+
end
|
137
|
+
|
138
|
+
def rm_dir_or_file(smth, *args, &blk)
|
139
|
+
cmd "rm -rf #{smth}"
|
140
|
+
end
|
141
|
+
|
142
|
+
alias_method :rm, :rm_file
|
143
|
+
|
144
|
+
def tail(file, last_lines_number=100)
|
145
|
+
Out.status("tailing", "#{file}")
|
146
|
+
|
147
|
+
result = capture "tail #{file} -n #{last_lines_number}"
|
148
|
+
# Out.out result
|
149
|
+
end
|
150
|
+
|
151
|
+
def act_log(act, log)
|
152
|
+
act = Out.set_color("#{act.camelize}ing", "green")
|
153
|
+
cmd "echo \"#{act} at $(date)\">>#{log}"
|
154
|
+
end
|
155
|
+
|
156
|
+
def bin?(name)
|
157
|
+
# begin
|
158
|
+
r = (exist_file?("/usr/bin/#{name}") or exist_file?("/bin/#{name}"))
|
159
|
+
# rescue SSHKit::Runner::ExecuteError => e
|
160
|
+
# false
|
161
|
+
# end
|
162
|
+
end
|
163
|
+
|
164
|
+
def read(*args, &blk)
|
165
|
+
file_read(*args, &blk)
|
166
|
+
end
|
167
|
+
|
168
|
+
def write(file, ctn, *args, &blk)
|
169
|
+
write_file(file, ctn)
|
170
|
+
end
|
171
|
+
|
172
|
+
def read(*args, &blk)
|
173
|
+
read_file(*args, &blk)
|
174
|
+
end
|
175
|
+
|
176
|
+
def exist?(*args, &blk)
|
177
|
+
exist_file?(*args, &blk)
|
178
|
+
end
|
179
|
+
|
180
|
+
# def read(file, *args, &blk)
|
181
|
+
# file = replace_tilde_with_remote_home(file)
|
182
|
+
# capture_rb_eval("File.read('#{file}')")
|
183
|
+
# end
|
184
|
+
|
185
|
+
def flow
|
186
|
+
yield self
|
187
|
+
end
|
188
|
+
|
189
|
+
def process(*names)
|
190
|
+
if names.empty?
|
191
|
+
capture "ps aux"
|
192
|
+
else
|
193
|
+
capture "ps aux | grep #{names.flatten.join(" ")}"
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
# def download(rmt, lc=nil, opts={})
|
198
|
+
# lc ||= File.basename remote
|
199
|
+
# on ::RoRmt.cur_role do
|
200
|
+
# Out.status("downloading file", "")
|
201
|
+
# Out.out "#{Out.set_color("From", "blue")}:#{remote}"
|
202
|
+
# Out.out "#{Out.set_color("To", "blue")}:#{lc}"
|
203
|
+
#
|
204
|
+
# download!(remote, lc, options)
|
205
|
+
# end
|
206
|
+
# end
|
207
|
+
|
208
|
+
# alias_method :up, :upload
|
209
|
+
|
210
|
+
# def exist_file?(file)
|
211
|
+
# result = capture build_rb_eval("File.exist?('#{file}')")
|
212
|
+
# to_boolean(result)
|
213
|
+
# end
|
214
|
+
|
215
|
+
|
216
|
+
def chdir(dir, *args, &blk)
|
217
|
+
bash "cd #{dir}", *args
|
218
|
+
end
|
219
|
+
|
220
|
+
def cd(*args, &blk)
|
221
|
+
within(*args, &blk)
|
222
|
+
end
|
223
|
+
|
224
|
+
# def dir_exist?(path)
|
225
|
+
# if dir.match(%r{\~})
|
226
|
+
# dir = replace_tilde_with_remote_home(dir)
|
227
|
+
# end
|
228
|
+
#
|
229
|
+
# result = capture build_rb_eval("Dir.exist?('#{dir}')")
|
230
|
+
# result
|
231
|
+
# end
|
232
|
+
|
233
|
+
|
234
|
+
def exist_ctn?(file, re)
|
235
|
+
ctn = capture("cat #{file}")
|
236
|
+
if ctn.match(re)
|
237
|
+
true
|
238
|
+
else
|
239
|
+
false
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
# @deprecated I forget that how to use it
|
244
|
+
|
245
|
+
#def test(*cmd)
|
246
|
+
# cmd = format(*cmd)
|
247
|
+
# result = nil
|
248
|
+
# on ::RoRmt.cur_role do
|
249
|
+
# result = test cmd
|
250
|
+
# end
|
251
|
+
# result
|
252
|
+
#end
|
253
|
+
end
|
254
|
+
end
|