mirror of
https://github.com/processone/ejabberd.git
synced 2024-11-28 16:34:13 +01:00
Container: Start BEAM with exec to maintain the PID and catch SIGTERM in Docker Stop
Until now, when stopping the ejabberd container, Erlang is not gracefully closed, Mnesia is not properly closed... exit code is 137. With this change, when the container is stopped, Erlang receives the SIGTERM signal, shutsdown, Mnesia database is properly closed, ... and exit code is 0.
This commit is contained in:
parent
8d15e973e2
commit
200cea25c8
20
.github/container/ejabberdctl.template
vendored
20
.github/container/ejabberdctl.template
vendored
@ -109,13 +109,25 @@ export ERL_LIBS
|
|||||||
export SCRIPT_DIR
|
export SCRIPT_DIR
|
||||||
|
|
||||||
# run command either directly or via su $INSTALLUSER
|
# run command either directly or via su $INSTALLUSER
|
||||||
exec_cmd()
|
run_cmd()
|
||||||
{
|
{
|
||||||
case $EXEC_CMD in
|
case $EXEC_CMD in
|
||||||
as_install_user) su -s /bin/sh -c '"$0" "$@"' "$INSTALLUSER" -- "$@" ;;
|
as_install_user) su -s /bin/sh -c '"$0" "$@"' "$INSTALLUSER" -- "$@" ;;
|
||||||
as_current_user) "$@" ;;
|
as_current_user) "$@" ;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
exec_cmd()
|
||||||
|
{
|
||||||
|
case $EXEC_CMD in
|
||||||
|
as_install_user) su -s /bin/sh -c '"$0" "$@"' "$INSTALLUSER" -- "$@" ;;
|
||||||
|
as_current_user) exec "$@" ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
run_erl()
|
||||||
|
{
|
||||||
|
NODE=$1; shift
|
||||||
|
run_cmd "$ERL" ${S:--}name "$NODE" $ERLANG_OPTS "$@"
|
||||||
|
}
|
||||||
exec_erl()
|
exec_erl()
|
||||||
{
|
{
|
||||||
NODE=$1; shift
|
NODE=$1; shift
|
||||||
@ -253,7 +265,7 @@ wait_status()
|
|||||||
if [ $timeout -eq 0 ] ; then
|
if [ $timeout -eq 0 ] ; then
|
||||||
status="$1"
|
status="$1"
|
||||||
else
|
else
|
||||||
exec_erl "$(uid ctl)" -hidden -noinput -s ejabberd_ctl \
|
run_erl "$(uid ctl)" -hidden -noinput -s ejabberd_ctl \
|
||||||
-extra "$ERLANG_NODE" $NO_TIMEOUT status > /dev/null
|
-extra "$ERLANG_NODE" $NO_TIMEOUT status > /dev/null
|
||||||
status="$?"
|
status="$?"
|
||||||
fi
|
fi
|
||||||
@ -262,7 +274,7 @@ wait_status()
|
|||||||
}
|
}
|
||||||
|
|
||||||
# ensure we can change current directory to SPOOL_DIR
|
# ensure we can change current directory to SPOOL_DIR
|
||||||
[ -d "$SPOOL_DIR" ] || exec_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"
|
||||||
exit 6
|
exit 6
|
||||||
@ -317,7 +329,7 @@ case $1 in
|
|||||||
wait_status 3 30 2 && stop_epmd # wait 30x2s before timeout
|
wait_status 3 30 2 && stop_epmd # wait 30x2s before timeout
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
exec_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 "$@"
|
||||||
result=$?
|
result=$?
|
||||||
case $result in
|
case $result in
|
||||||
|
Loading…
Reference in New Issue
Block a user