summaryrefslogtreecommitdiffhomepage
path: root/pkg/docker/docker-entrypoint.sh
diff options
context:
space:
mode:
authorLiam Crilly <liam.crilly@nginx.com>2023-05-09 22:53:18 +0100
committerLiam Crilly <liam.crilly@nginx.com>2023-05-09 22:53:18 +0100
commitd48180190752201865f41b2cf1e0a6740fa2ea59 (patch)
treea059ed440ffdb84172089d3dc91af9ae03f4b686 /pkg/docker/docker-entrypoint.sh
parent8ab16f71fee9505d4159154179082c0aec03ca4c (diff)
downloadunit-d48180190752201865f41b2cf1e0a6740fa2ea59.tar.gz
unit-d48180190752201865f41b2cf1e0a6740fa2ea59.tar.bz2
Docker: show welcome page on port 80 when entrypoint.d is empty.
The entrypoint script now performs a default configuration when no useful files are found in /docker-entrypoint.d/ The default configuration serves a welcome page in response to all requests, using Markdown unless text/html is sent in the Accept header. This provides a useful 'hello world' experience when running a Unit container for the first time.
Diffstat (limited to 'pkg/docker/docker-entrypoint.sh')
-rwxr-xr-xpkg/docker/docker-entrypoint.sh67
1 files changed, 35 insertions, 32 deletions
diff --git a/pkg/docker/docker-entrypoint.sh b/pkg/docker/docker-entrypoint.sh
index c670c2e6..4646409f 100755
--- a/pkg/docker/docker-entrypoint.sh
+++ b/pkg/docker/docker-entrypoint.sh
@@ -25,21 +25,23 @@ if [ "$1" = "unitd" ] || [ "$1" = "unitd-debug" ]; then
if /usr/bin/find "/var/lib/unit/" -mindepth 1 -print -quit 2>/dev/null | /bin/grep -q .; then
echo "$0: /var/lib/unit/ is not empty, skipping initial configuration..."
else
- if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -print -quit 2>/dev/null | /bin/grep -q .; then
- echo "$0: /docker-entrypoint.d/ is not empty, launching Unit daemon to perform initial configuration..."
- /usr/sbin/$1 --control unix:/var/run/control.unit.sock
+ echo "$0: Launching Unit daemon to perform initial configuration..."
+ /usr/sbin/$1 --control unix:/var/run/control.unit.sock
- for i in $(/usr/bin/seq $WAITLOOPS); do
- if [ ! -S /var/run/control.unit.sock ]; then
- echo "$0: Waiting for control socket to be created..."
- /bin/sleep $SLEEPSEC
- else
- break
- fi
- done
- # even when the control socket exists, it does not mean unit has finished initialisation
- # this curl call will get a reply once unit is fully launched
- /usr/bin/curl -f -s -X GET --unix-socket /var/run/control.unit.sock http://localhost/
+ for i in $(/usr/bin/seq $WAITLOOPS); do
+ if [ ! -S /var/run/control.unit.sock ]; then
+ echo "$0: Waiting for control socket to be created..."
+ /bin/sleep $SLEEPSEC
+ else
+ break
+ fi
+ done
+ # even when the control socket exists, it does not mean unit has finished initialisation
+ # this curl call will get a reply once unit is fully launched
+ /usr/bin/curl -s -X GET --unix-socket /var/run/control.unit.sock http://localhost/
+
+ if /usr/bin/find "/docker-entrypoint.d/" -mindepth 1 -print -quit 2>/dev/null | /bin/grep -q .; then
+ echo "$0: /docker-entrypoint.d/ is not empty, applying initial configuration..."
echo "$0: Looking for certificate bundles in /docker-entrypoint.d/..."
for f in $(/usr/bin/find /docker-entrypoint.d/ -type f -name "*.pem"); do
@@ -69,29 +71,30 @@ if [ "$1" = "unitd" ] || [ "$1" = "unitd-debug" ]; then
for f in $(/usr/bin/find /docker-entrypoint.d/ -type f -not -name "*.sh" -not -name "*.json" -not -name "*.pem" -not -name "*.js"); do
echo "$0: Ignoring $f";
done
+ else
+ echo "$0: /docker-entrypoint.d/ is empty, creating 'welcome' configuration..."
+ curl_put /usr/share/unit/welcome/welcome.json "config"
+ fi
- echo "$0: Stopping Unit daemon after initial configuration..."
- kill -TERM $(/bin/cat /var/run/unit.pid)
+ echo "$0: Stopping Unit daemon after initial configuration..."
+ kill -TERM $(/bin/cat /var/run/unit.pid)
- for i in $(/usr/bin/seq $WAITLOOPS); do
- if [ -S /var/run/control.unit.sock ]; then
- echo "$0: Waiting for control socket to be removed..."
- /bin/sleep $SLEEPSEC
- else
- break
- fi
- done
+ for i in $(/usr/bin/seq $WAITLOOPS); do
if [ -S /var/run/control.unit.sock ]; then
- kill -KILL $(/bin/cat /var/run/unit.pid)
- rm -f /var/run/control.unit.sock
+ echo "$0: Waiting for control socket to be removed..."
+ /bin/sleep $SLEEPSEC
+ else
+ break
fi
-
- echo
- echo "$0: Unit initial configuration complete; ready for start up..."
- echo
- else
- echo "$0: /docker-entrypoint.d/ is empty, skipping initial configuration..."
+ done
+ if [ -S /var/run/control.unit.sock ]; then
+ kill -KILL $(/bin/cat /var/run/unit.pid)
+ rm -f /var/run/control.unit.sock
fi
+
+ echo
+ echo "$0: Unit initial configuration complete; ready for start up..."
+ echo
fi
fi