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

Container: Experimental support CTL_ON_CREATE and CTL_ON_START environment variables

This commit is contained in:
Badlop 2022-04-25 10:53:14 +02:00
parent 200cea25c8
commit b0db87c683

View File

@ -252,6 +252,28 @@ check_start()
} }
} }
post_waiter_fork()
{
(FIRST_RUN=$FIRST_RUN "$0" post_waiter)&
}
post_waiter_waiting()
{
$0 started
[ -n "$FIRST_RUN" ] && [ -n "$CTL_ON_CREATE" ] && (post_waiter_loop $CTL_ON_CREATE)
[ -n "$CTL_ON_START" ] && post_waiter_loop $CTL_ON_START
}
post_waiter_loop()
{
LIST=$@
HEAD=${LIST%% ; *}
TAIL=${LIST#* ; }
echo ":> ejabberdctl $HEAD"
$0 $HEAD
[ "$HEAD" = "$TAIL" ] || post_waiter_loop $TAIL
}
# allow sync calls # allow sync calls
wait_status() wait_status()
{ {
@ -274,6 +296,7 @@ wait_status()
} }
# ensure we can change current directory to SPOOL_DIR # ensure we can change current directory to SPOOL_DIR
[ -f "$SPOOL_DIR/schema.DAT" ] || FIRST_RUN=true
[ -d "$SPOOL_DIR" ] || run_cmd mkdir -p "$SPOOL_DIR" [ -d "$SPOOL_DIR" ] || run_cmd mkdir -p "$SPOOL_DIR"
cd "$SPOOL_DIR" || { cd "$SPOOL_DIR" || {
echo "ERROR: can not access directory $SPOOL_DIR" echo "ERROR: can not access directory $SPOOL_DIR"
@ -288,6 +311,7 @@ case $1 in
;; ;;
foreground) foreground)
check_start check_start
post_waiter_fork
exec_erl "$ERLANG_NODE" $EJABBERD_OPTS -noinput exec_erl "$ERLANG_NODE" $EJABBERD_OPTS -noinput
;; ;;
foreground-quiet) foreground-quiet)
@ -328,6 +352,9 @@ case $1 in
stopped) stopped)
wait_status 3 30 2 && stop_epmd # wait 30x2s before timeout wait_status 3 30 2 && stop_epmd # wait 30x2s before timeout
;; ;;
post_waiter)
post_waiter_waiting
;;
*) *)
run_erl "$(uid ctl)" -hidden -noinput -s ejabberd_ctl \ run_erl "$(uid ctl)" -hidden -noinput -s ejabberd_ctl \
-extra "$ERLANG_NODE" $NO_TIMEOUT "$@" -extra "$ERLANG_NODE" $NO_TIMEOUT "$@"