From 81064d1d74a152381dea679a739a3d1d6a587700 Mon Sep 17 00:00:00 2001 From: Leopoldo Muller Date: Thu, 5 May 2016 17:28:11 +0100 Subject: [PATCH] Support for initialization scripts --- Dockerfile | 4 +++- README.md | 6 ++++++ entrypoint.sh | 24 ++++++++++++++++++++++++ test/init/test.cli | 1 + wait_for_jboss_cli.js | 12 ++++++++++++ 5 files changed, 46 insertions(+), 1 deletion(-) create mode 100755 entrypoint.sh create mode 100644 test/init/test.cli create mode 100644 wait_for_jboss_cli.js diff --git a/Dockerfile b/Dockerfile index 8676790..9afc1d1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,4 +23,6 @@ EXPOSE 8080 # Set the default command to run on boot # This will boot WildFly in the standalone mode and bind to all interface -CMD ["/opt/jboss/wildfly/bin/standalone.sh", "-b", "0.0.0.0"] +COPY entrypoint.sh /entrypoint.sh +COPY wait_for_jboss_cli.js /wait_for_jboss_cli.js +ENTRYPOINT ["/entrypoint.sh"] diff --git a/README.md b/README.md index 0d1a4d2..fe14635 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,12 @@ Logging can be done in many ways. [This blog post](https://goldmann.pl/blog/2014 Sometimes you need to customize the application server configuration. There are many ways to do it and [this blog post](https://goldmann.pl/blog/2014/07/23/customizing-the-configuration-of-the-wildfly-docker-image/) tries to summarize it. +## Initialization scripts + +If you need additional configuration it is possible to execute CLI scripts before initialization using: + + docker run -it -v [PATH TO YOUR SCRIPTS]:/init jboss/wildfly + ## Extending the image To be able to create a management user to access the administration console create a Dockerfile with the following content diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..6e84ece --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,24 @@ +#!/bin/sh +set -e + +#docker run [COMMAND] not provided +if [ "$#" -eq 0 ]; then + #/init directory exists and contain cli scripts + if [ -d /init ] && [ $(find /init -name "*.cli" | wc -l) -gt 0 ]; then + #start standalone server in admin only mode + $JBOSS_HOME/bin/standalone.sh --admin-only & + #wait for cli to be available + jjs /wait_for_jboss_cli.js + for s in /init/*.cli; do + #execute cli script + $JBOSS_HOME/bin/jboss-cli.sh --connect --file=$s + done + #shutdown admin only server + $JBOSS_HOME/bin/jboss-cli.sh --connect --command=shutdown + fi + # start real server + $JBOSS_HOME/bin/standalone.sh -b 0.0.0.0 +else + #docker run [COMMAND] is provided, execute it (e.g. bash) + exec "$@" +fi diff --git a/test/init/test.cli b/test/init/test.cli new file mode 100644 index 0000000..a87bf43 --- /dev/null +++ b/test/init/test.cli @@ -0,0 +1 @@ +help diff --git a/wait_for_jboss_cli.js b/wait_for_jboss_cli.js new file mode 100644 index 0000000..dfdf6a0 --- /dev/null +++ b/wait_for_jboss_cli.js @@ -0,0 +1,12 @@ +#!/usr/bin/jjs + +function canConnect() { + try { + new java.net.Socket("localhost", 9990) + return true + } catch(e) { + return false + } +} + +while(!canConnect()) { }