From b5535d894d1d1689d17319bf386f57c5c700ff5b Mon Sep 17 00:00:00 2001 From: Abhilash Raj Date: Tue, 28 Mar 2017 17:06:15 -0700 Subject: [PATCH] Initial mailman core docker container --- core/Dockerfile | 18 ++++++++++ core/assets/mailman.cfg | 24 +++++++++++++ core/assets/pidproxy.py | 80 +++++++++++++++++++++++++++++++++++++++++ core/assets/run.sh | 11 ++++++ 4 files changed, 133 insertions(+) create mode 100644 core/Dockerfile create mode 100644 core/assets/mailman.cfg create mode 100755 core/assets/pidproxy.py create mode 100755 core/assets/run.sh diff --git a/core/Dockerfile b/core/Dockerfile new file mode 100644 index 0000000..a31604c --- /dev/null +++ b/core/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.5 + +MAINTAINER Abhilash Raj + +# Install the latest master branch of the mailman directly +# from the Gitlab. +RUN pip install git+https://gitlab.com/mailman/mailman.git + +ADD assets/run.sh /opt/run.sh + +# Pidproxy is our sort-of process watcher that sends any +# signal that it receives to the mailman's master process. +ADD assets/pidproxy.py /opt/pidproxy.py + +# Change the working directory. +WORKDIR /opt/mailman + +CMD /opt/run.sh diff --git a/core/assets/mailman.cfg b/core/assets/mailman.cfg new file mode 100644 index 0000000..cd3c952 --- /dev/null +++ b/core/assets/mailman.cfg @@ -0,0 +1,24 @@ +[devmode] +enabled: yes +testing: yes +recipient: you@yourdomain.com + +[mta] +smtp_port: 9025 +lmtp_port: 9024 +incoming: mailman.testing.mta.FakeMTA + +[archiver.mhonarc] +enable: yes + +[archiver.mail_archive] +enable: yes + +[archiver.prototype] +enable: yes + +[runner.retry] +sleep_time: 10s + +[shell] +use_ipython: yes diff --git a/core/assets/pidproxy.py b/core/assets/pidproxy.py new file mode 100755 index 0000000..ddd1b58 --- /dev/null +++ b/core/assets/pidproxy.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python + +"""An executable which proxies for a subprocess; upon a signal, it sends that +signal to the process identified by a pidfile. + +This is a modified version of the pidproxy.py from supervisor's repository, +which can be found at: + +https://github.com/Supervisor/supervisor/blob/master/supervisor/pidproxy.py +""" + +import os +import sys +import signal +import time +from subprocess import run + + +# The sleep time before the watcher checks if the mailman process is still +# living. +SLEEP_TIME = 5 + + +class PidProxy: + pid = None + + def __init__(self, args): + self.setsignals() + try: + self.pidfile, cmdargs = args[1], args[2:] + self.pidfile = os.path.abspath(self.pidfile) + self.args = cmdargs + except (ValueError, IndexError): + self.usage() + sys.exit(1) + + def go(self): + run(self.args) + time.sleep(2) + with open(self.pidfile, 'r') as f: + self.pid = int(f.read().strip()) + while 1: + time.sleep(SLEEP_TIME) + try: + pid, sts = os.waitpid(-2, os.WNOHANG) + except OSError: + pid, sts = None, None + if pid: + break + + def usage(self): + print("pidproxy.py [ ...]") + + def setsignals(self): + signal.signal(signal.SIGTERM, self.passtochild) + signal.signal(signal.SIGHUP, self.passtochild) + signal.signal(signal.SIGINT, self.passtochild) + signal.signal(signal.SIGUSR1, self.passtochild) + signal.signal(signal.SIGUSR2, self.passtochild) + signal.signal(signal.SIGQUIT, self.passtochild) + signal.signal(signal.SIGCHLD, self.reap) + + def reap(self, sig, frame): + # do nothing, we reap our child synchronously + pass + + def passtochild(self, sig, frame): + if self.pid is None: + sys.exit(1) + os.kill(self.pid, sig) + if sig in [signal.SIGTERM, signal.SIGINT, signal.SIGQUIT]: + sys.exit(0) + + +def main(): + pp = PidProxy(sys.argv) + pp.go() + +if __name__ == '__main__': + main() diff --git a/core/assets/run.sh b/core/assets/run.sh new file mode 100755 index 0000000..65f7363 --- /dev/null +++ b/core/assets/run.sh @@ -0,0 +1,11 @@ +#! /bin/bash + +# Check if the configuration file is present. +if [[ ! -e /opt/mailman/mailman.cfg ]]; then + echo "/opt/mailman/mailman.cfg configuration file not found..." + exit 1 +fi + +# Run mailman using the pidproxy command which spawns off mailman +# and forwards any signal you send it to the master runner in mailman. +/opt/pidproxy.py /opt/mailman/var/master.pid mailman -C /opt/mailman/mailman.cfg start