Skip to content

Commit

Permalink
Template: Use --daemonize for temporary server startup.
Browse files Browse the repository at this point in the history
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+
  • Loading branch information
ltangvald authored and yosifkit committed Sep 18, 2019
1 parent 9e51c81 commit a9e8576
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions .template.Debian/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -92,21 +92,11 @@ _get_config() {

_start_server() {
local socket=$1; shift
"$@" --skip-networking --socket="${socket}" &
local pid="$!"

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

for i in {30..0}; do
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then
break
fi
sleep 1
done
if [ "$i" = 0 ]; then
_error "Unable to start server."
result=0
"$@" --daemonize --skip-networking --socket="${socket}" || result=$?
if [ ! "$result" = "0" ];then
_error "Unable to start server. Status code $result."
fi
return $pid
}

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

SOCKET="$(_get_config 'socket' "$@")"
_note "Starting server"
_start_server "${SOCKET}" "$@" || pid=$?
_note "Server started with pid $pid"
_start_server "${SOCKET}" "$@"
_note "Server started with."

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

Expand Down

0 comments on commit a9e8576

Please sign in to comment.