diff --git a/trunk/ripnews/TODO b/trunk/ripnews/TODO index 7541e50..f5f09d2 100644 --- a/trunk/ripnews/TODO +++ b/trunk/ripnews/TODO @@ -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$ [ ] check for multiple servers (ip adresses) for each name and pick @@ -20,4 +20,3 @@ exceptions. Use buffering for each body, before writing... [ ] more regression tests [ ] update documentation -[ ] locking so you won't run 2 ripnews processes at the same time diff --git a/trunk/ripnews/ripnews.rb b/trunk/ripnews/ripnews.rb index bac1977..07814cb 100755 --- a/trunk/ripnews/ripnews.rb +++ b/trunk/ripnews/ripnews.rb @@ -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