Skip to content

Commit 107d1c0

Browse files
committed
Add a health check to the container
1 parent c749f65 commit 107d1c0

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

Dockerfile

+8-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ RUN yum -y install python3
1212
# Install the python requirements of container accounting
1313
RUN pip3 install -r ./requirements.txt
1414

15-
# Set PYTHONPATH so Python can import the necessary files at run time.
15+
# Set PYTHONPATH so Python can import the necessary files at run time.
1616
ENV PYTHONPATH=/usr/share/container_accounting
1717

1818
# To avoid running the container as root, create an apel user.
@@ -22,4 +22,10 @@ RUN chown -R apel:apel /usr/share/container_accounting
2222
# Set the default user of the container to apel.
2323
USER apel:apel
2424

25-
ENTRYPOINT ./entrypoint.sh
25+
# Set a healthcheck for this container, and give the container 30 seconds
26+
# after start up where the health of the container will not be checked.
27+
# This makes it likely the underlying python call will have returned at least
28+
# once before the health check is called.
29+
HEALTHCHECK --start-period=30s CMD ./healthcheck.sh
30+
31+
ENTRYPOINT ./entrypoint.sh

healthcheck.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/sh
2+
3+
# A simple scrip to pass the stored return code of the python process back to
4+
# the caller for the purposes of a container health check.
5+
6+
exit `cat status.txt`
7+

0 commit comments

Comments
 (0)