![](https://secure.gravatar.com/avatar/3c9d7eb4973e9546c8c37e370a28a05a.jpg?s=120&d=mm&r=g)
On Sat, 26 Sep 1998, Scott wrote:
I personally like the idea of locking the files more than I like the idea of a daemon delivering queued mail because there will always be the worry that something accidentally kills the daemon process while no admin is around.
This is why I have the daemon check to see if an instance of
itself is already running before starting. If it's already running it dosen't start another copy of itself. That way you just run the daemon program from cron periodicaly and it automatically restarts itself if it gets killed. (I haven't had to worry about it since I installed it a month ago. )
I'm including the daemon version of run_queue attatched to this
message. (to use it you just eliminate the delivery attempts (i.e. any calls to OutgoingQueue.processQueue) elsewhere in the mailman code (my own mods to do this are a bit of a hack. If I have time to fix them up to be presentable I'll post a diff)
-The Dragon De Monsyne
#! /usr/bin/env python # # Copyright (C) 1998 by the Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or # modify it under the terms of the GNU General Public License # as published by the Free Software Foundation; either version 2 # of the License, or (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
import sys,os,stat,string,time import paths from Mailman import OutgoingQueue from Mailman import mm_cfg
PIDFILE=os.path.join(mm_cfg.DATA_DIR,"q.running") STALL_TIME = (60*15) SLEEP_TIME = 15
def CheckLock():
"""Makes sure only one of these runs at a time."""
pid=None
try:
pid=string.atoi(string.strip(open(PIDFILE,'r').read()))
except (IOError,ValueError):
pass
if pid:
#let's see if it's really out there. -ddm
try:
os.kill(pid,0)
age = time.time() - os.stat(PIDFILE)[stat.ST_MTIME]
if age > STALL_TIME:
#it's hanging... Zap it. -ddm
os.kill(pid,9)
else:
#it's really running.. -ddm
return 0
except os.error:
# Nope it aint. -ddm
pass
return 1
def TouchLock():
"tweak the pid file"
open(PIDFILE,'w').write("%i" % os.getpid())
#def Do_DeQ(): # print "foo" # #OutgoingQueue.processQueue()
def main(): if not CheckLock(): # print "already running" sys.exit()
TouchLock()
while 1:
q=OutgoingQueue.processQueue()
if not q:
time.sleep(SLEEP_TIME)
TouchLock()
if __name__ == '__main__': main()