Permalink
Browse files

Fix restart docker containers with mutiple services (supervisord)

  • Loading branch information...
glegoux committed Sep 22, 2017
1 parent cd4866d commit 1ea4f2440a298788ec10afd446ef4daee011a7e5
View
@@ -7,7 +7,7 @@ SCRIPT = "./script"
.PHONY: usage
usage:
@echo "targets include: usage gen-conf pre-build build install test stop start clean"
@echo "targets include: usage gen-conf pre-build build install test stop start status restart clean"
.PHONY: gen-conf
gen-conf:
@@ -48,6 +48,13 @@ stop:
start:
@$(SCRIPT)/start.sh
.PHONY: status
status:
@$(SCRIPT)/status.sh
.PHONY: restart
restart: stop start
.PHONY: clean
clean: stop
@$(SCRIPT)/clean.sh
View
@@ -25,11 +25,18 @@ RUN apt-get install -y net-tools
RUN apt-get install -y iputils-ping
RUN apt-get install -y dnsutils
RUN apt-get install -y lsof
RUN apt-get install -y curl wget
# python
RUN apt-get install -y python-dev
RUN curl "https://bootstrap.pypa.io/get-pip.py" -o /tmp/get-pip.py
RUN python /tmp/get-pip.py
# java
RUN apt-get install -y openjdk-8-jdk
# maven
RUN apt-get install -y maven=3.3.9-3
# supervisord
RUN pip install supervisor==3.3.3
RUN mkdir -p /var/log/supervisord/
@@ -13,10 +13,8 @@ COPY ./krb-conf/server/kdc.conf /etc/krb5kdc/kdc.conf
COPY ./krb-conf/server/kadm5.acl /etc/krb5kdc/kadm5.acl
COPY ./krb-conf/client/krb5.conf /etc/krb5.conf
# ssh client
RUN apt-get install -y openssh-client
# supervisord
COPY ./supervisord.conf /etc/supervisord.conf
# when container is starting
CMD ["service", "krb5-kdc", "start"]
CMD ["service", "krb5-admin-server", "start"]
CMD ["python", "-m", "SimpleHTTPServer", "5002"]
CMD ["/usr/local/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
@@ -0,0 +1,28 @@
; supervisord.conf - kdc-server
[supervisord]
logfile=/var/log/supervisord/supervisord.log ; supervisord log file
logfile_maxbytes=50MB ; maximum size of logfile before rotation
logfile_backups=10 ; number of backed up logfiles
loglevel=error ; info, debug, warn, trace
pidfile=/var/run/supervisord.pid ; pidfile location
nodaemon=false ; run supervisord as a daemon
minfds=1024 ; number of startup file descriptors
minprocs=200 ; number of process descriptors
user=root ; default user
childlogdir=/var/log/supervisord/ ; where child log files will live
[program:httpserver]
command=python -m SimpleHTTPServer 5002
autostart=true
autorestart=true
[program:krb5-kdc]
command=service krb5-kdc start
autostart=true
autorestart=true
[program:krb5-admin-server]
command=service krb5-admin-server start
autostart=true
autorestart=true
@@ -15,6 +15,8 @@ COPY ./krb-conf/client/krb5.conf /etc/krb5.conf
RUN apt-get install -y openssh-client
COPY ./ssh-conf/client/ssh_config /etc/ssh/ssh_config
# supervisord
COPY ./supervisord.conf /etc/supervisord.conf
# when container is starting
CMD ["/usr/bin/ssh", "-F", "/etc/ssh/ssh_config"]
CMD ["python", "-m", "SimpleHTTPServer", "5001"]
CMD ["/usr/local/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
@@ -0,0 +1,18 @@
; supervisord.conf - machine
[supervisord]
logfile=/var/log/supervisord/supervisord.log ; supervisord log file
logfile_maxbytes=50MB ; maximum size of logfile before rotation
logfile_backups=10 ; number of backed up logfiles
loglevel=error ; info, debug, warn, trace
pidfile=/var/run/supervisord.pid ; pidfile location
nodaemon=false ; run supervisord as a daemon
minfds=1024 ; number of startup file descriptors
minprocs=200 ; number of process descriptors
user=root ; default user
childlogdir=/var/log/supervisord/ ; where child log files will live
[program:httpserver]
command=python -m SimpleHTTPServer 5001
autostart=true
autorestart=true
@@ -16,6 +16,8 @@ RUN apt-get install -y openssh-server
RUN mkdir /var/run/sshd
COPY ./ssh-conf/server/sshd_config /etc/ssh/sshd_config
# supervisord
COPY ./supervisord.conf /etc/supervisord.conf
# when container is starting
CMD ["/usr/sbin/sshd"]
CMD ["python", "-m", "SimpleHTTPServer", "5003"]
CMD ["/usr/local/bin/supervisord", "-n", "-c", "/etc/supervisord.conf"]
@@ -0,0 +1,23 @@
; supervisord.conf - service
[supervisord]
logfile=/var/log/supervisord/supervisord.log ; supervisord log file
logfile_maxbytes=50MB ; maximum size of logfile before rotation
logfile_backups=10 ; number of backed up logfiles
loglevel=error ; info, debug, warn, trace
pidfile=/var/run/supervisord.pid ; pidfile location
nodaemon=false ; run supervisord as a daemon
minfds=1024 ; number of startup file descriptors
minprocs=200 ; number of process descriptors
user=root ; default user
childlogdir=/var/log/supervisord/ ; where child log files will live
[program:httpserver]
command=python -m SimpleHTTPServer 5003
autostart=true
autorestart=true
[program:sshd]
command=/usr/sbin/sshd
autostart=true
autorestart=true
View
@@ -14,4 +14,4 @@ ssh_server="${2:-krb5-service.example.com}"
ssh_client="krb5-machine"
ssh_cmd="ssh -vvv ${user}@${ssh_server}"
docker exec -it -e KRB5_TRACE=/dev/stdout "${ssh_client}" ${ssh_cmd}
docker exec -it -e KRB5_TRACE=/dev/stderr "${ssh_client}" ${ssh_cmd}
View
@@ -2,9 +2,10 @@
#
# start.sh
#
# Run docker containers cluster.
# Run docker containers for kerberos cluster.
cd "$(dirname "$0")"
cd ..
docker-compose start
View
@@ -0,0 +1,11 @@
#!/usr/bin/env bash
#
# status.sh
#
# Show docker containers status for kerberos cluster.
cd "$(dirname "$0")"
cd ..
docker-compose ps
View
@@ -5,18 +5,17 @@
# Execute kinit tests in docker container context.
cd "$(dirname "$0")"
cd ..
kinit_method=${1:-keytab}
container_name=${2:-krb5-machine}
if [[ "${kinit_method}" == "password" ]]; then
docker exec ${container_name} /bin/bash -c '
echo "bob" | kinit bob@EXAMPLE.COM
echo "bob" | KRB5_TRACE=/dev/stderr kinit bob@EXAMPLE.COM
'
elif [[ "${kinit_method}" == "keytab" ]]; then
docker exec ${container_name} /bin/bash -c '
kinit -kt /etc/bob.keytab bob@EXAMPLE.COM
KRB5_TRACE=/dev/stderr kinit -kt /etc/bob.keytab bob@EXAMPLE.COM
'
else
>&2 echo "ERROR: Bad kinit method!"
View
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
#
# make_test.sh
#
# Execute several targets of make.
cd "$(dirname "$0")"
cd ..
make usage status start stop restart stop status
View
@@ -0,0 +1,50 @@
#!/usr/bin/env bash
#
# restart_test.sh
#
# Test if each service is running in docker container after restarting
# with open port and ssh connection.
set -e
cd "$(dirname "$0")"
cd ..
is_open_port() {
local ip="$1"
local ports="$2"
local type_port="${3:-tcp}"
for port in ${ports}; do
if [[ "${type_port}" = "udp" ]]; then
local option="-u"
fi
nc ${option} -z -v -w2 "${ip}" "${port}"
if [[ $? -ne 0 ]]; then
return 1
fi
done
}
echo "=== restart status only on script ==="
make restart
echo "=== wait of each service started =="
sleep 5
echo "...OK"
echo "=== test udp/tcp open port ==="
# httpserver(s) tcp port
for i in 1 2 3; do
is_open_port "10.5.0.$i" "500$i"
done
# kerberos server udp/tcp port
is_open_port 10.5.0.2 "88 464 749"
is_open_port 10.5.0.2 "88 464" udp
# ssh server tcp port
is_open_port 10.5.0.3 "22"
echo "=== test ssh connection ==="
./test/kinit_test.sh
./test/ssh_test.sh bob krb5-service.example.com '-o PreferredAuthentications=gssapi-with-mic'
View
@@ -10,12 +10,12 @@ ssh_option="${3:--o PreferredAuthentications=gssapi-with-mic}"
docker_option="$4"
cmd=${5:-hostname}
ssh_cmd="ssh ${ssh_option} ${user}@${ssh_server} ${cmd}"
ssh_cmd="ssh -vvv ${ssh_option} ${user}@${ssh_server} ${cmd}"
ssh_client="krb5-machine"
echo "=== Test '${ssh_cmd}' from '${ssh_client}' container ===="
echo "=== test '${ssh_cmd}' from '${ssh_client}' container ===="
output=$(timeout 2s docker exec ${docker_option} "${ssh_client}" ${ssh_cmd})
output=$(timeout 2s docker exec -e KRB5_TRACE=/dev/stderr ${docker_option} "${ssh_client}" ${ssh_cmd})
exit_status=$?
if [[ ${exit_status} -eq 124 ]]; then
View
@@ -124,3 +124,17 @@ teardown() {
[[ "$status" -eq 0 ]] || failure
success
}
@test "Test make targets: status start stop restart usage" {
run_test ./make_test.sh
# Success
[[ "$status" -eq 0 ]] || failure
success
}
@test "Test service is running after restarting docker containers" {
run_test ./restart_test.sh
# Success
[[ "$status" -eq 0 ]] || failure
success
}

0 comments on commit 1ea4f24

Please sign in to comment.