119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/logical-construct/target/flight-deck.rb', line 119
def action(args)
require 'pathname'
Pathname.new(lockdir.absolute_path).mkpath
File::open(lockfile.absolute_path, File::CREAT|File::EXCL|File::WRONLY, 0600) do |file|
file.write(Process.pid)
end
at_exit{ File::unlink(lockfile.absolute_path) }
rescue Errno::EEXIST
pid = File::open(lockfile.absolute_path, File::RDONLY) do |file|
file.read.to_i
end
begin
Process.kill(0, pid)
puts "Another process (pid: #{pid}) already owns #{lockfile.absolute_path}"
puts "Exiting"
exit(1)
rescue Errno::ESRCH, RangeError
File::unlink(lockfile.absolute_path)
end
retry end
|