Skip to content

Commit

Permalink
Template: Use mysqladmin to stop temporary server
Browse files Browse the repository at this point in the history
Using a local socket means we don't need to know the pid of the server,
and mysqladmin shutdown will block until complete when using a local
socket.
  • Loading branch information
ltangvald authored and yosifkit committed Sep 18, 2019
1 parent ea73775 commit 9e51c81
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions .template.Debian/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -110,17 +110,13 @@ _start_server() {
}

_stop_server() {
local server_pid="$1"
kill "$server_pid"
for i in $(seq 1 60); do
sleep 1
if ! $(pidof /usr/sbin/mysqld >/dev/null 2>&1); then
return 0
fi
done
# The server hasn't shut down in a timely manner
_error "Unable to shut down server with process id $server_pid"

local passfile=$1
local socket=$2
result=0
mysqladmin --defaults-extra-file="${passfile}" shutdown -uroot --socket="${socket}" || result=$?
if [ ! "$result" = "0" ]; then
_error "Unable to shut down server. Status code $result."
fi
}
# allow the container to be started with `--user`
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
Expand Down Expand Up @@ -238,7 +234,7 @@ EOF
EOSQL
fi
_note "Stopping server"
_stop_server $pid
_stop_server "${PASSFILE}" "${SOCKET}"
_note "Server stopped"
rm -f "${PASSFILE}"
unset PASSFILE
Expand Down

0 comments on commit 9e51c81

Please sign in to comment.