rush 0.5.1 → 0.6

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -31,7 +31,7 @@ require 'rake/rdoctask'
31
31
  require 'fileutils'
32
32
  include FileUtils
33
33
 
34
- version = "0.5.1"
34
+ version = "0.6"
35
35
  name = "rush"
36
36
 
37
37
  spec = Gem::Specification.new do |s|
@@ -62,17 +62,17 @@ class Rush::Entry
62
62
  false
63
63
  end
64
64
 
65
- # Timestamp of entry creation.
66
- def created_at
65
+ # Timestamp of most recent change to the entry (permissions, contents, etc).
66
+ def changed_at
67
67
  stat[:ctime]
68
68
  end
69
69
 
70
- # Timestamp that entry was last modified on.
70
+ # Timestamp of last modification of the contents.
71
71
  def last_modified
72
72
  stat[:mtime]
73
73
  end
74
74
 
75
- # Timestamp that entry was last accessed on.
75
+ # Timestamp that entry was last accessed (read from or written to).
76
76
  def last_accessed
77
77
  stat[:atime]
78
78
  end
@@ -1,5 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'yaml'
3
+ require 'timeout'
3
4
 
4
5
  # Rush::Box uses a connection object to execute all rush commands. If the box
5
6
  # is local, Rush::Connection::Local is created. The local connection is the
@@ -280,14 +281,24 @@ class Rush::Connection::Local
280
281
  end
281
282
 
282
283
  # Terminate a process, by pid.
283
- def kill_process(pid)
284
- ::Process.kill('TERM', pid)
285
-
286
- # keep trying until it's dead (technique borrowed from god)
287
- 5.times do
288
- return if !process_alive(pid)
289
- sleep 0.5
290
- ::Process.kill('TERM', pid) rescue nil
284
+ def kill_process(pid, options={})
285
+ # time to wait before terminating the process, in seconds
286
+ wait = options[:wait] || 3
287
+
288
+ if wait > 0
289
+ ::Process.kill('TERM', pid)
290
+
291
+ # keep trying until it's dead (technique borrowed from god)
292
+ begin
293
+ Timeout.timeout(wait) do
294
+ loop do
295
+ return if !process_alive(pid)
296
+ sleep 0.5
297
+ ::Process.kill('TERM', pid) rescue nil
298
+ end
299
+ end
300
+ rescue Timeout::Error
301
+ end
291
302
  end
292
303
 
293
304
  ::Process.kill('KILL', pid) rescue nil
@@ -373,7 +384,7 @@ class Rush::Connection::Local
373
384
  when 'size' then size(params[:full_path])
374
385
  when 'processes' then YAML.dump(processes)
375
386
  when 'process_alive' then process_alive(params[:pid]) ? '1' : '0'
376
- when 'kill_process' then kill_process(params[:pid].to_i)
387
+ when 'kill_process' then kill_process(params[:pid].to_i, YAML.load(params[:payload]))
377
388
  when 'bash' then bash(params[:payload], params[:user], params[:background] == 'true')
378
389
  else
379
390
  raise UnknownAction
@@ -22,7 +22,11 @@ class Rush::Process
22
22
  end
23
23
 
24
24
  def inspect # :nodoc:
25
- "#{box} process #{@pid}: #{@cmdline}"
25
+ if box.to_s != 'localhost'
26
+ "#{box} #{@pid}: #{@cmdline}"
27
+ else
28
+ "#{@pid}: #{@cmdline}"
29
+ end
26
30
  end
27
31
 
28
32
  # Returns the Rush::Process parent of this process.
@@ -41,8 +45,8 @@ class Rush::Process
41
45
  end
42
46
 
43
47
  # Terminate the process.
44
- def kill
45
- box.connection.kill_process(pid)
48
+ def kill(options={})
49
+ box.connection.kill_process(pid, options)
46
50
  end
47
51
 
48
52
  def ==(other) # :nodoc:
@@ -32,8 +32,8 @@ class Rush::ProcessSet
32
32
  end
33
33
 
34
34
  # Kill all processes in the set.
35
- def kill
36
- processes.each { |p| p.kill }
35
+ def kill(options={})
36
+ processes.each { |p| p.kill(options) }
37
37
  end
38
38
 
39
39
  # Check status of all processes in the set, returns an array of booleans.
@@ -78,8 +78,8 @@ class Rush::Connection::Remote
78
78
  transmit(:action => 'process_alive', :pid => pid)
79
79
  end
80
80
 
81
- def kill_process(pid)
82
- transmit(:action => 'kill_process', :pid => pid)
81
+ def kill_process(pid, options={})
82
+ transmit(:action => 'kill_process', :pid => pid, :payload => YAML.dump(options))
83
83
  end
84
84
 
85
85
  def bash(command, user, background)
@@ -30,8 +30,8 @@ describe Rush::Entry do
30
30
  Rush::Entry.new('/1/2/../3').full_path.should == '/1/3'
31
31
  end
32
32
 
33
- it "knows its created_at time" do
34
- @entry.created_at.should == File.stat(@filename).ctime
33
+ it "knows its changed_at time" do
34
+ @entry.changed_at.should == File.stat(@filename).ctime
35
35
  end
36
36
 
37
37
  it "knows its last_modified time" do
@@ -96,8 +96,8 @@ describe Rush::Connection::Local do
96
96
  end
97
97
 
98
98
  it "receive -> kill_process" do
99
- @con.should_receive(:kill_process).with(123).and_return(true)
100
- @con.receive(:action => 'kill_process', :pid => '123')
99
+ @con.should_receive(:kill_process).with(123, :wait => 10).and_return(true)
100
+ @con.receive(:action => 'kill_process', :pid => '123', :payload => YAML.dump(:wait => 10))
101
101
  end
