more or less decent locking
This commit is contained in:
parent
d55a83664e
commit
8396d7f8cc
2 changed files with 16 additions and 9 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/local/bin/ruby -w
|
||||
|
||||
# $Dwarf: ripnews.rb,v 1.61 2003/05/24 18:33:46 ward Exp $
|
||||
# $Dwarf: ripnews.rb,v 1.62 2003/05/26 19:35:04 ward Exp $
|
||||
# $Source$
|
||||
|
||||
require 'date'
|
||||
|
|
@ -240,14 +240,22 @@ def lock
|
|||
group = @config.keys[0]
|
||||
if @config[group].has_key?("LOCKFILE")
|
||||
if FileTest.exists?(@config[group]["LOCKFILE"])
|
||||
# Should also detect stale locks here
|
||||
print "Already running, exiting...\n"
|
||||
exit
|
||||
else
|
||||
lock = File.new(@config[group]["LOCKFILE"], "w")
|
||||
lock.print "#{Process.pid}\n"
|
||||
lock = File.open(@config[group]["LOCKFILE"], "r")
|
||||
line = lock.gets
|
||||
lock.close
|
||||
line.chomp!
|
||||
psauxw = `ps -auxw`
|
||||
if /^\S+\s+#{line}\s+/.match(psauxw)
|
||||
print "Already running, exiting...\n"
|
||||
exit
|
||||
else
|
||||
print "Stale lock found... removing...\n"
|
||||
File.unlink(@config[group]["LOCKFILE"])
|
||||
end
|
||||
end
|
||||
lock = File.new(@config[group]["LOCKFILE"], "w")
|
||||
lock.print "#{Process.pid}\n"
|
||||
lock.close
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue