25
1
mirror of https://github.com/processone/ejabberd.git synced 2024-11-24 16:23:40 +01:00

Add ability to ignore failures in execution of container CTL_ON_* commands

This will allow to use register in CTL_ON_CREATE and not abort if used with
existing data that have account already registered.
This commit is contained in:
Paweł Chmielowski 2024-02-13 11:55:12 +01:00
parent cdaf45f91c
commit 67a6776fba
2 changed files with 18 additions and 8 deletions

View File

@ -331,13 +331,18 @@ post_waiter_loop()
LIST=$@ LIST=$@
HEAD=${LIST%% ; *} HEAD=${LIST%% ; *}
TAIL=${LIST#* ; } TAIL=${LIST#* ; }
echo ":> ejabberdctl $HEAD" HEAD2=${HEAD#\! *}
$0 $HEAD echo ":> ejabberdctl $HEAD2"
$0 $HEAD2
ctlstatus=$? ctlstatus=$?
if [ $ctlstatus -ne 0 ] ; then if [ $ctlstatus -ne 0 ] ; then
echo ":> FAILURE in command '$HEAD' !!! Stopping ejabberd..." if [ "$HEAD" != "$HEAD2" ] ; then
$0 halt > /dev/null echo ":> FAILURE in command '$HEAD2' !!! Ignoring result"
exit $ctlstatus else
echo ":> FAILURE in command '$HEAD' !!! Stopping ejabberd..."
$0 halt > /dev/null
exit $ctlstatus
fi
fi fi
[ "$HEAD" = "$TAIL" ] || post_waiter_loop $TAIL [ "$HEAD" = "$TAIL" ] || post_waiter_loop $TAIL
} }

View File

@ -221,10 +221,13 @@ and reads `CTL_ON_START` every time the container is started.
Those variables can contain one ejabberdctl command, Those variables can contain one ejabberdctl command,
or several commands separated with the blankspace and `;` characters. or several commands separated with the blankspace and `;` characters.
By default failure of any of commands executed that way would
abort start, this can be disabled by prefixing commands with `!`
Example usage (or check the [full example](#customized-example)): Example usage (or check the [full example](#customized-example)):
```yaml ```yaml
environment: environment:
- CTL_ON_CREATE=register admin localhost asd - CTL_ON_CREATE=\! register admin localhost asd
- CTL_ON_START=stats registeredusers ; - CTL_ON_START=stats registeredusers ;
check_password admin localhost asd ; check_password admin localhost asd ;
status status
@ -411,7 +414,9 @@ In this example, the main container is created first.
Once it is fully started and healthy, a second container is created, Once it is fully started and healthy, a second container is created,
and once ejabberd is started in it, it joins the first one. and once ejabberd is started in it, it joins the first one.
An account is registered in the first node when created, An account is registered in the first node when created (and
we ignore errors that can happen when doing that - for example
whenn account already exists),
and it should exist in the second node after join. and it should exist in the second node after join.
Notice that in this example the main container does not have access Notice that in this example the main container does not have access
@ -428,7 +433,7 @@ services:
environment: environment:
- ERLANG_NODE_ARG=ejabberd@main - ERLANG_NODE_ARG=ejabberd@main
- ERLANG_COOKIE=dummycookie123 - ERLANG_COOKIE=dummycookie123
- CTL_ON_CREATE=register admin localhost asd - CTL_ON_CREATE=\! register admin localhost asd
replica: replica:
image: ghcr.io/processone/ejabberd image: ghcr.io/processone/ejabberd