Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for initialization scripts #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/init/test.cli
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
help
12 changes: 12 additions & 0 deletions wait_for_jboss_cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/jjs

function canConnect() {
try {
new java.net.Socket("localhost", 9990)
return true
} catch(e) {
return false
}
}

while(!canConnect()) { }