102
102
 
103
103
  it "receive -> bash (foreground)" do
@@ -288,11 +288,25 @@ EOPS
288
288
  @con.process_alive(99999).should be_false
289
289
  end
290
290
 
291
- it "kills a process by pid" do
292
- ::Process.should_receive(:kill).at_least(:once)
291
+ it "kills a process by pid sending a TERM" do
292
+ @con.stub!(:process_alive).and_return(false)
293
+ ::Process.should_receive(:kill).with('TERM', 123).once
293
294
  @con.kill_process(123)
294
295
  end
295
296
 
297
+ it "kills a process by pid sending a KILL signal if TERM doesn't work" do
298
+ @con.stub!(:process_alive).and_return(true)
299
+ ::Process.should_receive(:kill).with('TERM', 123).at_least(:twice)
300
+ ::Process.should_receive(:kill).with('KILL', 123)
301
+ @con.kill_process(123)
302
+ end
303
+
304
+ it "kills a process by pid without sending TERM if :wait is zero" do
305
+ ::Process.should_not_receive(:kill).with('TERM', 123)
306
+ ::Process.should_receive(:kill).with('KILL', 123)
307
+ @con.kill_process(123, :wait => 0)
308
+ end
309
+
296
310
  it "does not raise an error if the process is already dead" do
297
311
  ::Process.should_receive(:kill).and_raise(Errno::ESRCH)
298
312
  lambda { @con.kill_process(123) }.should_not raise_error
@@ -93,8 +93,8 @@ describe Rush::Connection::Local do
93
93
  end
94
94
 
95
95
  it "transmits kill_process" do
96
- @con.should_receive(:transmit).with(:action => 'kill_process', :pid => 123)
97
- @con.kill_process(123)
96
+ @con.should_receive(:transmit).with(:action => 'kill_process', :pid => 123, :payload => YAML.dump(:wait => 10))
97
+ @con.kill_process(123, :wait => 10)
98
98
  end
99
99
 
100
100
  it "transmits bash" 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.5.1
4
+ version: "0.6"
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-03-24 00:00:00 -07:00
12
+ date: 2009-06-16 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -45,51 +45,51 @@ files:
45
45
  - Rakefile
46
46
  - bin/rush
47
47
  - bin/rushd
48
- - lib/rush.rb
49
48
  - lib/rush
50
- - lib/rush/embeddable_shell.rb
49
+ - lib/rush/access.rb
50
+ - lib/rush/array_ext.rb
51
+ - lib/rush/box.rb
52
+ - lib/rush/commands.rb
51
53
  - lib/rush/config.rb
52
- - lib/rush/head_tail.rb
53
- - lib/rush/search_results.rb
54
+ - lib/rush/dir.rb
55
+ - lib/rush/embeddable_shell.rb
54
56
  - lib/rush/entry.rb
55
- - lib/rush/find_by.rb
57
+ - lib/rush/exceptions.rb
56
58
  - lib/rush/file.rb
59
+ - lib/rush/find_by.rb
60
+ - lib/rush/fixnum_ext.rb
61
+ - lib/rush/head_tail.rb
57
62
  - lib/rush/local.rb
58
- - lib/rush/ssh_tunnel.rb
59
- - lib/rush/shell.rb
60
- - lib/rush/server.rb
63
+ - lib/rush/process.rb
61
64
  - lib/rush/process_set.rb
62
- - lib/rush/array_ext.rb
63
65
  - lib/rush/remote.rb
64
- - lib/rush/fixnum_ext.rb
65
- - lib/rush/commands.rb
66
- - lib/rush/process.rb
67
- - lib/rush/dir.rb
66
+ - lib/rush/search_results.rb
67
+ - lib/rush/server.rb
68
+ - lib/rush/shell.rb
69
+ - lib/rush/ssh_tunnel.rb
68
70
  - lib/rush/string_ext.rb
69
- - lib/rush/box.rb
70
- - lib/rush/exceptions.rb
71
- - lib/rush/access.rb
72
- - spec/remote_spec.rb
73
- - spec/rush_spec.rb
74
- - spec/base.rb
75
- - spec/ssh_tunnel_spec.rb
76
- - spec/local_spec.rb
77
- - spec/embeddable_shell_spec.rb
71
+ - lib/rush.rb
78
72
  - spec/access_spec.rb
79
- - spec/file_spec.rb
80
- - spec/string_ext_spec.rb
81
73
  - spec/array_ext_spec.rb
74
+ - spec/base.rb
75
+ - spec/box_spec.rb
82
76
  - spec/commands_spec.rb
83
77
  - spec/config_spec.rb
84
- - spec/fixnum_ext_spec.rb
85
- - spec/search_results_spec.rb
86
- - spec/process_spec.rb
87
- - spec/shell_spec.rb
88
78
  - spec/dir_spec.rb
79
+ - spec/embeddable_shell_spec.rb
89
80
  - spec/entry_spec.rb
81
+ - spec/file_spec.rb
90
82
  - spec/find_by_spec.rb
91
- - spec/box_spec.rb
83
+ - spec/fixnum_ext_spec.rb
84
+ - spec/local_spec.rb
92
85
  - spec/process_set_spec.rb
86
+ - spec/process_spec.rb
87
+ - spec/remote_spec.rb
88
+ - spec/rush_spec.rb
89
+ - spec/search_results_spec.rb
90
+ - spec/shell_spec.rb
91
+ - spec/ssh_tunnel_spec.rb
92
+ - spec/string_ext_spec.rb
93
93
  has_rdoc: true
94
94
  homepage: http://rush.heroku.com/
95
95
  post_install_message: