24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/sup/interactive_lock.rb', line 24
def lock_interactively stream=$stderr
begin
Index.lock
rescue Index::LockError => e
stream.puts "Error: the index is locked by another process! User '\#{e.user}' on\nhost '\#{e.host}' is running \#{e.pname} with pid \#{e.pid}.\nThe process was alive as of at least \#{time_ago_in_words e.mtime} ago.\n\n"
stream.print "Should I ask that process to kill itself (y/n)? "
stream.flush
success = if $stdin.gets =~ /^\s*y(es)?\s*$/i
stream.puts "Ok, trying to kill process..."
begin
Process.kill "TERM", e.pid.to_i
sleep DELAY
rescue Errno::ESRCH
stream.puts "Hm, I couldn't kill it."
end
stream.puts "Let's try that again."
begin
Index.lock
rescue Index::LockError => e
stream.puts "I couldn't lock the index. The lockfile might just be stale."
stream.print "Should I just remove it and continue? (y/n) "
stream.flush
if $stdin.gets =~ /^\s*y(es)?\s*$/i
FileUtils.rm e.path
stream.puts "Let's try that one more time."
begin
Index.lock
true
rescue Index::LockError => e
end
end
end
end
stream.puts "Sorry, couldn't unlock the index." unless success
success
end
end
|