mobilize-ssh 1.298 → 1.299
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +9 -2
- data/lib/mobilize-ssh/handlers/ssh.rb +12 -12
- data/lib/mobilize-ssh/helpers/ssh_helper.rb +0 -8
- data/lib/mobilize-ssh/version.rb +1 -1
- data/test/code2.sh +1 -1
- data/test/ssh_job_rows.yml +8 -8
- metadata +4 -4
data/README.md
CHANGED
@@ -215,14 +215,21 @@ Start
|
|
215
215
|
### Create Job
|
216
216
|
|
217
217
|
* For mobilize-ssh, the following task is available:
|
218
|
-
* ssh.run `node: <node_alias>, cmd: <command>, user: user, sources:[*<source_paths>]`, which reads sources, copies them to a temporary folder on the selected node, and runs the command inside that folder.
|
219
|
-
* user, sources, and
|
218
|
+
* ssh.run `node: <node_alias>, cmd: <command>, user: user, sources:[*<source_paths>], params:[{<key,value pairs>}]`, which reads sources, copies them to a temporary folder on the selected node, and runs the command inside that folder.
|
219
|
+
* user, sources, node, and params are optional; cmd is required.
|
220
220
|
* specifying user will cause the command to be prefixed with sudo su <user> -c.
|
221
221
|
* non-google sources will also be read as the specified user.
|
222
222
|
* git sources can be specified with syntax `git://<domain>/<repo_owner>/<repo_name>/<file_path>`.
|
223
223
|
* Accessing private repos requires that you add the Mobilize public key to the repository as a deploy key.
|
224
224
|
* there is no user-level access control for git repositories at this time.
|
225
225
|
* domain defaults to the first one listed, if not included.
|
226
|
+
* params are also optional for all of the below. They replace tokens in sources and the command.
|
227
|
+
* params are passed as a YML or JSON, as in:
|
228
|
+
* `ssh.run source:<source_path>, params:{'date':'2013-03-01', 'unit':'widgets'}`
|
229
|
+
* this example replaces all the keys, preceded by '@' in all source hqls with the value.
|
230
|
+
* The preceding '@' is used to keep from replacing instances
|
231
|
+
of "date" and "unit" in the command/source file; you should have `@date` and `@unit` in your actual HQL
|
232
|
+
if you'd like to replace those tokens.
|
226
233
|
* not specifying node will cause the command to be run on the default node.
|
227
234
|
* ssh sources can be specified with syntax
|
228
235
|
`ssh://<node><file_full_path>`. If node is omitted, default node will be used.
|
@@ -67,22 +67,21 @@ module Mobilize
|
|
67
67
|
return true
|
68
68
|
end
|
69
69
|
|
70
|
-
def Ssh.run(node,command,
|
71
|
-
|
70
|
+
def Ssh.run(node,command,user_name,file_hash={},run_params=nil)
|
71
|
+
default_user_name = Ssh.host(node)['user']
|
72
72
|
file_hash ||= {}
|
73
|
+
run_params ||={}
|
73
74
|
#make sure the dir for this command is clear
|
74
|
-
comm_md5 = [
|
75
|
+
comm_md5 = [user_name,node,command,file_hash.keys.to_s,Time.now.to_f.to_s].join.to_md5
|
75
76
|
comm_dir = Dir.mktmpdir
|
76
|
-
#add in default methods to the params
|
77
|
-
params.merge(Ssh.default_params)
|
78
77
|
#replace any params in the file_hash and command
|
79
|
-
|
80
|
-
command.gsub!(k,v)
|
78
|
+
run_params.each do |k,v|
|
79
|
+
command.gsub!("@#{k}",v)
|
81
80
|
file_hash.each do |name,data|
|
82
|
-
data.gsub!(k,v)
|
81
|
+
data.gsub!("@#{k}",v)
|
83
82
|
end
|
84
83
|
end
|
85
|
-
|
84
|
+
#populate comm dir with any files
|
86
85
|
Ssh.pop_comm_dir(comm_dir,file_hash)
|
87
86
|
#make sure user starts in rem_dir
|
88
87
|
rem_dir = "#{comm_md5}/"
|
@@ -103,9 +102,9 @@ module Mobilize
|
|
103
102
|
Ssh.write(node,command,cmd_path)
|
104
103
|
full_cmd = "(cd #{rem_dir} && sh #{cmd_file})"
|
105
104
|
#fire_cmd runs sh on cmd_path, optionally with sudo su
|
106
|
-
if
|
105
|
+
if user_name != default_user_name
|
107
106
|
#make sure user owns the folder and all files
|
108
|
-
fire_cmd = %{sudo chown -R #{
|
107
|
+
fire_cmd = %{sudo chown -R #{user_name} #{rem_dir}; sudo su #{user_name} -c "#{full_cmd}"}
|
109
108
|
rm_cmd = %{sudo rm -rf #{rem_dir}}
|
110
109
|
else
|
111
110
|
fire_cmd = full_cmd
|
@@ -216,7 +215,8 @@ module Mobilize
|
|
216
215
|
user_name = Ssh.user_name_by_stage_path(stage_path)
|
217
216
|
file_hash = Ssh.file_hash_by_stage_path(stage_path,gdrive_slot)
|
218
217
|
Gdrive.unslot_worker_by_path(stage_path)
|
219
|
-
|
218
|
+
run_params = params['params']
|
219
|
+
result = Ssh.run(node,command,user_name,file_hash,run_params)
|
220
220
|
#use Gridfs to cache result
|
221
221
|
response = {}
|
222
222
|
response['out_url'] = Dataset.write_by_url("gridfs://#{s.path}/out",result['stdout'].to_s,Gdrive.owner_name)
|
@@ -33,13 +33,5 @@ module Mobilize
|
|
33
33
|
host_domain_name = self.host(node)['name'].split(".")[-2..-1].join(".")
|
34
34
|
return true if self.gateway(node) and Socket.domain_name != host_domain_name
|
35
35
|
end
|
36
|
-
|
37
|
-
def self.default_params
|
38
|
-
time = Time.now.utc
|
39
|
-
{
|
40
|
-
'$utc_date'=>time.strftime("%Y-%m-%d"),
|
41
|
-
'$utc_time'=>time.strftime("%H:%M"),
|
42
|
-
}
|
43
|
-
end
|
44
36
|
end
|
45
37
|
end
|
data/lib/mobilize-ssh/version.rb
CHANGED
data/test/code2.sh
CHANGED
@@ -1 +1 @@
|
|
1
|
-
tail
|
1
|
+
tail @file
|
data/test/ssh_job_rows.yml
CHANGED
@@ -3,23 +3,23 @@
|
|
3
3
|
active: true
|
4
4
|
trigger: once
|
5
5
|
status: ""
|
6
|
-
stage1:
|
7
|
-
stage2:
|
6
|
+
stage1: ssh.run node:"test_node", cmd:"ruby code.rb", user:"root", sources:["code.rb", "code.sh"]
|
7
|
+
stage2: gsheet.write source:"stage1", target:"test_ssh_1.out"
|
8
8
|
- name: test_ssh_2
|
9
9
|
active: true
|
10
10
|
trigger: "after test_ssh_1"
|
11
11
|
status: ""
|
12
|
-
stage1:
|
13
|
-
stage2:
|
12
|
+
stage1: ssh.run cmd:"sh code2.sh", user:"root", sources:["code2.sh","test_node/var/log/syslog"], params:{file:"syslog"}
|
13
|
+
stage2: gsheet.write source:"stage1", target:"test_ssh_2.out"
|
14
14
|
- name: test_ssh_3
|
15
15
|
active: true
|
16
16
|
trigger: "after test_ssh_2"
|
17
17
|
status: ""
|
18
|
-
stage1:
|
19
|
-
stage2:
|
18
|
+
stage1: ssh.run cmd:"echo '@test_param'", params:{test_param:"test param successful"}
|
19
|
+
stage2: gsheet.write source:"stage1", target:"test_ssh_3.out"
|
20
20
|
- name: test_ssh_4
|
21
21
|
active: true
|
22
22
|
trigger: "after test_ssh_3"
|
23
23
|
status: ""
|
24
|
-
stage1:
|
25
|
-
stage2:
|
24
|
+
stage1: ssh.run node:"test_node", user:root, sources:["git://DeNA/mobilize-ssh/test/code.rb","git://DeNA/mobilize-ssh/test/code.sh"], cmd:"ruby code.rb"
|
25
|
+
stage2: gsheet.write source:stage1, target:"test_ssh_4.out"
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mobilize-ssh
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '1.
|
4
|
+
version: '1.299'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-04-
|
12
|
+
date: 2013-04-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: mobilize-base
|
@@ -119,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
119
119
|
version: '0'
|
120
120
|
segments:
|
121
121
|
- 0
|
122
|
-
hash:
|
122
|
+
hash: 1792150884808390636
|
123
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
124
124
|
none: false
|
125
125
|
requirements:
|
@@ -128,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
128
128
|
version: '0'
|
129
129
|
segments:
|
130
130
|
- 0
|
131
|
-
hash:
|
131
|
+
hash: 1792150884808390636
|
132
132
|
requirements: []
|
133
133
|
rubyforge_project:
|
134
134
|
rubygems_version: 1.8.25
|