Skip to content

Commit 6bfa2b3

Browse files
authored
Merge pull request #352 from sandstorm-io/initialize-mysql-once
2 parents d060283 + d83ddd0 commit 6bfa2b3

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

stacks/lemp/launcher.sh

+14-4
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,25 @@ for f in $log_files; do
3535
fi
3636
done
3737

38-
# Ensure mysql tables created
39-
# HOME=/etc/mysql /usr/bin/mysql_install_db
40-
HOME=/etc/mysql /usr/sbin/mysqld --initialize
38+
if [ ! -d /var/lib/mysql/mysql ]; then
39+
# Ensure mysql tables created
40+
HOME=/etc/mysql /usr/sbin/mysqld --initialize
41+
fi
4142

4243
# Spawn mysqld, php
4344
HOME=/etc/mysql /usr/sbin/mysqld --skip-grant-tables &
4445
/usr/sbin/php-fpm8.2 --nodaemonize --fpm-config /etc/php/8.2/fpm/php-fpm.conf &
45-
# Wait until mysql and php have bound their sockets, indicating readiness
46+
# Wait until mysql has bound its socket, indicating readiness
4647
wait_for mysql /var/run/mysqld/mysqld.sock
48+
49+
# # Uncomment this block if you need to preload a database for your app
50+
# if [ ! -e /var/.db-created ]; then
51+
# mysql --user root -e 'CREATE DATABASE app'
52+
# mysql --user root --database app < /opt/app/install.sql
53+
# touch /var/.db-created
54+
# fi
55+
56+
# Wait until php has bound its socket, indicating readiness
4757
wait_for php-fpm8.2 /var/run/php/php8.2-fpm.sock
4858

4959
# Start nginx.

stacks/uwsgi/launcher.sh

+11-3
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ done
3636

3737
UWSGI_SOCKET_FILE=/var/run/uwsgi.sock
3838

39-
# Ensure mysql tables created
40-
# HOME=/etc/mysql /usr/bin/mysql_install_db
41-
HOME=/etc/mysql /usr/sbin/mysqld --initialize
39+
if [ ! -d /var/lib/mysql/mysql ]; then
40+
# Ensure mysql tables created
41+
HOME=/etc/mysql /usr/sbin/mysqld --initialize
42+
fi
4243

4344
# Spawn mysqld
4445
HOME=/etc/mysql /usr/sbin/mysqld --skip-grant-tables &
@@ -47,6 +48,13 @@ MYSQL_SOCKET_FILE=/var/run/mysqld/mysqld.sock
4748
# Wait for mysql to bind its socket
4849
wait_for mysql $MYSQL_SOCKET_FILE
4950

51+
# # Uncomment this block if you need to preload a database for your app
52+
# if [ ! -e /var/.db-created ]; then
53+
# mysql --user root -e 'CREATE DATABASE app'
54+
# mysql --user root --database app < /opt/app/install.sql
55+
# touch /var/.db-created
56+
# fi
57+
5058
# Spawn uwsgi
5159
HOME=/var uwsgi \
5260
--socket $UWSGI_SOCKET_FILE \

0 commit comments

Comments
 (0)