more or less decent locking
This commit is contained in:
parent
d55a83664e
commit
8396d7f8cc
2 changed files with 16 additions and 9 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
# $Dwarf: TODO,v 1.15 2003/04/28 14:36:19 ward Exp $
|
# $Dwarf: TODO,v 1.16 2003/05/26 19:35:04 ward Exp $
|
||||||
# $Source$
|
# $Source$
|
||||||
|
|
||||||
[ ] check for multiple servers (ip adresses) for each name and pick
|
[ ] check for multiple servers (ip adresses) for each name and pick
|
||||||
|
|
@ -20,4 +20,3 @@
|
||||||
exceptions. Use buffering for each body, before writing...
|
exceptions. Use buffering for each body, before writing...
|
||||||
[ ] more regression tests
|
[ ] more regression tests
|
||||||
[ ] update documentation
|
[ ] update documentation
|
||||||
[ ] locking so you won't run 2 ripnews processes at the same time
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/local/bin/ruby -w
|
#!/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$
|
# $Source$
|
||||||
|
|
||||||
require 'date'
|
require 'date'
|
||||||
|
|
@ -240,14 +240,22 @@ def lock
|
||||||
group = @config.keys[0]
|
group = @config.keys[0]
|
||||||
if @config[group].has_key?("LOCKFILE")
|
if @config[group].has_key?("LOCKFILE")
|
||||||
if FileTest.exists?(@config[group]["LOCKFILE"])
|
if FileTest.exists?(@config[group]["LOCKFILE"])
|
||||||
# Should also detect stale locks here
|
lock = File.open(@config[group]["LOCKFILE"], "r")
|
||||||
print "Already running, exiting...\n"
|
line = lock.gets
|
||||||
exit
|
|
||||||
else
|
|
||||||
lock = File.new(@config[group]["LOCKFILE"], "w")
|
|
||||||
lock.print "#{Process.pid}\n"
|
|
||||||
lock.close
|
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
|
end
|
||||||
|
lock = File.new(@config[group]["LOCKFILE"], "w")
|
||||||
|
lock.print "#{Process.pid}\n"
|
||||||
|
lock.close
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue