dataflake.org

Home Documentation Software Old Stuff Bug Reporting

PID file not removed when daemon exit abruptly (Resolved)

Request MaildropHost -- bug report -- by Johnny Souza
Posted on Oct 18, 2007 11:45 am
Subscribe

Enter your email address to receive mail on every change to this issue.

Entries (Latest first)


  Resolve by Jens Vagelpohl on Oct 18, 2007 2:08 pm
  Thanks for the patch, it's been committed:

http://svn.dataflake.org/?view=rev&revision=1434

 

  Initial Request by Johnny Souza on Oct 18, 2007 11:45 am
  Hi,

When the daemon (maildrop.py) receive a SIGTERM signal or occour an error the pidfile is not removed.
It make a error in the next maildropctl start.
If uses cron to start daemon again, the daemon is not started because the pidfile exists.

ERROR MESSAGE:
Error: maildrop daemon already started.

SOLUTION:

Register a function that remove the pidfile in atexit and as handler os SIGTERM. Diff bellow.


Index: maildrop.py
===================================================================
--- maildrop.py (revisao 1433)
+++ maildrop.py (copia de trabalho)
@@ -17,6 +17,8 @@
import time
import rfc822
import imp
+import atexit
+import signal

FATAL_ERROR_CODES = ('500', '501', '502', '503', '504', '550', '551', '553')
MaildropError = 'Maildrop Error'
@@ -214,6 +216,17 @@
pid_file.close()


+
+def exit_function(pidfile_path):
+ # Remove the daemon pid file
+ try: os.unlink(pidfile_path)
+ except: pass
+
+
+def handle_sigterm(signum, frame):
+ sys.exit(0)
+
+
if __name__ == "__main__":
try:
if len(sys.argv) < 2:
@@ -340,6 +353,8 @@
print >>sys.stderr, "fork #2 failed: %d (%s)" % (
e.errno, e.strerror)
sys.exit(1)
+ atexit.register(exit_function,MAILDROP_PID_FILE)
+ signal.signal(signal.SIGTERM,handle_sigterm)
else:
print '***** Starting in DEBUG mode *****'
print '***** All log messages are shown on the console *****'