Skip to content

Commit a9e8576

Browse files
ltangvaldyosifkit
authored andcommitted
Template: Use --daemonize for temporary server startup.
When using --daemonize, the server process will fork and exit when the server is ready for use, removing the need for a wait loop. Note: This is only supported for 5.7+
1 parent 9e51c81 commit a9e8576

File tree

1 file changed

+6
-16
lines changed

1 file changed

+6
-16
lines changed

.template.Debian/docker-entrypoint.sh

+6-16
Original file line numberDiff line numberDiff line change
@@ -92,21 +92,11 @@ _get_config() {
9292

9393
_start_server() {
9494
local socket=$1; shift
95-
"$@" --skip-networking --socket="${socket}" &
96-
local pid="$!"
97-
98-
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${socket}" )
99-
100-
for i in {30..0}; do
101-
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
102-
break
103-
fi
104-
sleep 1
105-
done
106-
if [ "$i" = 0 ]; then
107-
_error "Unable to start server."
95+
result=0
96+
"$@" --daemonize --skip-networking --socket="${socket}" || result=$?
97+
if [ ! "$result" = "0" ];then
98+
_error "Unable to start server. Status code $result."
10899
fi
109-
return $pid
110100
}
111101

112102
_stop_server() {
@@ -154,8 +144,8 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
154144

155145
SOCKET="$(_get_config 'socket' "$@")"
156146
_note "Starting server"
157-
_start_server "${SOCKET}" "$@" || pid=$?
158-
_note "Server started with pid $pid"
147+
_start_server "${SOCKET}" "$@"
148+
_note "Server started with."
159149

160150
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )
161151

0 commit comments

Comments
 (0)