cleaner lock file checking, don't use 'ps'

This commit is contained in:
Ward Wouts 2005-02-01 09:33:56 +00:00
parent 42347d5f66
commit 1a1ed818f4

View file

@ -1,6 +1,6 @@
#!/usr/local/bin/ruby -w
# $Dwarf: ripnews.rb,v 1.90 2005/01/30 14:47:00 ward Exp $
# $Dwarf: ripnews.rb,v 1.91 2005/01/30 18:43:17 ward Exp $
# $Source$
#
@ -315,15 +315,15 @@ def lock
if @config[group].has_key?("LOCKFILE")
if FileTest.exists?(@config[group]["LOCKFILE"])
lock = File.open(@config[group]["LOCKFILE"], "r")
line = lock.gets
pid = lock.gets
lock.close
if line
line.chomp!
psauxw = `ps auxw`
if /^\S+\s+#{line}\s+/.match(psauxw)
if pid
pid.chomp!
begin
Process.kill(0, pid)
print "Already running, exiting...\n"
exit
else
rescue Errno::ESRCH
print "Stale lock found... removing...\n"
File.unlink(@config[group]["LOCKFILE"])
end