[sylvain] r51089 - in buildout/infrae.maildrophost/trunk: . docs infrae/maildrophost
[email protected] Mon, 7 Oct 2013 13:51:02 +0200 (CEST)
| Newsgroups | gmane.comp.web.zope.silva.cvs |
|---|---|
| Message-ID | <[email protected]> |
Author: sylvain
Date: Mon Oct 7 13:51:02 2013
New Revision: 51089
Modified:
buildout/infrae.maildrophost/trunk/README.txt
buildout/infrae.maildrophost/trunk/docs/HISTORY.txt
buildout/infrae.maildrophost/trunk/infrae/maildrophost/ctl.py
buildout/infrae.maildrophost/trunk/setup.py
Log:
Apply patch provided by Maurits van Rees. Prepare to tag 2.2.
Modified: buildout/infrae.maildrophost/trunk/README.txt
==============================================================================
--- buildout/infrae.maildrophost/trunk/README.txt (original)
+++ buildout/infrae.maildrophost/trunk/README.txt Mon Oct 7 13:51:02 2013
@@ -29,7 +29,7 @@
Products.MaildropHost
zope-conf-additional +=
<product-config maildrophost>
- config-path-application ${maildrophost:configuration}
+ config-path-application ${maildrophost:maildrophost.cfg}
</product-config>
@@ -88,6 +88,48 @@
Must be an interger or float which say how much time the daemon
should wait between sending two mails to the mail server.
+``supervised_daemon``
+ If 1, the internal maildrop script will remain running in the
+ foreground. This is mostly useful when you start the main
+ maildrophost script itself on the foreground with ``bin/maildrophost
+ fg``. See the `Configuration for supervisor`_ section.
+
+``maildrophost.cfg``
+ Specify an alternative path for storing the generated
+ ``maildrophost.cfg`` file. Note that this file gets rewritten each
+ time you run buildout. The default value is
+ ``${buildout:directory}/maildrophost.cfg``.
+
+
+Configuration for supervisor
+============================
+
+Buildout generates a ``bin/maildrophost`` script (if you use
+``maildrophost`` as the name of the buildout section). When calling
+``bin/maildrophost start`` this script does some checks and basically
+calls ``python maildrop.py maildrophost.cfg`` and quits, without
+waiting to for the ``maildrop.py`` script to exit properly. The
+``maildrop.py`` script creates a fork of itself and exits.
+
+This is not helpful when you want to use maildrophost in combination
+with `supervisor <http://supervisord.org>`_. If you want to do that
+you should enable the ``supervised_daemon`` option and let supervisor
+start the maildrophost script on the foreground. Sample config would
+be this::
+
+ [maildrophost]
+ recipe = infrae.maildrophost
+ smtp_host = localhost
+ smtp_port = 25
+ supervised_daemon = 1
+
+ [supervisor]
+ recipe = collective.recipe.supervisor
+ ...
+ programs =
+ ...
+ 40 maildrop ${buildout:directory}/bin/maildrophost [fg] true
+
Latest version
==============
Modified: buildout/infrae.maildrophost/trunk/docs/HISTORY.txt
==============================================================================
--- buildout/infrae.maildrophost/trunk/docs/HISTORY.txt (original)
+++ buildout/infrae.maildrophost/trunk/docs/HISTORY.txt Mon Oct 7 13:51:02 2013
@@ -2,10 +2,14 @@
History
=======
-2.2 (unreleased)
+2.2 (2013-10-07)
----------------
-* ...
+* Add ``fg`` command line option to start the script on the
+ foreground. For best results, combine this with enabling the
+ ``supervised_daemon`` option. Patch provided by Maurits van Rees
+ from Zest Software.
+
2.1 (2013-08-19)
----------------
Modified: buildout/infrae.maildrophost/trunk/infrae/maildrophost/ctl.py
==============================================================================
--- buildout/infrae.maildrophost/trunk/infrae/maildrophost/ctl.py (original)
+++ buildout/infrae.maildrophost/trunk/infrae/maildrophost/ctl.py Mon Oct 7 13:51:02 2013
@@ -3,10 +3,17 @@
# See also LICENSE.txt
# $Id$
+import atexit
import os
+import signal
+import subprocess
import sys
import psutil
+from maildrop import write_pid, exit_function, handle_sigterm
+from stringparse import parse_assignments
+from stringparse import ParserSyntaxError
+
SCRIPT = os.path.join(os.path.dirname(__file__), 'maildrop.py')
@@ -62,6 +69,48 @@
sys.exit(1)
+def maildrop_fg(configuration, pidfile):
+ """Start maildrophost in the foreground.
+
+ If you use this *and* you set DEBUG or SUPERVISED_DAEMON to a true
+ value, it should be a fine configuration to use with supervisor.
+ """
+ if not os.path.isfile(SCRIPT):
+ print>>sys.stderr, 'Could not find MaildropHost server script.'
+ sys.exit(1)
+
+ if not os.path.isfile(configuration):
+ print>>sys.stderr, 'Could not find MaildropHost configuration.'
+ sys.exit(1)
+
+ ## if there's no running process then start one
+ pid = maildrop_pid(pidfile)
+ if not is_process_running(pid):
+ print>>sys.stdout, 'Starting MaildropHost...'
+ # We will not fork, so write the pid of the current script in
+ # the pidfile.
+
+ try:
+ config = dict(parse_assignments(open(configuration).read()))
+ except ParserSyntaxError:
+ print>>sys.stderr, 'Cannot load config from "%s"' % configuration
+ sys.exit(1)
+ if not config['SUPERVISED_DAEMON']:
+ print>>sys.stderr, (
+ 'When running in foreground mode SUPERVISED_DAEMON '
+ 'must be turned on in the configuration file at "%s"' %
+ configuration)
+ sys.exit(1)
+
+ write_pid(pidfile, os.getpid())
+ atexit.register(exit_function, pidfile)
+ signal.signal(signal.SIGTERM, handle_sigterm)
+ subprocess.call([sys.executable, SCRIPT, configuration])
+ else:
+ print>>sys.stderr, 'MaildropHost is already running with PID %s.' % pid
+ sys.exit(1)
+
+
def maildrop_stop(configuration, pidfile):
"""Stop maildrophost.
"""
@@ -99,7 +148,7 @@
def usage():
- print "usage: %s [start|stop|restart|status]" % sys.argv[0]
+ print "usage: %s [start|fg|stop|restart|status]" % sys.argv[0]
sys.exit(-255)
@@ -109,6 +158,8 @@
action = sys.argv[1]
if action == 'start':
return maildrop_start(**options)
+ elif action == 'fg':
+ return maildrop_fg(**options)
elif action == 'stop':
return maildrop_stop(**options)
elif action == 'restart':
Modified: buildout/infrae.maildrophost/trunk/setup.py
==============================================================================
--- buildout/infrae.maildrophost/trunk/setup.py (original)
+++ buildout/infrae.maildrophost/trunk/setup.py Mon Oct 7 13:51:02 2013
@@ -6,7 +6,7 @@
from setuptools import setup, find_packages
name = "infrae.maildrophost"
-version = "2.2dev"
+version = "2.2"
setup(name = name,
version = version,