Skip to content

Commit 9e51c81

Browse files
ltangvaldyosifkit
authored andcommitted
Template: Use mysqladmin to stop temporary server
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.
1 parent ea73775 commit 9e51c81

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

.template.Debian/docker-entrypoint.sh

+8-12
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,13 @@ _start_server() {
110110
}
111111

112112
_stop_server() {
113-
local server_pid="$1"
114-
kill "$server_pid"
115-
for i in $(seq 1 60); do
116-
sleep 1
117-
if ! $(pidof /usr/sbin/mysqld >/dev/null 2>&1); then
118-
return 0
119-
fi
120-
done
121-
# The server hasn't shut down in a timely manner
122-
_error "Unable to shut down server with process id $server_pid"
123-
113+
local passfile=$1
114+
local socket=$2
115+
result=0
116+
mysqladmin --defaults-extra-file="${passfile}" shutdown -uroot --socket="${socket}" || result=$?
117+
if [ ! "$result" = "0" ]; then
118+
_error "Unable to shut down server. Status code $result."
119+
fi
124120
}
125121
# allow the container to be started with `--user`
126122
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
@@ -238,7 +234,7 @@ EOF
238234
EOSQL
239235
fi
240236
_note "Stopping server"
241-
_stop_server $pid
237+
_stop_server "${PASSFILE}" "${SOCKET}"
242238
_note "Server stopped"
243239
rm -f "${PASSFILE}"
244240
unset PASSFILE

0 commit comments

Comments
 (0)