rush 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ Jeweler::Tasks.new do |s|
18
18
  s.files = FileList["[A-Z]*", "{bin,lib,spec}/**/*"]
19
19
  end
20
20
 
21
- Jeweler::RubyforgeTasks.new
21
+ Jeweler::GemcutterTasks.new
22
22
 
23
23
  ######################################################
24
24
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.4
1
+ 0.6.5
@@ -64,15 +64,17 @@ class Rush::Box
64
64
  # box.bash '/etc/init.d/mysql restart', :user => 'root'
65
65
  # box.bash 'rake db:migrate', :user => 'www', :env => { :RAILS_ENV => 'production' }
66
66
  # box.bash 'mongrel_rails start', :background => true
67
+ # box.bash 'rake db:migrate', :user => 'www', :env => { :RAILS_ENV => 'production' }, :reset_environment => true
67
68
  #
68
69
  def bash(command, options={})
69
70
  cmd_with_env = command_with_environment(command, options[:env])
71
+ options[:reset_environment] ||= false
70
72
 
71
73
  if options[:background]
72
- pid = connection.bash(cmd_with_env, options[:user], true)
74
+ pid = connection.bash(cmd_with_env, options[:user], true, options[:reset_environment])
73
75
  processes.find_by_pid(pid)
74
76
  else
75
- connection.bash(cmd_with_env, options[:user], false)
77
+ connection.bash(cmd_with_env, options[:user], false, options[:reset_environment])
76
78
  end
77
79
  end
78
80
 
@@ -307,17 +307,19 @@ class Rush::Connection::Local
307
307
  # if it's dead, great - do nothing
308
308
  end
309
309
 
310
- def bash(command, user=nil, background=false)
311
- return bash_background(command, user) if background
310
+ def bash(command, user=nil, background=false, reset_environment=false)
311
+ return bash_background(command, user, reset_environment) if background
312
312
 
313
313
  require 'session'
314
314
 
315
315
  sh = Session::Bash.new
316
316
 
317
+ shell = reset_environment ? "env -i bash" : "bash"
318
+
317
319
  if user and user != ""
318
- out, err = sh.execute "cd /; sudo -H -u #{user} bash", :stdin => command
320
+ out, err = sh.execute "cd /; sudo -H -u #{user} \"#{shell}\"", :stdin => command
319
321
  else
320
- out, err = sh.execute command
322
+ out, err = sh.execute shell, :stdin => command
321
323
  end
322
324
 
323
325
  retval = sh.status
@@ -328,7 +330,7 @@ class Rush::Connection::Local
328
330
  out
329
331
  end
330
332
 
331
- def bash_background(command, user)
333
+ def bash_background(command, user, reset_environment)
332
334
  pid = fork do
333
335
  inpipe, outpipe = IO.pipe
334
336
 
@@ -338,10 +340,12 @@ class Rush::Connection::Local
338
340
 
339
341
  close_all_descriptors([inpipe.to_i])
340
342
 
343
+ shell = reset_environment ? "env -i bash" : "bash"
344
+
341
345
  if user and user != ''
342
- exec "cd /; sudo -H -u #{user} bash"
346
+ exec "cd /; sudo -H -u #{user} \"#{shell}\""
343
347
  else
344
- exec "bash"
348
+ exec shell
345
349
  end
346
350
  end
347
351
 
@@ -385,7 +389,7 @@ class Rush::Connection::Local
385
389
  when 'processes' then YAML.dump(processes)
386
390
  when 'process_alive' then process_alive(params[:pid]) ? '1' : '0'
387
391
  when 'kill_process' then kill_process(params[:pid].to_i, YAML.load(params[:payload]))
388
- when 'bash' then bash(params[:payload], params[:user], params[:background] == 'true')
392
+ when 'bash' then bash(params[:payload], params[:user], params[:background] == 'true', params[:reset_environment] == 'true')
389
393
  else
390
394
  raise UnknownAction
