Skip to content

Commit b3dd67e

Browse files
committed
User supervisord to handle the two processes
The docker container consists for two processes: xl2tpd and ipsec. Previously, the former was launched in the background and the latter was kept in the foreground. This has two issues: 1. You can't gracefully stop the docker container anymore because none of the two processes receive the terminate signal from docker. 2. If xl2tpd fails in the background, this goes unnoticed and the docker-container does not stop. This commit replaces this behaviour: Supervisord is used to control the two processes. If one of them fail, the whole docker container will fail. Also the stdout and stderr is collected and aggregated and can therefor be viewed in the docker logs.
1 parent eaf1f55 commit b3dd67e

File tree

4 files changed

+61
-4
lines changed

4 files changed

+61
-4
lines changed

Dockerfile

+6-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ RUN apt-get update && apt-get install -y \
66
libgmp-dev \
77
iptables \
88
xl2tpd \
9-
module-init-tools
9+
module-init-tools \
10+
supervisor
1011

1112
ENV STRONGSWAN_VERSION 5.5.0
1213
ENV GPG_KEY 948F158A4E76A27BF3D07532DF42C170B34DBA77
@@ -45,6 +46,10 @@ ADD strongswan.conf /etc/strongswan.conf
4546
ADD xl2tpd.conf /etc/xl2tpd/xl2tpd.conf
4647
ADD options.xl2tpd /etc/ppp/options.xl2tpd
4748

49+
# Supervisor config
50+
ADD supervisord.conf supervisord.conf
51+
ADD kill_supervisor.py /usr/bin/kill_supervisor.py
52+
4853
ADD run.sh /run.sh
4954
ADD vpn_adduser /usr/local/bin/vpn_adduser
5055
ADD vpn_deluser /usr/local/bin/vpn_deluser

kill_supervisor.py

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python
2+
import sys
3+
import os
4+
import signal
5+
6+
def write_stdout(s):
7+
sys.stdout.write(s)
8+
sys.stdout.flush()
9+
10+
def write_stderr(s):
11+
sys.stderr.write(s)
12+
sys.stderr.flush()
13+
14+
def main():
15+
while 1:
16+
write_stdout('READY\n')
17+
line = sys.stdin.readline()
18+
write_stdout('This line kills supervisor: ' + line);
19+
try:
20+
pidfile = open('/var/run/supervisord.pid','r')
21+
pid = int(pidfile.readline());
22+
os.kill(pid, signal.SIGQUIT)
23+
except Exception as e:
24+
write_stdout('Could not kill supervisor: ' + e.strerror + '\n')
25+
write_stdout('RESULT 2\nOK')
26+
27+
if __name__ == '__main__':
28+
main()

run.sh

+1-3
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,6 @@ if [ -f "/etc/ipsec.d/xl2tpd.conf" ]; then
7777
cp -f /etc/ipsec.d/xl2tpd.conf /etc/xl2tpd/xl2tpd.conf
7878
fi
7979

80-
echo "Starting XL2TPD process..."
8180
mkdir -p /var/run/xl2tpd
82-
/usr/sbin/xl2tpd -c /etc/xl2tpd/xl2tpd.conf
8381

84-
ipsec start --nofork\
82+
exec /usr/bin/supervisord -c /supervisord.conf

supervisord.conf

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
[supervisord]
2+
nodaemon=true
3+
4+
[program:xl2tpd]
5+
command=/usr/sbin/xl2tpd -c /etc/xl2tpd/xl2tpd.conf -D
6+
redirect_stderr=true
7+
numprocs=1
8+
stdout_logfile=/dev/fd/1
9+
stdout_logfile_maxbytes=0
10+
11+
[program:ipsec]
12+
command=ipsec start --nofork
13+
redirect_stderr=true
14+
numprocs=1
15+
stdout_logfile=/dev/fd/1
16+
stdout_logfile_maxbytes=0
17+
18+
[eventlistener:ipsec_exit]
19+
command=/usr/bin/kill_supervisor.py
20+
process_name=ipsec
21+
events=PROCESS_STATE_FATAL
22+
23+
[eventlistener:xl2tpd_exit]
24+
command=/usr/bin/kill_supervisor.py
25+
process_name=xl2tpd
26+
events=PROCESS_STATE_FATAL

0 commit comments

Comments
 (0)