Initial mailman core docker container
This commit is contained in:
18
core/Dockerfile
Normal file
18
core/Dockerfile
Normal file
@@ -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
|
||||||
24
core/assets/mailman.cfg
Normal file
24
core/assets/mailman.cfg
Normal file
@@ -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
|
||||||
80
core/assets/pidproxy.py
Executable file
80
core/assets/pidproxy.py
Executable file
@@ -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 <pidfile name> <command> [<cmdarg1> ...]")
|
||||||
|
|
||||||
|
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()
|
||||||
11
core/assets/run.sh
Executable file
11
core/assets/run.sh
Executable file
@@ -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
|
||||||
Reference in New Issue
Block a user