1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
=============================
Starting and stopping Mailman
=============================
The Mailman daemon processes can be started and stopped from the command
line.
Set up
======
All we care about is the master process; normally it starts a bunch of
qrunners, but we don't care about any of them, so write a test configuration
file for the master that disables all the qrunners.
>>> import shutil
>>> from os.path import dirname, join
>>> config_file = join(dirname(config.filename), 'no-qrunners.cfg')
>>> shutil.copyfile(config.filename, config_file)
>>> with open(config_file, 'a') as fp:
... print >> fp, """\
... [qrunner.archive]
... start: no
... [qrunner.bounces]
... start: no
... [qrunner.command]
... start: no
... [qrunner.in]
... start: no
... [qrunner.lmtp]
... start: no
... [qrunner.news]
... start: no
... [qrunner.out]
... start: no
... [qrunner.pipeline]
... start: no
... [qrunner.rest]
... start: no
... [qrunner.retry]
... start: no
... [qrunner.virgin]
... start: no
... [qrunner.digest]
... start: no
... """
Starting
========
>>> from mailman.commands.cli_control import Start
>>> start = Start()
>>> class FakeArgs:
... force = False
... run_as_user = True
... quiet = False
... config = config_file
>>> args = FakeArgs()
Starting the daemons prints a useful message and starts the master qrunner
watcher process in the background.
>>> start.process(args)
Starting Mailman's master queue runner
>>> import errno, os, time
>>> from datetime import timedelta, datetime
>>> def find_master():
... until = timedelta(seconds=10) + datetime.now()
... while datetime.now() < until:
... time.sleep(0.1)
... try:
... with open(config.PID_FILE) as fp:
... pid = int(fp.read().strip())
... os.kill(pid, 0)
... except IOError as error:
... if error.errno != errno.ENOENT:
... raise
... except ValueError:
... pass
... except OSError as error:
... if error.errno != errno.ESRCH:
... raise
... else:
... print 'Master process found'
... return pid
... else:
... raise AssertionError('No master process')
The process exists, and its pid is available in a run time file.
>>> pid = find_master()
Master process found
Stopping
========
You can also stop the master watcher process from the command line, which
stops all the child processes too.
>>> from mailman.commands.cli_control import Stop
>>> stop = Stop()
>>> stop.process(args)
Shutting down Mailman's master queue runner
>>> def bury_master():
... until = timedelta(seconds=10) + datetime.now()
... while datetime.now() < until:
... time.sleep(0.1)
... try:
... import sys
... os.kill(pid, 0)
... os.waitpid(pid, os.WNOHANG)
... except OSError as error:
... if error.errno == errno.ESRCH:
... # The process has exited.
... print 'Master process went bye bye'
... return
... else:
... raise
... else:
... raise AssertionError('Master process lingered')
>>> bury_master()
Master process went bye bye
XXX We need tests for restart (SIGUSR1) and reopen (SIGHUP).
|