391
395
  end
@@ -82,8 +82,8 @@ class Rush::Connection::Remote
82
82
  transmit(:action => 'kill_process', :pid => pid, :payload => YAML.dump(options))
83
83
  end
84
84
 
85
- def bash(command, user, background)
86
- transmit(:action => 'bash', :payload => command, :user => user, :background => background)
85
+ def bash(command, user, background, reset_environment)
86
+ transmit(:action => 'bash', :payload => command, :user => user, :background => background, :reset_environment => reset_environment)
87
87
  end
88
88
 
89
89
  # Given a hash of parameters (converted by the method call on the connection
@@ -22,17 +22,17 @@ describe Rush::Box do
22
22
  end
23
23
 
24
24
  it "executes bash commands" do
25
- @box.connection.should_receive(:bash).with('cmd', nil, false).and_return('output')
25
+ @box.connection.should_receive(:bash).with('cmd', nil, false, false).and_return('output')
26
26
  @box.bash('cmd').should == 'output'
27
27
  end
28
28
 
29
29
  it "executes bash commands with an optional user" do
30
- @box.connection.should_receive(:bash).with('cmd', 'user', false)
30
+ @box.connection.should_receive(:bash).with('cmd', 'user', false, false)
31
31
  @box.bash('cmd', :user => 'user')
32
32
  end
33
33
 
34
34
  it "executes bash commands in the background, returning a Rush::Process" do
35
- @box.connection.should_receive(:bash).with('cmd', nil, true).and_return(123)
35
+ @box.connection.should_receive(:bash).with('cmd', nil, true, false).and_return(123)
36
36
  @box.stub!(:processes).and_return([ mock('ps', :pid => 123) ])
37
37
  @box.bash('cmd', :background => true).pid.should == 123
38
38
  end
@@ -100,13 +100,18 @@ describe Rush::Connection::Local do
100
100
  @con.receive(:action => 'kill_process', :pid => '123', :payload => YAML.dump(:wait => 10))
101
101
  end
102
102
 
103
+ it "receive -> bash (reset environment)" do
104
+ @con.should_receive(:bash).with('cmd', 'user', false, true).and_return('output')
105
+ @con.receive(:action => 'bash', :payload => 'cmd', :user => 'user', :background => 'false', :reset_environment => 'true').should == 'output'
106
+ end
107
+
103
108
  it "receive -> bash (foreground)" do
104
- @con.should_receive(:bash).with('cmd', 'user', false).and_return('output')
109
+ @con.should_receive(:bash).with('cmd', 'user', false, false).and_return('output')
105
110
  @con.receive(:action => 'bash', :payload => 'cmd', :user => 'user', :background => 'false').should == 'output'
106
111
  end
107
112
 
108
113
  it "receive -> bash (background)" do
109
- @con.should_receive(:bash).with('cmd', 'user', true).and_return('output')
114
+ @con.should_receive(:bash).with('cmd', 'user', true, false).and_return('output')
110
115
  @con.receive(:action => 'bash', :payload => 'cmd', :user => 'user', :background => 'true').should == 'output'
111
116
  end
112
117
 
@@ -98,8 +98,8 @@ describe Rush::Connection::Local do
98
98
  end
99
99
 
100
100
  it "transmits bash" do
101
- @con.should_receive(:transmit).with(:action => 'bash', :payload => 'cmd', :user => 'user', :background => 'bg').and_return('output')
102
- @con.bash('cmd', 'user', 'bg').should == 'output'
101
+ @con.should_receive(:transmit).with(:action => 'bash', :payload => 'cmd', :user => 'user', :background => 'bg', :reset_environment => false).and_return('output')
102
+ @con.bash('cmd', 'user', 'bg', false).should == 'output'
103
103
  end
104
104
 
105
105
  it "an http result code of 401 raises NotAuthorized" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rush
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Wiggins
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-10 00:00:00 -08:00
12
+ date: 2010-01-20 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency